0

我已经尝试了我能想到的一切来改变我的颤振应用程序的背景颜色,但每次我运行应用程序时,背景都是黑色的。

这是 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,
    );
  }
}

我不认为我什至在使用themes/color.dart,但我想我还是会把它留在里面。亮度应该设置它。

这是 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()),
                    );
                  }
              ),
            ]
        )
    );
  }
}

看起来背景应该是浅灰色,但它是黑色的。我尝试使缓存无效并重新启动。

4

0 回答 0