|
|
|
@@ -1,4 +1,8 @@ |
|
|
|
import 'dart:io'; |
|
|
|
|
|
|
|
import 'package:dio/dio.dart'; |
|
|
|
import 'package:farm_tpf/data/repository/repository.dart'; |
|
|
|
import 'package:farm_tpf/data/repository/user_repository.dart'; |
|
|
|
import 'package:farm_tpf/main.dart'; |
|
|
|
import 'package:farm_tpf/models/index.dart'; |
|
|
|
import 'package:farm_tpf/presentation/custom_widgets/bottom_loader.dart'; |
|
|
|
@@ -6,6 +10,9 @@ import 'package:farm_tpf/presentation/custom_widgets/loading_list_page.dart'; |
|
|
|
import 'package:farm_tpf/presentation/screens/plot/widget_search.dart'; |
|
|
|
import 'package:farm_tpf/presentation/screens/plot_detail/sc_plot_detail.dart'; |
|
|
|
import 'package:farm_tpf/utils/const_color.dart'; |
|
|
|
import 'package:farm_tpf/utils/const_common.dart'; |
|
|
|
import 'package:farm_tpf/utils/pref.dart'; |
|
|
|
import 'package:firebase_messaging/firebase_messaging.dart'; |
|
|
|
import 'package:flutter/material.dart'; |
|
|
|
import 'package:flutter_bloc/flutter_bloc.dart'; |
|
|
|
import 'package:farm_tpf/utils/const_string.dart'; |
|
|
|
@@ -20,6 +27,63 @@ class PlotListScreen extends StatefulWidget { |
|
|
|
} |
|
|
|
|
|
|
|
class _PlotListScreenState extends State<PlotListScreen> { |
|
|
|
UserRepository _userRepository = UserRepository(); |
|
|
|
final FirebaseMessaging _firebaseMessaging = FirebaseMessaging(); |
|
|
|
var pref = LocalPref(); |
|
|
|
var token; |
|
|
|
var client; |
|
|
|
String pushkey = ""; |
|
|
|
|
|
|
|
Future<Null> getSharedPrefs() async { |
|
|
|
token = await pref.getString(DATA_CONST.TOKEN_KEY); |
|
|
|
pushkey = await pref.getString(DATA_CONST.PUSH_KEY); |
|
|
|
var options = BaseOptions(baseUrl: ConstCommon.baseUrl); |
|
|
|
options.headers["Authorization"] = "Bearer $token"; |
|
|
|
client = Dio(options); |
|
|
|
if (Platform.isIOS) { |
|
|
|
_firebaseMessaging |
|
|
|
.requestNotificationPermissions(IosNotificationSettings()); |
|
|
|
} |
|
|
|
_firebaseMessaging.configure( |
|
|
|
onMessage: (Map<String, dynamic> message) async { |
|
|
|
print("onMessage: $message"); |
|
|
|
}, |
|
|
|
onBackgroundMessage: Platform.isIOS ? null : myBackgroundMessageHandler, |
|
|
|
onLaunch: (Map<String, dynamic> message) async { |
|
|
|
print("onLaunch: $message"); |
|
|
|
}, |
|
|
|
onResume: (Map<String, dynamic> message) async { |
|
|
|
print("onResume: $message"); |
|
|
|
}, |
|
|
|
); |
|
|
|
_firebaseMessaging.requestNotificationPermissions( |
|
|
|
const IosNotificationSettings( |
|
|
|
sound: true, badge: true, alert: true, provisional: true)); |
|
|
|
_firebaseMessaging.onIosSettingsRegistered |
|
|
|
.listen((IosNotificationSettings settings) { |
|
|
|
print("Settings registered: $settings"); |
|
|
|
}); |
|
|
|
if (pushkey?.isEmpty ?? true) { |
|
|
|
_firebaseMessaging.getToken().then((String token) { |
|
|
|
assert(token != null); |
|
|
|
print("Push Messaging token: $token"); |
|
|
|
_userRepository.updateFcmToken(token).then((value) { |
|
|
|
print("send push key successful"); |
|
|
|
pref.saveString(DATA_CONST.PUSH_KEY, token); |
|
|
|
}); |
|
|
|
// client.put(""); |
|
|
|
}); |
|
|
|
} else { |
|
|
|
print("Don't need get push key"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@override |
|
|
|
void initState() { |
|
|
|
super.initState(); |
|
|
|
getSharedPrefs(); |
|
|
|
} |
|
|
|
|
|
|
|
@override |
|
|
|
Widget build(BuildContext context) { |
|
|
|
return BlocProvider( |