Flutter Widget框架概述

1、更换主题

import 'package:flutter/foundation.dart';

import 'package:flutter/material.dart';

void main() {

  runApp(new MyApp());

}

class MyApp extends StatelessWidget {

  @override

  Widget build(BuildContext context) {

    final appName = 'Custom Themes';

    return new MaterialApp(

      title: appName,

      theme: new ThemeData(

        brightness: Brightness.dark,

        primaryColor: Colors.lightBlue[800],

        accentColor: Colors.cyan[600],

      ),

      home: new MyHomePage(

        title: appName,

      ),

    );

  }

}

class MyHomePage extends StatelessWidget {

  final String title;

  MyHomePage({Key key, @required this.title}) : super(key: key);

  @override

  Widget build(BuildContext context) {

    return new Scaffold(

      appBar: new AppBar(

        title: new Text(title),

      ),

      body: new Center(

        child: new Container(

          color: Theme.of(context).accentColor,

          child: new Text(

            'Text with a background color',

            style: Theme.of(context).textTheme.title,

          ),

        ),

      ),

      floatingActionButton: new Theme(

        data: Theme.of(context).copyWith(accentColor: Colors.yellow),

        child: new FloatingActionButton(

          onPressed: null,

          child: new Icon(Icons.add),

        ),

      ),

    );

  }

}

2、

![20190307100759-QQ20190306-172058.png](https://raw.githubusercontent.com/931743010/YosoroImage/master/img/20190307100759-QQ20190306-172058.png?token=AI4lj-DCBPDimXVnZz6b6GdBFN0WRTXTks5cgH09wA%3D%3D)

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容