今回は「flutter Authentication」に手動でユーザー登録する方法を紹介します。
目次
ユーザーを手動登録する手順

「Firebaseプロジェクト > Authentication」から「ユーザーを追加」をクリックします。

ユーザーのメールアドレスとパスワードを入力し「ユーザーを追加」をクリックします。

これでユーザーの登録は完了です。
Flutterアプリからサインインする

Firebase Authenticationで登録したユーザーでログインできるか下のコードを使って試してみてください。(pubspec.yamlの更新を忘れないように)
登録したメールアドレスとパスワードをそれぞれ、変数「_email」「_password」に代入してステータスバーのアイコンをクリックすれば登録メールアドレスが出力されます。
import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
runApp(MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
final _auth = FirebaseAuth.instance;
final _email = 'flutter@gmail.com'; //登録ユーザーのメールアドレス
final _password = 'flutter'; //登録ユーザーのパスワード
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('Chat'),
actions: [
IconButton(
onPressed: () async {
var loginUser = await _auth.signInWithEmailAndPassword(
email: _email, password: _password);
if (_auth.currentUser != null) {
print('ログインユーザー:${_auth.currentUser!.email}');
}else{
print('ログインに失敗しました');
}
},
icon: Icon(Icons.check),
),
],
),
),
);
}
}
以上です。