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
| class ParentWidgetC extends StatefulWidget { @override State<StatefulWidget> createState() => _ParentWidgetCState(); }
class _ParentWidgetCState extends State<ParentWidgetC> { bool _active = false;
void _handleTapboxChanged(bool newValue) { setState(() { _active = newValue; }); }
@override Widget build(BuildContext context) { return TapboxC(active: _active, onChanged: _handleTapboxChanged); } }
class TapboxC extends StatefulWidget { TapboxC({Key? key, this.active = false, required this.onChanged}) : super(key: key); final bool active; final ValueChanged<bool> onChanged;
@override State<StatefulWidget> createState() => _TapboxCState(); }
class _TapboxCState extends State<TapboxC> { bool _highlight = false;
void _handleTapDown(TapDownDetails details) { setState(() { _highlight = true; }); }
void _handleTapUp(TapUpDetails details) { setState(() { _highlight = false; }); }
void _handleTaoCancel() { setState(() { _highlight = false; }); }
void _handleTap() { widget.onChanged(!widget.active); }
@override Widget build(BuildContext context) { return GestureDetector( onTapDown: _handleTapDown, onTapUp: _handleTapUp, onTap: _handleTap, onTapCancel: _handleTaoCancel, child: Container( width: 150.0, height: 150.0, decoration: BoxDecoration( color: widget.active ? Colors.lightGreen[700] : Colors.grey[600], border: _highlight ? Border.all(color: Colors.teal, width: 10.0) : null, ), child: Center( child: Text(widget.active ? 'Active' : 'Inactive', style: TextStyle(fontSize: 32.0, color: Colors.white))), ), ); } }
|
v1.5.2