Flutter学习 — 设计基础

效果图:

在这里插入图片描述

代码+注释:

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,
          ),
        ),
      ),
    );
  }
}

喜欢记得点个赞哟,我叫王睿很高兴认识大家!

更多原理请参考谷歌官网:
使用主题共享颜色和字体样式

猜你喜欢

转载自blog.csdn.net/qq_27494201/article/details/106840048