0

I've tried everything I can think of to change the background color of my flutter app, but every time I run the app, the background is black.

This is main.dart

import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'auth_controller.dart';
import 'themes/color.dart';
import 'index.dart';

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
   await Firebase.initializeApp().then((value) => Get.put(AuthController));
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      //ThemeData
      title: 'Title',
      theme: ThemeData(
        brightness: Brightness.light,
      ),
      home:const Index(),
      debugShowCheckedModeBanner: false,
    );
  }
}

I don't think I'm even using themes/color.dart but I thought I'd leave it in anyway. Brightness should set it.

This is index.dart

import 'package:flutter/material.dart';
import 'themes/color.dart';
import 'signup.dart';

Future<void> main() async {
  runApp(MyApp(
    routes: <String, WidgetBuilder>{
      '/signup': (BuildContext context) => const SignUp()
    },
    debugShowCheckedModeBanner: false,
  ));
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key, required Map<String, WidgetBuilder> routes, required bool debugShowCheckedModeBanner}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Welcome to Flutter',
      home: Scaffold(
        backgroundColor: const Color(0xFFe3e4e4),
        appBar: AppBar(
          title: const Text('Flutter Screen Background Color Example'),
        ),
        body: const Center(child: Index()),
      ),
    );
  }
}

class Index extends StatelessWidget {
  const Index({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Center(
        child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              const SizedBox(height: 20,),
              ElevatedButton(
                  child: const Text('WTF'),
                  onPressed: () {
                    Navigator.push(
                      context,
                      MaterialPageRoute(
                          builder: (context) => const SignUp()),
                    );
                  }
              ),
            ]
        )
    );
  }
}

It seems like the background should be a light grey,but it's black. I tried invalidating the caches and restarting too.

tdrsam
  • 527
  • 1
  • 8
  • 28
  • I am having trouble to understand the code-snippet. on `main()` there is no `MyApp()` initialization. can you update the question if there any typo-error? – Md. Yeasin Sheikh Nov 05 '21 at 10:55
  • Do you mean ```main.dart``` because it's got ```runApp(const MyApp());``` – tdrsam Nov 05 '21 at 10:59
  • yes , also the cant find root on route. And is there any specific reason of having two different `main` with `MaterialApp` – Md. Yeasin Sheikh Nov 05 '21 at 11:12
  • I'm not sure I follow. Are you talking about the ```Future main``` in main.dart and ```void main()``` in index.dart? Also, what does this have to do with the background? – tdrsam Nov 05 '21 at 11:18
  • could be, Those two are using different `MaterialApp` – Md. Yeasin Sheikh Nov 05 '21 at 11:20
  • I edited the code according to what I think you're suggesting. It's getting a bit late here though. It still hasn't changed the background. – tdrsam Nov 05 '21 at 11:40

0 Answers0