text_tools_overlay.dart (6162B)
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 | import 'package:flutter/material.dart'; import 'package:flutter_colorpicker/flutter_colorpicker.dart'; import '../../styles/variables.dart'; class TextToolsOverlay extends StatelessWidget { final bool isActive; final bool isTextSelected; final Color currentColor; final double currentFontSize; final VoidCallback onClose; final VoidCallback onAddText; final Function(Color) onColorChanged; final Function(double) onFontSizeChanged; const TextToolsOverlay({ super.key, required this.isActive, required this.isTextSelected, required this.currentColor, required this.currentFontSize, required this.onClose, required this.onAddText, required this.onColorChanged, required this.onFontSizeChanged, }); @override Widget build(BuildContext context) { if (!isActive) return const SizedBox.shrink(); return Positioned( bottom: 100 + MediaQuery.of(context).padding.bottom, left: 0, right: 0, child: Center( child: Container( margin: const EdgeInsets.symmetric(horizontal: 20), padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8), decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.circular(30), boxShadow: [ BoxShadow( color: Colors.black.withOpacity(0.15), blurRadius: 12, offset: const Offset(0, 6), ), ], ), // Prevent overflow if screen is narrow child: SingleChildScrollView( scrollDirection: Axis.horizontal, child: Row( mainAxisSize: MainAxisSize.min, children: [ IconButton( icon: const Icon( Icons.check_circle, color: Variables.textPrimary, ), onPressed: onClose, tooltip: "Done", ), Container(width: 1, height: 20, color: Variables.borderSubtle), const SizedBox(width: 8), IconButton( icon: const Icon( Icons.add_circle_outline, color: Variables.textPrimary, ), onPressed: onAddText, tooltip: "Add Text", ), if (isTextSelected) ...[ const SizedBox(width: 8), Container( width: 1, height: 20, color: Variables.borderSubtle, ), const SizedBox(width: 12), const Icon( Icons.text_fields, size: 18, color: Variables.textSecondary, ), SizedBox( width: 100, child: SliderTheme( data: SliderThemeData( trackHeight: 2, thumbShape: const RoundSliderThumbShape( enabledThumbRadius: 6, ), activeTrackColor: Variables.textPrimary, inactiveTrackColor: Variables.borderSubtle, thumbColor: Colors.black, overlayShape: SliderComponentShape.noOverlay, ), child: Slider( value: currentFontSize.clamp(10.0, 200.0), min: 10.0, max: 200.0, onChanged: onFontSizeChanged, ), ), ), const SizedBox(width: 12), GestureDetector( onTap: () => _showColorPicker(context), child: Container( width: 24, height: 24, decoration: BoxDecoration( color: currentColor, shape: BoxShape.circle, border: Border.all( color: Variables.borderSubtle, width: 1, ), ), ), ), const SizedBox(width: 8), ], ], ), ), ), ), ); } void _showColorPicker(BuildContext context) { showModalBottomSheet( context: context, backgroundColor: Colors.transparent, builder: (ctx) => Container( padding: const EdgeInsets.all(24), decoration: const BoxDecoration( color: Colors.white, borderRadius: BorderRadius.vertical(top: Radius.circular(24)), ), child: SafeArea( child: Column( mainAxisSize: MainAxisSize.min, children: [ Text( "Text Color", style: Variables.headerStyle.copyWith(fontSize: 16), ), const SizedBox(height: 20), BlockPicker( pickerColor: currentColor, onColorChanged: (c) { onColorChanged(c); Navigator.pop(ctx); }, layoutBuilder: (context, colors, child) => SizedBox( width: 300, height: 160, child: GridView.count( crossAxisCount: 5, crossAxisSpacing: 10, mainAxisSpacing: 10, children: [ for (Color color in colors) child(color), ], ), ), ), ], ), ), ), ); } } |