如何在没有 Flutter 脚手架的情况下在屏幕上获取简单文本?
How to get simple text on screen without Scafflod in Flutter?
我已经从 Scafflod 和按钮中清除了 Flutter 示例,并期待我得到相同的内容,但没有标题栏和按钮:
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,
),
],
),
);
}
}
不幸的是,我得到的东西不适合任何门:
这是什么?怎么变这么大?如何解决?
Scaffold
正在设置基本的 material 设计视觉布局结构,其中包括默认文本样式等。如果您出于任何原因不想使用 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
),
),
)
Text(
'Sign in / Sign up with',
style: TextStyle(
fontFamily: appFontFamily,
fontSize: 20,
decoration: TextDecoration.none,////set decoration to .none
fontWeight: FontWeight.bold,
color: defaultTitleColor,
),
)
我已经从 Scafflod 和按钮中清除了 Flutter 示例,并期待我得到相同的内容,但没有标题栏和按钮:
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,
),
],
),
);
}
}
不幸的是,我得到的东西不适合任何门:
这是什么?怎么变这么大?如何解决?
Scaffold
正在设置基本的 material 设计视觉布局结构,其中包括默认文本样式等。如果您出于任何原因不想使用 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
),
),
)
Text(
'Sign in / Sign up with',
style: TextStyle(
fontFamily: appFontFamily,
fontSize: 20,
decoration: TextDecoration.none,////set decoration to .none
fontWeight: FontWeight.bold,
color: defaultTitleColor,
),
)