import "package
lutter/material.dart";
void main() => runApp(ManagerSelfState());
class ManagerSelfState extends StatelessWidget {
@override
Widget build(BuildContext context) {
// TODO: implement build
return MaterialApp(
debugShowCheckedModeBanner: false,
title:'Flutter demo',
home:Scaffold(
appBar: AppBar(
title: Text('Flutter demo'),
),
body: Center(
child: Tapbox(),
),
)
);
}
}
class Tapbox extends StatefulWidget {
@override
State<StatefulWidget> createState(){
return _tapboxState();
}
}
class _tapboxState extends State<Tapbox> {
bool _active = false;
void _handleTap(){
setState(() {
_active = !_active;
});
}
@override
Widget build(BuildContext context) {
// TODO: implement build
return GestureDetector(
onTap: _handleTap,
child: Container(
child: Center(
child: Text(
_active ?"点我禁用":"点我活动",
style
extStyle(
fontSize:32.0,
color:Colors.white
)
),
),
width: 200.0,
height: 200.0,
decoration: BoxDecoration(
color: _active?Colors.lightGreen[700]:Colors.grey[600],
),
),
);
}
}