Flutter

Flutter Example 使用主题

2018-11-14  本文已影响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,
      ),
    );
  }
}

上一篇下一篇

猜你喜欢

热点阅读