I’m working through the Flutter apprentice chapter 1. My Widget colour wont change from blue to grey in the IOS simulator. does anyone know why?
import ‘package:flutter/material.dart’;
void main() {
runApp(Recipieapp());
}
class Recipieapp extends StatelessWidget {
// This widget is the root of your application.
// 1
@override
Widget build(BuildContext context) {
// 2
final ThemeData theme = ThemeData();
// 3
return MaterialApp(
// 4
title: ‘Recipe Calculator’,
// 5
theme: theme.copyWith(
colorScheme: theme.colorScheme.copyWith(
primary: Colors.grey,
secondary: Colors.black,
),
),
// 6
home: MyHomePage(title: ‘Recipe Calculator’),
);
}
}
jomoka
October 15, 2021, 5:56am
2
@nedlington91 did you manage to get it to work? What you have there looks fine!
You can also check out the final project to see if you did anything wrong.
Yeah It’s interesting. The only thing that differs is I had to remove the const from line
home: const MyHomePage(title: ‘Recipe Calculator’)
the other interesting thing is the colours in the script change to grey and black but when run on the simulator it remains as blue. it stays blue even is I hot reload, restart or fully shut down and restart everything
jomoka
October 18, 2021, 4:51am
4
@nedlington91 maybe this forum post may help?
@salmankhilji thanks for the interesting question.
By diving into the ThemeData documentation and implementation here is the reason why the background color is blue vs white in some cases.
Using ThemeData Constructor
When you used the ThemeData constructor:
ThemeData(
colorScheme: Theme.of(context).colorScheme.copyWith(
primary: Colors.grey,
secondary: Colors.black,
),
),
By default scaffoldBackgroundColor takes the canvasColor as shown …