为了开始学习颤动的跨平台应用程序开发,我正在跟随Nick Manning的。但是,在视频的43:47处,我得到以下 error 。
本质上,应用程序类是由Main的RunApp方法的Runapp()方法调用的类。所讨论的代码是themedata小部件的AppBartheme参数。将常数命名的AppBartextStyle作为文本构造函数的参数,而AppBartheme的参数又是AppBartheme的参数。目前,该程序实际上无法实现任何建设性的输出,但是我试图为程序的其余部分设置文本主题,而该主题不起作用。
app.dart and style.dart的代码如下。
// app.dart
import 'package:flutter/material.dart';
import 'screens/location_detail/location_detail.dart';
import 'style.dart';
class App extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: LocationDetail(),
theme: ThemeData(
appBarTheme: AppBarTheme(
textTheme: TextTheme(title: AppBarTextStyle),
),
),
);
}
}
import 'package:flutter/material.dart';
const LargeTextSize = 26.0;
const MediumTextSize = 20.0;
const bodytextSize = 16.0;
const String FontNameDefault = "Montserrat";
const AppBarTextStyle = TextStyle(
fontFamily: FontNameDefault,
fontWeight: FontWeight.w300,
fontSize: MediumTextSize,
color: Colors.white,
);
看完颤动 appbartheme class api api文档,似乎看来自视频发布以来,AppBartheme的构造函数已被贬低。这是“扑面文档”中给出的弃用消息:
@depreced('此属性不再使用,请改用systemoverlayStyle。'''此功能在v2.4.0-0.0.0.pre。
如下提示,我尝试用建议的命名构造函数SystemOverLayStyle替换默认的构造函数。但这是无济于事的,因为我收到以下错误消息。
我不知道如何修复我的代码,非常感谢您的帮助。提前致谢!
In beginning to learn Flutter cross-platform application development, I am following along Nick Manning's Flutter Course - Full Tutorial for Beginners (Build iOS and Android Apps). However, at 43:47 of the video, I am getting the following error.
Essentially, the App class is the class called by the runApp() method of Main's runApp method. The code in question is the appBarTheme parameter of the ThemeData widget. A constant named AppBarTextStyle is given as the argument for the TextTheme constructor, which is in turn an argument for AppBarTheme. At the moment, the program would not really achieve any constructive output, but I am trying to set the text theme for the remainder of the program which does not work.
The code for app.dart and style.dart is given below.
// app.dart
import 'package:flutter/material.dart';
import 'screens/location_detail/location_detail.dart';
import 'style.dart';
class App extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: LocationDetail(),
theme: ThemeData(
appBarTheme: AppBarTheme(
textTheme: TextTheme(title: AppBarTextStyle),
),
),
);
}
}
import 'package:flutter/material.dart';
const LargeTextSize = 26.0;
const MediumTextSize = 20.0;
const bodytextSize = 16.0;
const String FontNameDefault = "Montserrat";
const AppBarTextStyle = TextStyle(
fontFamily: FontNameDefault,
fontWeight: FontWeight.w300,
fontSize: MediumTextSize,
color: Colors.white,
);
After looking at the Flutter AppBarTheme class API documentation, it appears that the constructor for AppBarTheme had been deprecated since the release of the video. This is the deprecation message given in the Flutter documentation:
@Deprecated('This property is no longer used, please use systemOverlayStyle instead. ' 'This feature was deprecated after v2.4.0-0.0.pre.')
As prompted, I tried replacing the default constructor with the suggested named constructor, systemOverlayStyle. But this was to no avail, as I received the following error message.
I have no idea how to fix my code and would very much appreciate some help. Thanks in advance!
发布评论
评论(2)
为了更改AppBar文本主题,您需要使用
ToolbartextStyle
和titletlextStyle
。扩展父主题更好,更好
In order to change appBar text theme, you need to use
toolbarTextStyle
andtitleTextStyle
.It is better with extending parent theme
您应该这样使用它,而不是
texttheme
:You should use it like this instead of
textTheme
: