skip to Main Content

I trying to change the background color to Black for the app, for now its dark but not pitch black. This is my code

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      theme: ThemeData.dark().copyWith(
        colorScheme: const ColorScheme.dark().copyWith(background: Colors.black),
      ),
      title: "Test",
      home: Scaffold(body: Center(child: Text("Test"))),
    );
  }
}

what mistake am i doing?

2

Answers


  1. change the background color to black, you need to modify the backgroundColor property of the scaffoldBackgroundColor in your ThemeData. Here’s how you can do it:

    class MyApp extends StatelessWidget {
      const MyApp({Key? key});
    
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          debugShowCheckedModeBanner: false,
          theme: ThemeData.dark().copyWith(
            scaffoldBackgroundColor: Colors.black, // Change background color to black
          ),
          title: "Test",
          home: Scaffold(body: Center(child: Text("Test"))),
        );
      }
    }
    
    Login or Signup to reply.
  2. What you are doing is setting the color scheme of app.
    To change to background color of entire app you need to write code like below.

    @override
      Widget build(BuildContext context) {
        return MaterialApp(
          theme: ThemeData.dark().copyWith(
            scaffoldBackgroundColor: const  Color(0xFF000000),
            colorScheme: const ColorScheme.dark().copyWith( background: const Color(0xFF000000)),
          ),
          title: 'Button Types',
          home: const Scaffold(
            body: ButtonTypesExample(),
          ),
        );
      }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search