MaterialApp的主题定制

  • theme 属性应用ThemeData类来固件
import 'package:flutter/material.dart';

void main() =>  runApp(App());

class App extends StatelessWidget {

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold( 
          appBar: AppBar(
            title: Text('顶部工具栏标题'),
            elevation: 10.0, // 设置顶部阴影大小
          ),// 添加顶部工具栏
          body: HelloWidget()
      ), 
      theme: ThemeData(
          primarySwatch: Colors.pink
      ),
    );
  }
}

class HelloWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Center(
        child: Text(
          'Hello Widget',
          textDirection: TextDirection.ltr,
          style: TextStyle(
            fontSize: 45.0,
            fontWeight: FontWeight.bold,
            color: Colors.amberAccent,
          ),
        )
    );
  }
}

在这里插入图片描述

项目地址

Logo

开源鸿蒙跨平台开发社区汇聚开发者与厂商,共建“一次开发,多端部署”的开源生态,致力于降低跨端开发门槛,推动万物智联创新。

更多推荐