FlutterとFirebaseを使ってアプリを制作しています。
FlutterでLoginPageとProfilePageを作成し、サインインしてるかどうかをRootPageで判定、判定後どちらか(ログインしてればProfile、してなければLogin)に飛ばす処理を実装しようとしています。
RootPageのif(user == null)
の部分をビルドしてからif(user != null)
などに変えてリロードすればエラーコードが消え、LoginPageもProfileも表示されるのですがビルドしてすぐだとエラーが表示されてしまいます。できれば参考通り、StreamBuilderで処理したいです。
どうしたらいいのでしょうか;;
(↓の参考で言うLandingPage)
ErrorCode
1I/flutter (19880): user:0eiBglEEHRgQFS8Y4LSarodMqfD2 2I/flutter (19880): user:はるのん 3I/flutter (19880): ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════ 4I/flutter (19880): The following assertion was thrown building Profile(dirty, state: _ProfileState#1ed5a): 5I/flutter (19880): A non-null String must be provided to a Text widget. 6I/flutter (19880): 'package:flutter/src/widgets/text.dart': 7I/flutter (19880): Failed assertion: line 298 pos 10: 'data != null' 8I/flutter (19880): 9I/flutter (19880): The relevant error-causing widget was: 10I/flutter (19880): Profile file:///Users/harunon/Projects/makeup/lib/root_page.dart:24:20 11I/flutter (19880): 12I/flutter (19880): When the exception was thrown, this was the stack: 13I/flutter (19880): #2 new Text (package:flutter/src/widgets/text.dart:298:10) 14I/flutter (19880): #3 _ProfileState.build (package:makeup/profile.dart:20:16) 15I/flutter (19880): #4 StatefulElement.build (package:flutter/src/widgets/framework.dart:4619:28) 16I/flutter (19880): #5 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4502:15) 17I/flutter (19880): #6 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4675:11) 18I/flutter (19880): #7 Element.rebuild (package:flutter/src/widgets/framework.dart:4218:5) 19I/flutter (19880): #8 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4481:5) 20I/flutter (19880): #9 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4666:11) 21I/flutter (19880): #10 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4476:5) 22I/flutter (19880): #11 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3446:14) 23I/flutter (19880): #12 Element.updateChild (package:flutter/src/widgets/framework.dart:3211:20) 24I/flutter (19880): #13 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4527:16) 25I/flutter (19880): #14 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4675:11) 26I/flutter (19880): #15 Element.rebuild (package:flutter/src/widgets/framework.dart:4218:5) 27I/flutter (19880): #16 BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2627:33) 28I/flutter (19880): #17 WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:883:20) 29I/flutter (19880): #18 RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:284:5) 30I/flutter (19880): #19 SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1113:15) 31I/flutter (19880): #20 SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1052:9) 32I/flutter (19880): #21 SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:968:5) 33I/flutter (19880): #25 _invoke (dart:ui/hooks.dart:261:10) 34I/flutter (19880): #26 _drawFrame (dart:ui/hooks.dart:219:3) 35I/flutter (19880): (elided 5 frames from class _AssertionError and dart:async) 36I/flutter (19880): 37I/flutter (19880): ════════════════════════════════════════════════════════════════════════════════════════════════════ 38
下記実装コードです
RootPage
1import 'package:firebase_auth/firebase_auth.dart'; 2import 'package:flutter/material.dart'; 3import 'package:makeup/login_page.dart'; 4import 'package:makeup/profile.dart'; 5 6class RootPage extends StatelessWidget { 7 @override 8 Widget build(BuildContext context) { 9 return StreamBuilder<FirebaseUser>( 10 stream: FirebaseAuth.instance.onAuthStateChanged, 11 builder: (context, snapshot) { 12 if (snapshot.connectionState == ConnectionState.active) { 13 FirebaseUser user = snapshot.data; 14 print('user:' + user.uid); 15 if (user != user) { 16 return LoginPage(); 17 } else { 18 print('user:' + user.displayName); 19 return Profile(user: user); 20 } 21 } else { 22 return Scaffold( 23 body: Center( 24 child: CircularProgressIndicator(), 25 ), 26 ); 27 } 28 }, 29 ); 30 } 31} 32
他の場所が間違っている可能性もあるのですべてのコードを載せておきます
https://github.com/harunonsystem/makeuplist
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/07/11 13:52