前提・実現したいこと
flutterでFirebaseAuthを使ってログイン機能をつけようとしたら、ビルド時にエラーが怒ってしまい、ビルドできないので助けてください。
発生している問題・エラーメッセージ
Bad state: Tried to read a provider that threw during the creation of its value.
The exception occurred during the creation of type SignUpModel.
[core/no-app] No Firebase App '[DEFAULT]' has been created - call Firebase.initializeApp()
flutterでFirebaseAuthを使ってログイン機能をつけようとしたら、ビルド時にエラーが怒ってしまい、ビルドできないので助けてください。
1
該当のソースコード
エラーで出ているSignUpModelのコードのコード
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:school_memories/pages/login_page.dart';
import 'package:school_memories/pages/signup_model.dart';
class SignUpPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
final mailController = TextEditingController();
final passwordController = TextEditingController();
return ChangeNotifierProvider<SignUpModel>(
create: (_) => SignUpModel(),
child: Scaffold(
backgroundColor: Colors.white,
body: Consumer<SignUpModel>(
builder: (context, model, child) {
return SafeArea(
child: Container(
padding: EdgeInsets.only(left: 16, right: 16),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
SizedBox(
height: 50,
),
Text(
"ようこそ",
style: TextStyle(
fontSize: 26, fontWeight: FontWeight.bold),
),
SizedBox(
height: 6,
),
Text(
"Sign up to get started!",
style: TextStyle(
fontSize: 20, color: Colors.grey.shade400),
),
],
),
Column(
children: <Widget>[
TextField(
decoration: InputDecoration(
labelText: "Email ID",
labelStyle: TextStyle(
fontSize: 14,
color: Colors.grey.shade400,
fontWeight: FontWeight.w600),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
borderSide:
BorderSide(color: Colors.grey.shade300),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
borderSide: BorderSide(color: Colors.red),
),
floatingLabelBehavior: FloatingLabelBehavior.auto,
),controller: mailController,
onChanged: (text) {
model.mail = text;
},
),
SizedBox(
height: 16,
),
TextField(
decoration: InputDecoration(
labelText: "Password",
labelStyle: TextStyle(
fontSize: 14,
color: Colors.grey.shade400,
fontWeight: FontWeight.w600),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
borderSide:
BorderSide(color: Colors.grey.shade300),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
borderSide: BorderSide(color: Colors.red),
),
floatingLabelBehavior: FloatingLabelBehavior.auto,
),obscureText: true,
controller: passwordController,
onChanged: (text) {
model.password = text;
},
),
SizedBox(
height: 30,
),
Container(
height: 50,
child: FlatButton(
onPressed: () async{ try {
await model.signUp();
_showDialog(context, '登録完了しました');
} catch (e) {
_showDialog(context, e.toString());
}},
padding: EdgeInsets.all(0),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(6),
),
child: Ink(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.centerLeft,
end: Alignment.centerRight,
colors: [
Color(0xffaea6c2),
Color(0xff98a3ef),
Color(0xff8e8dcb),
],
),
borderRadius: BorderRadius.circular(6),
),
child: Container(
alignment: Alignment.center,
constraints: BoxConstraints(
minHeight: 50, maxWidth: double.infinity),
child: Text(
"新規登録",
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.white),
textAlign: TextAlign.center,
),
),
),
),
),
SizedBox(
height: 16,
),
SizedBox(
height: 30,
),
],
),
Padding(
padding: const EdgeInsets.only(bottom: 10),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
"すでにアカウントをお持ちですか?",
style: TextStyle(fontWeight: FontWeight.bold),
),
GestureDetector(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => LoginPage(),
),
);
},
child: Text(
"ログイン",
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.red),
),
)
],
),
)
],
),
),
);
},
),
),
);
}
}
Future _showDialog(
BuildContext context,
String title,
) {
return showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Text(title),
actions: <Widget>[
FlatButton(
child: Text('OK'),
onPressed: () {
Navigator.of(context).pop();
},
),
],
);
},
);
}
Dart
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2021/05/23 08:16