Home > OS >  MaterialApp's theme primary color doesn't work
MaterialApp's theme primary color doesn't work

Time:10-16

On this flutter sample secondary color works fine but primary color doesn't seem to work why is that?

class MyApp extends StatelessWidget {
  
  @override
  Widget build(BuildContext context) {
    final ThemeData theme = ThemeData();
   
    return MaterialApp(
      
      theme: theme.copyWith(
        colorScheme: theme.colorScheme.copyWith(
          primary: Colors.blue,
          secondary: Colors.orange,
        )
      ),
      
      home: MyHomePage(),
    );
  }
}

CodePudding user response:

Try this

theme: ThemeData( primaryColor: Colors.lightBlue[800], accentColor: Colors.yellow, ),

CodePudding user response:

class MyApp extends StatelessWidget {
  
  @override
  Widget build(BuildContext context) {
    final ThemeData theme = ThemeData();
   
    return MaterialApp(
      
     theme: ThemeData(
    colorScheme: ColorScheme.fromSwatch(
      primarySwatch: Colors.blue,
    ).copyWith(
      secondary: Colors.green,
    ),
      
      home: MyHomePage(),
    ));
  }
}
  • Related