flutter appbartheme类构造者弃用

发布于 2025-02-13 21:45:45 字数 1850 浏览 1 评论 0 原文

为了开始学习颤动的跨平台应用程序开发,我正在跟随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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

苯莒 2025-02-20 21:45:45

为了更改AppBar文本主题,您需要使用 ToolbartextStyle titletlextStyle

theme: ThemeData(
  appBarTheme: AppBarTheme(
    toolbarTextStyle: TextStyle(..),
    titleTextStyle: TextStyle(..),
  ),
),

扩展父主题更好,更好

更好的丰富内容是 cookbook/design/themes

In order to change appBar text theme, you need to use toolbarTextStyle and titleTextStyle.

theme: ThemeData(
  appBarTheme: AppBarTheme(
    toolbarTextStyle: TextStyle(..),
    titleTextStyle: TextStyle(..),
  ),
),

It is better with extending parent theme

A better rich content is cookbook/design/themes

愛上了 2025-02-20 21:45:45

您应该这样使用它,而不是 texttheme

 MaterialApp(
      theme: ThemeData(
        appBarTheme: AppBarTheme(
          color: darkBlue,
          toolbarTextStyle: const TextTheme(
            headline6: TextStyle(
              color: Colors.white,
              fontSize: 20,
            ),
          ).bodyText2,
          titleTextStyle: const TextTheme(
            headline6: const TextStyle(
              color: Colors.white,
              fontSize: 20,
            ),
          ).headline6,
        ),
      ),
      home: SafeArea(
        child: const Scaffold(
          body: MyStatefulWidget(),
        ),
      ),
    );

You should use it like this instead of textTheme:

 MaterialApp(
      theme: ThemeData(
        appBarTheme: AppBarTheme(
          color: darkBlue,
          toolbarTextStyle: const TextTheme(
            headline6: TextStyle(
              color: Colors.white,
              fontSize: 20,
            ),
          ).bodyText2,
          titleTextStyle: const TextTheme(
            headline6: const TextStyle(
              color: Colors.white,
              fontSize: 20,
            ),
          ).headline6,
        ),
      ),
      home: SafeArea(
        child: const Scaffold(
          body: MyStatefulWidget(),
        ),
      ),
    );
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文