cfug / flutter.cn

Flutter CN docs translation plan, get started from the wiki: https://github.com/cfug/flutter.cn/wiki
https://docs.flutter.cn
Other
518 stars 356 forks source link

编写你的第一个 Flutter App [2/2]-7 #1034

Open cuilanxin opened 2 years ago

cuilanxin commented 2 years ago

页面 URL

https://codelabs.flutter-io.cn/codelabs/first-flutter-app-pt2-cn/index.html#6

页面源地址

No response

描述问题

主题并没有发生改变

// 这是我的代码
class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
  final wordPair = WordPair.random();
    return  MaterialApp(
      title: 'Welcome to Flutter', 
        theme: ThemeData(
        primaryColor: Colors.white,
      ), // 程序的主题
      home: Scaffold(
        appBar: AppBar(title: const Text('hello word')),
        body: Center(child: Text(wordPair.asPascalCase))
      )
    );
  }
}
// 这个是文档的代码
class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      title: 'Startup Name Generator',
      theme: new ThemeData(          // 新增代码开始... 
        primaryColor: Colors.white,
      ),                             // ... 代码新增结束
      home: new RandomWords(),
    );
  }
}

期望如何修复

希望知道这个问题是什么

附加信息

No response

cuilanxin commented 2 years ago

当我使用 primarySwatch 替换掉 primaryColor 时,主题颜色发生了改变

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      // ...
      theme: new ThemeData( 
        primarySwatch: Colors.blueGrey,
      ), 
     // ...                   
    );
  }
}