/
auth_page.dart
78 lines (73 loc) · 2.5 KB
/
auth_page.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import '../features/authenticator/authenticator.dart';
/// 強制アップデート情報を取得してダイアログを表示するデモページ
class AuthPage extends HookWidget {
const AuthPage({
Key? key,
}) : super(key: key);
@override
Widget build(BuildContext context) {
final user = useProvider(authenticatorProvider);
final authenticator = useProvider(authenticatorProvider.notifier);
final nameController =
useTextEditingController(text: user?.displayName ?? '');
final hasSigned = user != null;
void _showNameFieldDialog() {
showDialog<void>(
context: context,
builder: (context) {
return AlertDialog(
title: const Text('ニックネーム変更'),
content: TextField(
controller: nameController,
),
actions: [
TextButton(
onPressed: Navigator.of(context).pop,
child: const Text('キャンセル'),
),
TextButton(
onPressed: () {
authenticator.updateDisplayName(nameController.text);
Navigator.of(context).pop();
},
child: const Text('変更'),
),
],
);
},
);
}
return Scaffold(
appBar: AppBar(title: const Text('Authentication')),
body: SafeArea(
child: ListView(
padding: const EdgeInsets.all(32),
children: [
Text('ログイン状態:${hasSigned ? 'ログイン済み' : '未ログイン'}'),
const SizedBox(height: 16),
if (hasSigned) ...[
Text('ニックネーム:${user!.displayName ?? '名無し'}'),
const SizedBox(height: 16),
ElevatedButton(
onPressed: _showNameFieldDialog,
child: const Text('ニックネーム変更'),
),
const SizedBox(height: 16),
OutlinedButton(
onPressed: authenticator.deleteAccount,
child: const Text('アカウント削除'),
),
] else
ElevatedButton(
onPressed: authenticator.signInWithAnonymous,
child: const Text('匿名アカウント作成'),
),
],
),
),
);
}
}