一、Flutter 应用主题 Flutter 应用主题都封装在 ThemeData 类中 , 在 MaterialApp 的 theme 字段 , 可以设置 ThemeData 主题 , 可设置的选项如下 , 下面的 ThemeData 工厂构造函数中的可选参数就是可以设置的各种主题选项 ; class ThemeData extends Diagnosticable {factory ThemeData({Brightness brightness,MaterialCol...
六、使用 SafeArea 进行全面屏适配 代码语言:javascript 代码运行次数:0 运行 AI代码解释 import'package:flutter/material.dart';voidmain(){runApp(MyApp());}classMyAppextendsStatelessWidget{@override Widgetbuild(BuildContext context){returnMaterialApp(title:'Flutter Demo',theme:ThemeData(primarySwatch:Colors.b...
chevron_right), onTap: () { print('点击事件:点击了 ListTile === title为:$data'); }, onLongPress: () { print('长按事件:长按了 ListTile === title为:$data'); }, selected: true, ), Text( '${widget.counter}', style: Theme.of(context).textTheme.display1, ), Text( '${widget...
theme: ThemeData( primarySwatch: Colors.blue, ), // home: MyHomePage(title: 'Flutter Demo Home Page'), /// FairWidget 是用来加载 bundle 资源的容器 /// /// path 参数:需要加载的 bundle 资源文件路径 /// data 参数:需要传递给动态页面的参数 home: FairWidget( /// path 可以是 assets 目录...
我们经常通过这样的方式,通过BuildContext,可以拿到Theme和MediaQuery 代码语言:javascript 代码运行次数:0 运行 AI代码解释 //得到状态栏的高度 var statusBarHeight = MediaQuery.of(context).padding.top; //复制合并出新的主题 var copyTheme =Theme.of(context).copyWith(primaryColor: Colors.blue); 看到of的...
}class_ThemeRouteDemoState extends State<ThemeRouteDemo>{ Color _themeColor= Colors.green;//当前路由主题色 (改变主题色)@override Widget build(BuildContext context) { ThemeData themeData=Theme.of(context);returnTheme( data: ThemeData( primarySwatch: _themeColor,//用于导航栏、FloatingActionButton的背景...
Theme 是一个单子Widget 容器,可以通过设置其 data 属性,对其子 Widget 进行样式定制: 如果不想继承 App 全局的颜色或字体样式,可以直接新建一个 ThemeData 实例 如果想继承大部分 App 的主题,同时只更新小部分样式,可以使用 copyWith 方法 dart class _HomePageState extends State<HomePage> { double size = 30...
class _ThemeTestRouteState extends State<ThemeTestRoute> { Color _themeColor = Colors.teal; //当前路由主题色 @override Widget build(BuildContext context) { ThemeData themeData = Theme.of(context); return Theme( data: ThemeData( primarySwatch: _themeColor, //用于导航栏、FloatingActionButton的背景...
StoreConnector<int, String>( converter: (store) => store.state.toString(), builder: (context, count) { return Text( 'The button has been pushed this many times: $count', style: Theme.of(context).textTheme.display1, ); }, ) ], ), ), // Connect the Store to a FloatingAction...
style: Theme.of(context).textTheme.headlineMedium, ); } } BLoC/Cubit: 基于块模式构建,将业务逻辑与用户界面解耦,适用于复杂的状态管理。 https://pub.dev/packages/flutter_bloc Bloc 架构 https://bloclibrary.dev/#/zh-cn/coreconcepts?id=bloc ...