-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
【WIP】FCMトークンの登録 #180
【WIP】FCMトークンの登録 #180
Conversation
|
||
/// [FcmTokenRepository] のインスタンス。 | ||
final _fcmTokenRepository = FcmTokenRepository(); | ||
final _token = await ref.read(getFcmTokenProvider).call(); | ||
final _userId = ref.read(userIdProvider); | ||
|
||
final _deviceInfo = await getDeviceInfo(); | ||
|
||
if (_token == null || _userId == null) { | ||
return; | ||
} | ||
|
||
await _fcmTokenRepository.setUserFcmToken( | ||
userId: _userId, | ||
token: _token, | ||
deviceInfo: _deviceInfo, | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
こんな感じでやりたい事あってますでしょうか??
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
内容はあっています!が、他の書き込み処理を参考にサービスクラスをつくってそこで set の処理を書いてみてください!!(UI は Repository に直接依存させない、Repository とやりとりするのはモデルであるべき)
// TODO: パッケージ依存なのでcommonではない? | ||
Future<String> getDeviceInfo() async { | ||
final _deviceInfoPlugin = DeviceInfoPlugin(); | ||
late final String _os; | ||
late final String _osVersion; | ||
late final String _device; | ||
|
||
if (Platform.isAndroid) { | ||
final _androidInfo = await _deviceInfoPlugin.androidInfo; | ||
_os = 'Android'; | ||
_osVersion = _androidInfo.version.release; | ||
_device = _androidInfo.device; | ||
} else if (Platform.isIOS) { | ||
final _iosInfo = await _deviceInfoPlugin.iosInfo; | ||
_os = 'iOS'; | ||
_osVersion = _iosInfo.systemVersion; | ||
_device = _iosInfo.utsname.machine; | ||
} else { | ||
_os = ''; | ||
_osVersion = ''; | ||
_device = ''; | ||
} | ||
|
||
final _deviceInfo = 'os: $_os, osVersion: $_osVersion, device: $_device'; | ||
return _deviceInfo; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
こんな感じでやりたい事あってますでしょうか??
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
あっていると思います!
else は考えなくていい気もするので throw UnimplementedError
とかでも良いかもしれません!
また、late final
みたいなことは特にせずに単にそれぞれの if 句 else if 句の中で return した方が読みやすいようにも感じます!
/// 指定した [userId], [token]、[deviceInfo]をもとに ユーザーのFCMトークン情報を作成する。 | ||
Future<void> setUserFcmToken({ | ||
required String userId, | ||
required String token, | ||
required String deviceInfo, | ||
}) => | ||
_query.set( | ||
userFcmTokenId: token, | ||
createUserFcmToken: CreateUserFcmToken( | ||
userId: userId, | ||
token: token, | ||
deviceInfo: deviceInfo, | ||
), | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
とても良いです!!
/// 指定した [UserFcmToken] を取得する [FutureProvider]. | ||
final fcmTokenFutureProvider = FutureProvider.family | ||
.autoDispose<ReadUserFcmToken?, String>((ref, userFcmTokenId) async { | ||
return ref | ||
.watch(fcmTokenRepositoryProvider) | ||
.fetchUserFcmToken(userFcmTokenId: userFcmTokenId); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
サンプル実装なので良いですが、他を参考に
- View と Controller:
fcm_token/ui/fcm_token.dart
- Model:
fcm_token/fcm_token.dart
に書くべきだと思います!
return; | ||
} | ||
|
||
await _fcmTokenRepository.setUserFcmToken( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(同上)ここにリポジトリのことを書かない
Issue
close #49
説明
UI
その他
fcmToken確認用の開発ページは、あまりイケてるコードではないですが、確認用なのでいいかなと。(いい感じにしようとしてあまりうまくいかなかった。。)
→もし流石にもうちょっと綺麗にしたいとかあればおっしゃってください🙇
チェックリスト