project_board_page_alternate.dart (5016B)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 | import 'package:flutter/material.dart'; import 'package:creekui/ui/styles/variables.dart'; import 'package:creekui/data/models/image_model.dart'; import 'package:creekui/data/repos/image_repo.dart'; import 'package:creekui/ui/widgets/moodboard_image_card.dart'; import 'package:creekui/ui/widgets/empty_state.dart'; import 'image_details_page.dart'; class ProjectBoardPageAlternate extends StatefulWidget { final int projectId; const ProjectBoardPageAlternate({super.key, required this.projectId}); @override State<ProjectBoardPageAlternate> createState() => ProjectBoardPageAlternateState(); } class ProjectBoardPageAlternateState extends State<ProjectBoardPageAlternate> { final _imageRepo = ImageRepo(); List<ImageModel> _allImages = []; List<ImageModel> _filteredImages = []; List<String> _allTags = []; final Set<String> _selectedTags = {}; bool _isLoading = true; @override void initState() { super.initState(); _loadData(); } @override void didUpdateWidget(covariant ProjectBoardPageAlternate oldWidget) { super.didUpdateWidget(oldWidget); if (oldWidget.projectId != widget.projectId) _loadData(); } void refreshData() => _loadData(); Future<void> _loadData() async { setState(() => _isLoading = true); final images = await _imageRepo.getImages(widget.projectId); final Set<String> tags = {}; for (var img in images) { tags.addAll(img.tags); } if (mounted) { setState(() { _allImages = images; _filteredImages = images; _allTags = tags.toList()..sort(); _isLoading = false; }); if (_selectedTags.isNotEmpty) _applyFilter(); } } void _applyFilter() { setState(() { _filteredImages = _selectedTags.isEmpty ? _allImages : _allImages .where( (img) => img.tags.toSet().intersection(_selectedTags).isNotEmpty, ) .toList(); }); } @override Widget build(BuildContext context) { if (_isLoading) return const Center(child: CircularProgressIndicator()); final leftColumn = <Widget>[]; final rightColumn = <Widget>[]; for (int i = 0; i < _filteredImages.length; i++) { final item = MoodboardImageCard( image: _filteredImages[i], height: (i % 3 == 0) ? 240 : 180, showTags: true, onTap: () => Navigator.push( context, MaterialPageRoute( builder: (_) => ImageDetailsPage( imagePath: _filteredImages[i].filePath, imageId: _filteredImages[i].id, projectId: widget.projectId, ), ), ), onDeleted: refreshData, ); if (i % 2 == 0) { leftColumn.add( Padding(padding: const EdgeInsets.only(bottom: 12), child: item), ); } else { rightColumn.add( Padding(padding: const EdgeInsets.only(bottom: 12), child: item), ); } } return Column( children: [ // Context Info Row (Image Count + Active Filters) Padding( padding: const EdgeInsets.fromLTRB(16, 0, 16, 16), child: Row( children: [ const Spacer(), if (_selectedTags.isNotEmpty) Container( padding: const EdgeInsets.symmetric( horizontal: 8, vertical: 4, ), decoration: BoxDecoration( color: Variables.textPrimary, borderRadius: BorderRadius.circular(12), ), child: Text( "${_selectedTags.length} Active", style: Variables.captionStyle.copyWith( color: Colors.white, fontWeight: FontWeight.bold, ), ), ), ], ), ), // Masonry Grid Expanded( child: _filteredImages.isEmpty ? const EmptyState( icon: Icons.image_not_supported_outlined, title: "No images found", subtitle: "Try removing filters or adding new images", ) : SingleChildScrollView( padding: const EdgeInsets.fromLTRB(16, 0, 16, 80), child: Row( crossAxisAlignment: CrossAxisAlignment.start, children: [ Expanded(child: Column(children: leftColumn)), const SizedBox(width: 12), Expanded(child: Column(children: rightColumn)), ], ), ), ), ], ); } } |