我正在學習“撰寫您的第一個 Flutter 應用程式”教程,并且已經順利進入第 2 部分第 7 步。然而,上線:
foregroundColor: Colors.black,
VSCode 強調foregroundColor并說:
The named parameter 'foregroundColor' isn't defined
熱多載后它沒有改變顏色,并且不會出現錯誤,除錯控制臺說:
lib/main.dart:17
foregroundColor: Colors.black,
^^^^^^^^^^^^^^^
: Context: Found this candidate, but the arguments don't match.
../…/material/theme_data.dart:219
factory ThemeData({
^
這是完整的build小部件(在MyApp類中):
Widget build(BuildContext context) {
return MaterialApp(
title: 'Startup Name Generator',
theme: ThemeData(
backgroundColor: Colors.white,
foregroundColor: Colors.black,
),
home: RandomWords(),
);
}
更新:我沒有
appBarTheme: const AppBarTheme(
//themes here
),
inside ThemeData,如教程所示。添加后,它起作用了!
uj5u.com熱心網友回復:
Flutter 主題資料不提供前景屬性。但是 appBarThemeData 提供了這一點。像這樣
theme: ThemeData(
// This is the theme of your application.
//
// Try running your application with "flutter run". You'll see the
// application has a blue toolbar. Then, without quitting the app, try
// changing the primarySwatch below to Colors.green and then invoke
// "hot reload" (press "r" in the console where you ran "flutter run",
// or simply save your changes to "hot reload" in a Flutter IDE).
// Notice that the counter didn't reset back to zero; the application
// is not restarted.
backgroundColor: Colors.red,
appBarTheme: const AppBarTheme(foregroundColor: Colors.red),
primarySwatch: Colors.blue,
),
uj5u.com熱心網友回復:
我想你指的是這個代碼實驗室。https://codelabs.developers.google.com/codelabs/first-flutter-app-pt2#6
別擔心,這是一個錯誤。我已經報告了那個。當前ThemeData 類中沒有名為 foregroundColor 的屬性。
現在 Flutter 團隊建議使用 ColorScheme 來定義應用程式的顏色。這是一個相同的例子。
theme: ThemeData(
colorScheme: ColorScheme.light(
primary: Colors.blue,
secondary: Colors.red,
background: Colors.white,
),
appBarTheme: AppBarTheme(
backgroundColor: Colors.white,
elevation: 0,
iconTheme: IconThemeData(color: AppColor.primaryColor)),
scaffoldBackgroundColor: Colors.white);
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/335003.html
下一篇:我有一個關于飛鏢功能的基本問題:
