Discuz!NT|BBS|论坛

注册

 

发新话题 回复该主题

例子程序2 [复制链接]

1#
import "packagelutter/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 ?"点我禁用":"点我活动",
              styleextStyle(
                  fontSize:32.0,
                  color:Colors.white
              )
          ),
        ),
        width: 200.0,
        height: 200.0,
        decoration: BoxDecoration(
          color: _active?Colors.lightGreen[700]:Colors.grey[600],
        ),
      ),

    );
  }
}
分享 转发
TOP
发新话题 回复该主题