颤振查询

时间:2020-08-24 20:33:05

标签: firebase flutter authentication dart

import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return FutureBuilder(
      future: Firebase.initializeApp(),
      builder: (context, snapshot) {
        if (snapshot.connectionState == ConnectionState.done) {
          return MaterialApp(
            title: 'Flutter Demo',
            debugShowCheckedModeBanner: false,
            theme: ThemeData(
              scaffoldBackgroundColor: Color(0xFFFFECB3),
              primarySwatch: Colors.orange,
              visualDensity: VisualDensity.adaptivePlatformDensity,
            ),
            home: SignUp(),
          );
        }
      },
    );
  }
}

我的代码显示错误,我是新手。

一个构建函数返回null。 相关的引起错误的小部件是 FutureBuilder <FirebaseApp>

1 个答案:

答案 0 :(得分:1)

尝试以下操作:

import 'package:flutter/material.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp();
  runApp(MyApp());
}
    
class MyApp extends StatelessWidget {

  @override
  Widget build(BuildContext context) {
  return MaterialApp(
    title: 'Flutter Demo',
    debugShowCheckedModeBanner: false,
    theme: ThemeData(
    scaffoldBackgroundColor: Color(0xFFFFECB3),
    primarySwatch: Colors.orange,
    visualDensity: VisualDensity.adaptivePlatformDensity),
    home: SignUp());
          }
     },);
    }