Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
cuilanxin opened this issue Feb 17, 2022 · 1 comment
Open

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

cuilanxin opened this issue Feb 17, 2022 · 1 comment
Labels
E: 页面问题 页面内容有误或需要改进。

Comments

@cuilanxin
Copy link

页面 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 cuilanxin added the E: 页面问题 页面内容有误或需要改进。 label Feb 17, 2022
@cuilanxin
Copy link
Author

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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E: 页面问题 页面内容有误或需要改进。
Projects
None yet
Development

No branches or pull requests

1 participant