Flutter基础知识

18 篇文章 0 订阅
6 篇文章 0 订阅

程序入口和Theme
在这里插入图片描述
StatelessWidget和StatefulWidget

class MyApp extends StatelessWidget {
  // This widget is the root of your application.这是我的APP的基底
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.deepOrange,
      ),
      home: MyHomePage(
          title: 'Flutter Demo Home Page'),
    );
  }
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  void _incrementCounter() {//变化数据的注册
    setState(() {
      // 可变化的数据,以及数据变化的方式
      _counter++;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(
          widget.title,
          textAlign: TextAlign.right,
          maxLines: 1,
          overflow: TextOverflow.fade,
          style: TextStyle(
            fontSize: 40,
            color: Colors.white,
            decoration: TextDecoration.underline,
            decorationStyle: TextDecorationStyle.wavy,
          ),
        ),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text.rich(TextSpan(children: [
              TextSpan(
                  text: "You know who\n ",
                  style: TextStyle(
                    color: Colors.green,
                    fontSize: 34,
                  )),
              TextSpan(text: " have pushed the button this many times:,")
            ])),
            Text(
              '$_counter',//变化数据的使用
              style: Theme
                  .of(context)
                  .textTheme
                  .display1,
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,//这里就是点击事件的触发
        tooltip: 'Increment',
        child: Icon(Icons.add),
      ), 
    );
  }
}

使用资源包

站在巨人肩膀上:https://pub.dartlang.org

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值