如何定义一小组自定义文本样式,然后可以在我的应用程序中重复使用它们。自定义文本样式应基于主题中定义的文本样式。
我知道如何创建单独的 TextStyles (例如)
Theme.of(context).textTheme.title.copyWith(fontWeight: FontWeight.bold,)
您可以创建一个提供获取字体样式的方法的类。
这是一个声明的示例CustomTextStyle
公开一个类display5
非常大的文本的方法。
import 'package:flutter/material.dart';
void main() {
runApp(new MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
home: new HomePage(),
);
}
}
class CustomTextStyle {
static TextStyle display5(BuildContext context) {
return Theme.of(context).textTheme.display4.copyWith(fontSize: 192.0);
}
}
class HomePage extends StatelessWidget {
@override
Widget build(BuildContext context) => new Scaffold(
appBar: new AppBar(
title: new Text('Custom Font Example'),
),
body: new Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
new Card(
child: new Container(
child: new Text(
'Wow',
style: CustomTextStyle.display5(context),
),
),
),
],
),
);
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)