|
|
|
|
@ -583,39 +583,20 @@ class _AddRecipeScreenState extends State<AddRecipeScreen> {
|
|
|
|
|
final tagController = TextEditingController();
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
// Get all existing tags from all recipes
|
|
|
|
|
final allRecipes = await _recipeService?.getAllRecipes() ?? [];
|
|
|
|
|
final allTags = <String>{};
|
|
|
|
|
for (final recipe in allRecipes) {
|
|
|
|
|
allTags.addAll(recipe.tags);
|
|
|
|
|
}
|
|
|
|
|
final existingTags = allTags.toList()..sort();
|
|
|
|
|
|
|
|
|
|
final result = await showDialog<String>(
|
|
|
|
|
context: context,
|
|
|
|
|
builder: (context) => AlertDialog(
|
|
|
|
|
title: const Text('Add Tag'),
|
|
|
|
|
content: TextField(
|
|
|
|
|
controller: tagController,
|
|
|
|
|
autofocus: true,
|
|
|
|
|
decoration: const InputDecoration(
|
|
|
|
|
hintText: 'Enter tag name',
|
|
|
|
|
border: OutlineInputBorder(),
|
|
|
|
|
),
|
|
|
|
|
textCapitalization: TextCapitalization.none,
|
|
|
|
|
onSubmitted: (value) {
|
|
|
|
|
if (value.trim().isNotEmpty) {
|
|
|
|
|
Navigator.pop(context, value.trim());
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
actions: [
|
|
|
|
|
TextButton(
|
|
|
|
|
onPressed: () => Navigator.pop(context),
|
|
|
|
|
child: const Text('Cancel'),
|
|
|
|
|
),
|
|
|
|
|
FilledButton(
|
|
|
|
|
onPressed: () {
|
|
|
|
|
final text = tagController.text.trim();
|
|
|
|
|
if (text.isNotEmpty) {
|
|
|
|
|
Navigator.pop(context, text);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
child: const Text('Add'),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
builder: (context) => _AddTagDialog(
|
|
|
|
|
tagController: tagController,
|
|
|
|
|
existingTags: existingTags,
|
|
|
|
|
currentTags: _recipe?.tags ?? [],
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
@ -1778,6 +1759,233 @@ class _AddRecipeScreenState extends State<AddRecipeScreen> {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Dialog for adding tags with existing tags selection
|
|
|
|
|
class _AddTagDialog extends StatefulWidget {
|
|
|
|
|
final TextEditingController tagController;
|
|
|
|
|
final List<String> existingTags;
|
|
|
|
|
final List<String> currentTags;
|
|
|
|
|
|
|
|
|
|
const _AddTagDialog({
|
|
|
|
|
required this.tagController,
|
|
|
|
|
required this.existingTags,
|
|
|
|
|
required this.currentTags,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
State<_AddTagDialog> createState() => _AddTagDialogState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _AddTagDialogState extends State<_AddTagDialog> with SingleTickerProviderStateMixin {
|
|
|
|
|
late List<String> _filteredTags;
|
|
|
|
|
late ScrollController _scrollController;
|
|
|
|
|
late AnimationController _animationController;
|
|
|
|
|
late Animation<double> _animation;
|
|
|
|
|
bool _isUserScrolling = false;
|
|
|
|
|
DateTime? _lastUserScrollTime;
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
super.initState();
|
|
|
|
|
_filteredTags = List.from(widget.existingTags);
|
|
|
|
|
widget.tagController.addListener(_filterTags);
|
|
|
|
|
|
|
|
|
|
_scrollController = ScrollController();
|
|
|
|
|
|
|
|
|
|
_animationController = AnimationController(
|
|
|
|
|
vsync: this,
|
|
|
|
|
duration: const Duration(seconds: 8), // Slower animation
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
_animation = Tween<double>(begin: 0, end: 0.3).animate( // Only scroll 30% of the way
|
|
|
|
|
CurvedAnimation(parent: _animationController, curve: Curves.easeInOut),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
_startAutoScroll();
|
|
|
|
|
_animation.addListener(_animateScroll);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void dispose() {
|
|
|
|
|
widget.tagController.removeListener(_filterTags);
|
|
|
|
|
_animationController.dispose();
|
|
|
|
|
_scrollController.dispose();
|
|
|
|
|
super.dispose();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void _startAutoScroll() {
|
|
|
|
|
if (!_isUserScrolling && _filteredTags.length > 3) {
|
|
|
|
|
_animationController.repeat(reverse: true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void _animateScroll() {
|
|
|
|
|
if (!_isUserScrolling && _scrollController.hasClients && _filteredTags.length > 3) {
|
|
|
|
|
final maxScroll = _scrollController.position.maxScrollExtent;
|
|
|
|
|
if (maxScroll > 0) {
|
|
|
|
|
// Only scroll a small amount (30% of max scroll) to suggest scrollability
|
|
|
|
|
final targetScroll = _animation.value * maxScroll;
|
|
|
|
|
if ((_scrollController.offset - targetScroll).abs() > 1) {
|
|
|
|
|
_scrollController.jumpTo(targetScroll);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void _filterTags() {
|
|
|
|
|
final query = widget.tagController.text.toLowerCase();
|
|
|
|
|
setState(() {
|
|
|
|
|
if (query.isEmpty) {
|
|
|
|
|
_filteredTags = List.from(widget.existingTags);
|
|
|
|
|
} else {
|
|
|
|
|
_filteredTags = widget.existingTags
|
|
|
|
|
.where((tag) => tag.toLowerCase().contains(query))
|
|
|
|
|
.toList();
|
|
|
|
|
}
|
|
|
|
|
// Reset scroll position when tags change
|
|
|
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
|
|
|
if (_scrollController.hasClients) {
|
|
|
|
|
_scrollController.jumpTo(0);
|
|
|
|
|
_isUserScrolling = false;
|
|
|
|
|
_lastUserScrollTime = null;
|
|
|
|
|
_startAutoScroll();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void _selectTag(String tag) {
|
|
|
|
|
Navigator.pop(context, tag);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
final theme = Theme.of(context);
|
|
|
|
|
final isDark = theme.brightness == Brightness.dark;
|
|
|
|
|
|
|
|
|
|
return AlertDialog(
|
|
|
|
|
title: const Text('Add Tag'),
|
|
|
|
|
contentPadding: const EdgeInsets.fromLTRB(24, 20, 24, 24),
|
|
|
|
|
content: SizedBox(
|
|
|
|
|
width: MediaQuery.of(context).size.width * 0.95,
|
|
|
|
|
child: Column(
|
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
children: [
|
|
|
|
|
// Search field
|
|
|
|
|
TextField(
|
|
|
|
|
controller: widget.tagController,
|
|
|
|
|
autofocus: true,
|
|
|
|
|
decoration: InputDecoration(
|
|
|
|
|
hintText: 'Enter tag name or select from existing',
|
|
|
|
|
border: const OutlineInputBorder(),
|
|
|
|
|
prefixIcon: const Icon(Icons.search),
|
|
|
|
|
),
|
|
|
|
|
textCapitalization: TextCapitalization.none,
|
|
|
|
|
onSubmitted: (value) {
|
|
|
|
|
if (value.trim().isNotEmpty) {
|
|
|
|
|
Navigator.pop(context, value.trim());
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(height: 16),
|
|
|
|
|
// Existing tags scrollable list with fade hint
|
|
|
|
|
if (_filteredTags.isNotEmpty) ...[
|
|
|
|
|
Text(
|
|
|
|
|
'Existing Tags',
|
|
|
|
|
style: theme.textTheme.titleSmall?.copyWith(
|
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(height: 8),
|
|
|
|
|
SizedBox(
|
|
|
|
|
height: 50,
|
|
|
|
|
child: NotificationListener<ScrollNotification>(
|
|
|
|
|
onNotification: (notification) {
|
|
|
|
|
// Detect when user manually scrolls
|
|
|
|
|
if (notification is ScrollStartNotification && notification.dragDetails != null) {
|
|
|
|
|
_isUserScrolling = true;
|
|
|
|
|
_lastUserScrollTime = DateTime.now();
|
|
|
|
|
_animationController.stop();
|
|
|
|
|
} else if (notification is ScrollEndNotification) {
|
|
|
|
|
// Resume auto-scroll after user stops scrolling for 3 seconds
|
|
|
|
|
_lastUserScrollTime = DateTime.now();
|
|
|
|
|
Future.delayed(const Duration(seconds: 3), () {
|
|
|
|
|
if (mounted && _lastUserScrollTime != null) {
|
|
|
|
|
final timeSinceLastScroll = DateTime.now().difference(_lastUserScrollTime!);
|
|
|
|
|
if (timeSinceLastScroll.inSeconds >= 3) {
|
|
|
|
|
setState(() {
|
|
|
|
|
_isUserScrolling = false;
|
|
|
|
|
});
|
|
|
|
|
_startAutoScroll();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
},
|
|
|
|
|
child: ListView.builder(
|
|
|
|
|
controller: _scrollController,
|
|
|
|
|
scrollDirection: Axis.horizontal,
|
|
|
|
|
itemCount: _filteredTags.length,
|
|
|
|
|
itemBuilder: (context, index) {
|
|
|
|
|
final tag = _filteredTags[index];
|
|
|
|
|
final isAlreadyAdded = widget.currentTags.contains(tag);
|
|
|
|
|
return Padding(
|
|
|
|
|
padding: const EdgeInsets.only(right: 8),
|
|
|
|
|
child: FilterChip(
|
|
|
|
|
label: Text(tag),
|
|
|
|
|
selected: isAlreadyAdded,
|
|
|
|
|
onSelected: isAlreadyAdded
|
|
|
|
|
? null
|
|
|
|
|
: (selected) {
|
|
|
|
|
_selectTag(tag);
|
|
|
|
|
},
|
|
|
|
|
selectedColor: theme.primaryColor,
|
|
|
|
|
checkmarkColor: Colors.white,
|
|
|
|
|
backgroundColor: isDark
|
|
|
|
|
? Colors.grey[800]
|
|
|
|
|
: Colors.grey[200],
|
|
|
|
|
disabledColor: Colors.grey[400],
|
|
|
|
|
labelStyle: TextStyle(
|
|
|
|
|
color: isAlreadyAdded
|
|
|
|
|
? Colors.white
|
|
|
|
|
: (isDark ? Colors.white : Colors.black87),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
] else if (widget.tagController.text.isNotEmpty)
|
|
|
|
|
Text(
|
|
|
|
|
'No tags found',
|
|
|
|
|
style: theme.textTheme.bodySmall?.copyWith(
|
|
|
|
|
color: isDark ? Colors.grey[400] : Colors.grey[600],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
actions: [
|
|
|
|
|
TextButton(
|
|
|
|
|
onPressed: () => Navigator.pop(context),
|
|
|
|
|
child: const Text('Cancel'),
|
|
|
|
|
),
|
|
|
|
|
FilledButton(
|
|
|
|
|
onPressed: () {
|
|
|
|
|
final text = widget.tagController.text.trim();
|
|
|
|
|
if (text.isNotEmpty) {
|
|
|
|
|
Navigator.pop(context, text);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
child: const Text('Add'),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Widget that displays a video thumbnail preview with a few seconds of playback.
|
|
|
|
|
class _VideoThumbnailPreview extends StatefulWidget {
|
|
|
|
|
|