美文网首页Flutter
Flutter Example 使用主题

Flutter Example 使用主题

作者: 三只仓鼠 | 来源:发表于2018-11-14 12:23 被阅读1次
    image.png
    import 'package:flutter/material.dart';
    
    void main() => runApp(MyApp());
    
    class MyApp extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return new MaterialApp(
            debugShowCheckedModeBanner: false,
            theme: new ThemeData(primaryColor: Colors.green[300]),
            home: new MyHome());
      }
    }
    
    class MyHome extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return new Scaffold(
          appBar: new AppBar(
            title: new Center(
                child: new Text(
              "Home",
              style: TextStyle(
                  color: Colors.white, fontWeight: FontWeight.bold, fontSize: 25.0),
            )),
          ),
          body: new Center(
            child: new Container(
              height: 500.0,
              width: 500.0,
              color: Theme.of(context).primaryColor, //获取主题属性
              child: new Center(
                  child: new Text(
                "Home Page",
                style: Theme.of(context).textTheme.title,
              )),
            ),
          ),
          //悬浮组件
          floatingActionButton: new FloatingActionButton(
            onPressed: null,
            child: new Icon(Icons.shopping_cart),
            backgroundColor: Colors.red,
          ),
        );
      }
    }
    
    

    相关文章

      网友评论

        本文标题:Flutter Example 使用主题

        本文链接:https://www.haomeiwen.com/subject/ctgdfqtx.html