note_input_sheet.dart (6737B)
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 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 | import 'package:flutter/material.dart'; import 'package:shared_preferences/shared_preferences.dart'; import 'package:creekui/ui/styles/variables.dart'; class NoteInputSheet extends StatefulWidget { final List<String> categories; final String initialCategory; final Function(String content, String category) onSubmit; const NoteInputSheet({ super.key, required this.categories, required this.initialCategory, required this.onSubmit, }); @override State<NoteInputSheet> createState() => _NoteInputSheetState(); } class _NoteInputSheetState extends State<NoteInputSheet> { late String _selectedCategory; final TextEditingController _controller = TextEditingController(); String _userName = "Alex"; // Default @override void initState() { super.initState(); _selectedCategory = widget.initialCategory; _loadUserName(); } Future<void> _loadUserName() async { final prefs = await SharedPreferences.getInstance(); if (mounted) { setState(() { _userName = prefs.getString('user_name') ?? "Alex"; }); } } @override void dispose() { _controller.dispose(); super.dispose(); } @override Widget build(BuildContext context) { return Padding( padding: const EdgeInsets.all(16), child: Column( mainAxisSize: MainAxisSize.min, children: [ // Header Row Row( children: [ Container( width: 30, height: 30, decoration: BoxDecoration( shape: BoxShape.circle, border: Border.all( color: Variables.surfaceBackground, width: 1.25, ), ), child: const CircleAvatar( radius: 15, backgroundColor: Colors.grey, child: Icon(Icons.person, color: Colors.white, size: 18), ), ), const SizedBox(width: 10), Text( _userName, style: Variables.bodyStyle.copyWith( fontSize: 12, fontWeight: FontWeight.w500, ), ), const Spacer(), Container( padding: const EdgeInsets.symmetric( horizontal: 12, vertical: 6, ), decoration: BoxDecoration( color: Variables.chipBackground, borderRadius: BorderRadius.circular(1000), ), child: DropdownButtonHideUnderline( child: DropdownButton<String>( value: widget.categories.contains(_selectedCategory) ? _selectedCategory : null, hint: Text( "Type", style: Variables.bodyStyle.copyWith(fontSize: 12), ), isDense: true, icon: const Icon( Icons.arrow_drop_down, size: 20, color: Variables.textPrimary, ), style: Variables.bodyStyle.copyWith(fontSize: 12), dropdownColor: Colors.white, items: widget.categories .map( (c) => DropdownMenuItem(value: c, child: Text(c)), ) .toList(), onChanged: (v) { if (v != null) setState(() => _selectedCategory = v); }, ), ), ), ], ), const SizedBox(height: 16), // Input Row Row( crossAxisAlignment: CrossAxisAlignment.end, children: [ Expanded( child: Container( decoration: BoxDecoration( color: Variables.surfaceSubtle, border: Border.all(color: Variables.borderSubtle), borderRadius: BorderRadius.circular(8), ), child: TextField( controller: _controller, autofocus: true, maxLines: null, style: Variables.bodyStyle.copyWith(fontSize: 12), decoration: const InputDecoration( hintText: "Enter note details...", border: InputBorder.none, contentPadding: EdgeInsets.symmetric( horizontal: 12, vertical: 10, ), ), ), ), ), const SizedBox(width: 8), IconButton( icon: const Icon( Icons.send, color: Variables.textPrimary, size: 24, ), onPressed: () { if (_controller.text.isNotEmpty) { widget.onSubmit(_controller.text.trim(), _selectedCategory); } }, padding: EdgeInsets.zero, constraints: const BoxConstraints(minWidth: 24, minHeight: 24), ), ], ), const SizedBox(height: 10), ], ), ); } } class NoteModalOverlay extends StatelessWidget { final Widget modalContent; final Size screenSize; const NoteModalOverlay({ super.key, required this.modalContent, required this.screenSize, }); @override Widget build(BuildContext context) { final mq = MediaQuery.of(context); return Align( alignment: Alignment.bottomCenter, child: AnimatedPadding( duration: const Duration(milliseconds: 250), curve: Curves.easeOut, padding: EdgeInsets.only(bottom: mq.viewInsets.bottom), child: ConstrainedBox( constraints: BoxConstraints(maxHeight: screenSize.height), child: Material( color: Colors.white, elevation: 10, shadowColor: Colors.black26, borderRadius: const BorderRadius.vertical(top: Radius.circular(20)), clipBehavior: Clip.antiAlias, child: SingleChildScrollView( padding: EdgeInsets.only(bottom: mq.padding.bottom), child: modalContent, ), ), ), ), ); } } |