Skip to content

Commit

Permalink
Merge pull request #121 from kosukesaigusa/root
Browse files Browse the repository at this point in the history
Root
  • Loading branch information
kosukesaigusa committed Aug 7, 2023
2 parents f473057 + 9921428 commit 08bdb67
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,14 @@ final initializeFirebaseMessagingProvider =

/// FCM トークンを取得する [Provider].
final getFcmTokenProvider = Provider.autoDispose<Future<String?> Function()>(
(ref) => () => ref.read(firebaseMessagingProvider).getToken(),
(ref) => () async {
final token = await ref.read(firebaseMessagingProvider).getToken();
if (token == null) {
return null;
}
debugPrint('🔥 FCM token: $token');
return token;
},
);

/// terminated (!= background) の状態から、通知によってアプリを開いた場合に非 null となる
Expand Down
45 changes: 45 additions & 0 deletions packages/mottai_flutter_app/lib/root/ui/root.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import 'package:auto_route/auto_route.dart';
import 'package:flutter/material.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';

import '../../push_notification/firebase_messaging.dart';

/// メインの [BottomNavigationBar] を含む画面。
@RoutePage()
class RootPage extends ConsumerStatefulWidget {
const RootPage({super.key});

/// [AutoRoute] で指定するパス文字列。
static const path = '/';

/// [RootPage] に遷移する際に `context.router.pushNamed` で指定する文字列。
static const location = path;

@override
ConsumerState<RootPage> createState() => _RootPageState();
}

class _RootPageState extends ConsumerState<RootPage> {
@override
void initState() {
super.initState();
Future.wait<void>([
ref.read(initializeFirebaseMessagingProvider)(),
ref.read(getFcmTokenProvider)(),
]);
}

@override
Widget build(BuildContext context) {
return Scaffold(
bottomNavigationBar: BottomNavigationBar(
items: const [
BottomNavigationBarItem(icon: Icon(Icons.map)),
BottomNavigationBarItem(icon: Icon(Icons.chat)),
BottomNavigationBarItem(icon: Icon(Icons.reviews)),
BottomNavigationBarItem(icon: Icon(Icons.person)),
],
),
);
}
}

0 comments on commit 08bdb67

Please sign in to comment.