Flutter Example 使用主题

《Flutter Example 使用主题》 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,
      ),
    );
  }
}

    原文作者:三只仓鼠
    原文地址: https://www.jianshu.com/p/63057f785eaa
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞