0

这是我的第一次 Flutter Web 体验。有趣的是,这段代码适用于“flutter run”

在此处输入图像描述

颤振医生

[√] Flutter (Channel stable, 2.0.1, on Microsoft Windows [Version 10.0.19041.867], locale tr-TR)

[√] Android 工具链 - 为 Android 设备开发(Android SDK 版本 29.0.2)

[√] Chrome - 为网络开发

[√] Android Studio(3.4版)

[√] IntelliJ IDEA 社区版(2019.1版本)

[√] VS Code,64 位版本(1.54.1 版)

[√] 已连接设备(2 个可用)

索引.html

<body>

  <script src="https://www.gstatic.com/firebasejs/8.3.1/firebase-app.js"></script>
  
  <script src="https://www.gstatic.com/firebasejs/8.3.1/firebase-auth.js"></script>

  <script>
    var firebaseConfig = {
      apiKey: this is private
      authDomain:
      projectId: 
      storageBucket: 
      messagingSenderId: 
      appId: 
    };
    firebase.initializeApp(firebaseConfig);
  </script>
  <script>
    if ('serviceWorker' in navigator) {
      window.addEventListener('flutter-first-frame', function () {
        navigator.serviceWorker.register('flutter_service_worker.js');
      });
    }
  </script>
  <script src="main.dart.js" type="application/javascript"></script>
</body>

主要代码

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

class MyApp extends StatelessWidget {
  FirebaseAuthService _firebaseAuthService= new FirebaseAuthService();
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Todo App',
      home: Container(
        color: Colors.white,
        child: Center(
          child: StreamBuilder(
            stream: _firebaseAuthService.authHandle(),
            builder: (context,AsyncSnapshot<User> snapshot){
              if(snapshot.hasError){
                return Text("There was an error loading data");
              }
              else if (snapshot.connectionState == ConnectionState.waiting){
                return CircularProgressIndicator();
              }
              if(snapshot.data == null){
                return LoginView();
              }
              else{
                return HomeView();
              }
            },
          ),
        ),
      ),
    );
  }
4

0 回答 0