Android emulator 如何在不使用Scafflod的情况下在屏幕上获取简单文本?
我已经清理了Scafflod和button中的颤振示例,并希望得到相同的内容,但没有标题栏和按钮:Android emulator 如何在不使用Scafflod的情况下在屏幕上获取简单文本?,android-emulator,dart,flutter,scaffolding,Android Emulator,Dart,Flutter,Scaffolding,我已经清理了Scafflod和button中的颤振示例,并希望得到相同的内容,但没有标题栏和按钮: void main() => runApp(new MyApp()); class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return new MaterialApp( title: 'My app title', theme: n
void main() => runApp(new MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: 'My app title',
theme: new ThemeData(
primarySwatch: Colors.blue,
),
home: new MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key}) : super(key: key);
@override
_MyHomePageState createState() => new _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
@override
Widget build(BuildContext context) {
return new Center(
child: new Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Text(
'You have pushed the button this many times:',
),
new Text(
'$_counter',
style: Theme.of(context).textTheme.display1,
),
],
),
);
}
}
void main()=>runApp(新的MyApp());
类MyApp扩展了无状态小部件{
@凌驾
小部件构建(构建上下文){
返回新材料PP(
标题:“我的应用程序标题”,
主题:新主题数据(
主样本:颜色。蓝色,
),
主页:新建MyHomePage(),
);
}
}
类MyHomePage扩展StatefulWidget{
MyHomePage({Key}):超级(Key:Key);
@凌驾
_MyHomePageState createState()=>new_MyHomePageState();
}
类_MyHomePageState扩展状态{
int _计数器=0;
@凌驾
小部件构建(构建上下文){
返回新中心(
子:新列(
mainAxisAlignment:mainAxisAlignment.center,
儿童:[
新文本(
“您已经按了这么多次按钮:”,
),
新文本(
“$”计数器“,
样式:Theme.of(context).textTheme.display1,
),
],
),
);
}
}
不幸的是,我得到的不适合任何门:
这是什么?它怎么会变得这么大?如何修复?
Scaffold
正在设置基本的材质设计视觉布局结构,其中包括默认的文本样式等。如果出于任何原因不想使用Scaffold
,则可以使用theme.of(context)
应用当前主题中的相关文本样式和颜色。例如:
Text(
'You have pushed the button this many times:',
style: Theme.of(context).primaryTextTheme.headline,
textAlign: TextAlign.center,
),
您可以将文本包装在“Material”小部件中。此外,使用“style:”参数可以解决问题
Material(
color: Colors.transparent,
child: Text(
"Your Text Here",
style: TextStyle(
fontFamily: 'custom font', // remove this if don't have custom font
fontSize: 20.0, // text size
color: Colors.white, // text color
),
),
)
我应该为任何
文本元素写这篇文章吗?是否存在HTML中的继承?您可以使用DefaultTextStyle
小部件定义要使用的基本文本样式,然后任何后代text
元素都将使用该样式。
Text(
'Sign in / Sign up with',
style: TextStyle(
fontFamily: appFontFamily,
fontSize: 20,
decoration: TextDecoration.none,////set decoration to .none
fontWeight: FontWeight.bold,
color: defaultTitleColor,
),
)