gpt4 book ai didi

尝试添加原色时,Flutter ThemeData 原色不会与主题发生变化

转载 作者:行者123 更新时间:2023-12-04 13:06:36 27 4
gpt4 key购买 nike

我在 LinkedIn Learning 上关注来自 London App Brewery 的 BMI Calculator 应用程序。
尝试将primaryColor设置为红色时,即使我覆盖了Primary Color,我的模拟器仍然显示Light Blue默认AppBar。这是代码

    import 'package:flutter/material.dart';

void main() {
runApp(const MyApp());
}

class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);

// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(
primaryColor: Colors.red,
),
home: const InputPage(),
);
}
}

class InputPage extends StatefulWidget {
const InputPage({Key? key}) : super(key: key);

@override
_InputPageState createState() => _InputPageState();
}

class _InputPageState extends State<InputPage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('BMI CALCULATOR'),
),
body: const Center(
child: Text('Body Text'),
),
floatingActionButton: FloatingActionButton(
onPressed: () {},
child: const Icon(Icons.add),
),
);
}
}

最佳答案

使用主色板

theme: ThemeData(
primarySwatch: Colors.red,
),

关于尝试添加原色时,Flutter ThemeData 原色不会与主题发生变化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69169306/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com