class ParentWidget extends StatefulWidget {
@override
_ParentWidgetState createState () => new _ParentWidgetState();
}
class _ParentWidgetState extends State
{
bool _active = false;
void _handleTapboxChanged(bool newValue) {
setState(() {
_active = newValue;
});
}
@override
Widget build(BuildContext context) {
return new Container(
child: new TapboxB(
active: _active,
onChanged: _handleTapboxChanged,
),
);
}
}
// --------------------- TapboxB ---------------------
class TapboxB extends StatelessWidget {
TapboxB({Key key, this.active: true, @required this.onChanged}) : super(key: key);
final bool active;
final ValueChanged onChanged;
void _handleTap() {
onChanged(!active);
}
Widget build(BuildContext context) {
return new GestureDetector(
onTap: _handleTap,
child: new Container(
child: new Center(
child: new Text(
active ? 'Active' : 'Inactive',
style: new TextStyle(fontSize: 32.0, color: Colors.white)
),
),
width: 200.0,
height: 200.0,
decoration: new BoxDecoration(
color: active ? Colors.lightGreen[700] : Colors.grey[600]
),
),
);
}
}