project_tag_page.dart (5475B)
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 166 167 168 169 170 171 172 173 174 175 | import 'dart:io'; import 'package:flutter/material.dart'; import 'package:image_picker/image_picker.dart'; import 'package:creekui/ui/styles/variables.dart'; import 'package:creekui/ui/widgets/top_bar.dart'; import 'package:creekui/ui/widgets/bottom_bar.dart'; import 'package:creekui/ui/widgets/moodboard_image_card.dart'; import 'package:creekui/ui/widgets/empty_state.dart'; import 'package:creekui/data/models/image_model.dart'; import 'package:creekui/data/repos/image_repo.dart'; import 'package:creekui/data/repos/project_repo.dart'; import 'package:creekui/data/repos/note_repo.dart'; import 'image_save_page.dart'; import 'image_details_page.dart'; class ProjectTagPage extends StatefulWidget { final int projectId; final String tag; const ProjectTagPage({super.key, required this.projectId, required this.tag}); @override State<ProjectTagPage> createState() => _ProjectTagPageState(); } class _ProjectTagPageState extends State<ProjectTagPage> { final _imageRepo = ImageRepo(); final _projectRepo = ProjectRepo(); final _noteRepo = NoteRepo(); final ImagePicker _picker = ImagePicker(); List<ImageModel> _images = []; String _projectName = "Project"; bool _isLoading = true; @override void initState() { super.initState(); _loadData(); } Future<void> _loadData() async { final project = await _projectRepo.getProjectById(widget.projectId); if (project != null) _projectName = project.title; final allImages = await _imageRepo.getImages(widget.projectId); final List<ImageModel> filtered = []; await Future.wait( allImages.map((img) async { bool matches = false; if (widget.tag == 'Uncategorized') { if (img.tags.isEmpty) { final notes = await _noteRepo.getNotesForImage(img.id); if (!notes.any((n) => n.category.isNotEmpty)) matches = true; } } else { if (img.tags.contains(widget.tag)) matches = true; else { final notes = await _noteRepo.getNotesForImage(img.id); if (notes.any((n) => n.category == widget.tag)) matches = true; } } if (matches) filtered.add(img); }), ); if (mounted) { setState(() { _images = filtered; _isLoading = false; }); } } Future<void> _pickAndRedirect() async { try { final List<XFile> pickedFiles = await _picker.pickMultiImage(); if (pickedFiles.isNotEmpty) { if (!mounted) return; Navigator.push( context, MaterialPageRoute( builder: (_) => ImageSavePage( imagePaths: pickedFiles.map((e) => e.path).toList(), projectId: widget.projectId, projectName: _projectName, isFromShare: false, ), ), ).then((_) => _loadData()); } } catch (e) { debugPrint("Error picking images: $e"); } } @override Widget build(BuildContext context) { final leftColumn = <Widget>[]; final rightColumn = <Widget>[]; for (int i = 0; i < _images.length; i++) { final item = MoodboardImageCard( image: _images[i], height: (i % 3 == 0) ? 240 : 180, onTap: () => Navigator.push( context, MaterialPageRoute( builder: (_) => ImageDetailsPage( imagePath: _images[i].filePath, imageId: _images[i].id, projectId: widget.projectId, ), ), ).then((_) => _loadData()), onDeleted: _loadData, ); 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 Scaffold( backgroundColor: Variables.background, appBar: TopBar( currentProjectId: widget.projectId, titleOverride: widget.tag.toUpperCase(), onBack: () => Navigator.pop(context), hideSecondRow: true, ), bottomNavigationBar: BottomBar( currentTab: BottomBarItem.moodboard, projectId: widget.projectId, ), floatingActionButton: FloatingActionButton( onPressed: _pickAndRedirect, backgroundColor: Variables.textPrimary, foregroundColor: Variables.background, child: const Icon(Icons.add_photo_alternate_outlined), ), body: _isLoading ? const Center(child: CircularProgressIndicator()) : _images.isEmpty ? EmptyState( icon: Icons.image_not_supported_outlined, title: "No images found", subtitle: "No images found for '${widget.tag}'", ) : SingleChildScrollView( padding: const EdgeInsets.fromLTRB(16, 16, 16, 80), child: Row( crossAxisAlignment: CrossAxisAlignment.start, children: [ Expanded(child: Column(children: leftColumn)), const SizedBox(width: 12), Expanded(child: Column(children: rightColumn)), ], ), ), ); } } |