微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

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

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐