token
This commit is contained in:
@@ -23,12 +23,45 @@ import 'package:prosappco/src/screens/service.dart';
|
||||
import 'package:prosappco/src/screens/solicitudes.dart';
|
||||
import 'package:prosappco/src/services/local_notifications.dart';
|
||||
import 'firebase_options.dart';
|
||||
import 'package:firebase_messaging/firebase_messaging.dart';
|
||||
|
||||
Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
|
||||
await Firebase.initializeApp();
|
||||
|
||||
print('Handling a backdround message: ${message.messageId}');
|
||||
}
|
||||
|
||||
void main() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
await Firebase.initializeApp(
|
||||
options: DefaultFirebaseOptions.currentPlatform,
|
||||
).then((value) => Get.put(AuthenticationRepository()));
|
||||
|
||||
FirebaseMessaging.onBackgroundMessage((_firebaseMessagingBackgroundHandler));
|
||||
|
||||
FirebaseMessaging messaging = FirebaseMessaging.instance;
|
||||
|
||||
NotificationSettings settings = await messaging.requestPermission(
|
||||
alert: true,
|
||||
announcement: false,
|
||||
badge: true,
|
||||
carPlay: false,
|
||||
criticalAlert: false,
|
||||
provisional: false,
|
||||
sound: true,
|
||||
);
|
||||
|
||||
FirebaseMessaging.onMessage.listen((RemoteMessage message) {
|
||||
print('Got a message whilst in the foreground!');
|
||||
print('Message data: ${message.data}');
|
||||
|
||||
if (message.notification != null) {
|
||||
print('Message also contained a notification: ${message.notification}');
|
||||
}
|
||||
});
|
||||
|
||||
print('User granted permission: ${settings.authorizationStatus}');
|
||||
|
||||
await initNotifications();
|
||||
|
||||
await initializeDateFormatting('es_MX', null);
|
||||
|
||||
@@ -28,6 +28,21 @@ class ServiceScreen extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _ServiceScreenState extends State<ServiceScreen> {
|
||||
void _saveToken() async {
|
||||
FirebaseMessaging messaging = FirebaseMessaging.instance;
|
||||
|
||||
final token = await messaging.getToken();
|
||||
|
||||
try {
|
||||
await FirebaseFirestore.instance
|
||||
.collection('users')
|
||||
.doc(uid)
|
||||
.update({'token': token});
|
||||
} catch (e) {
|
||||
print(e);
|
||||
}
|
||||
}
|
||||
|
||||
EventoService eventoService = EventoService();
|
||||
String _locationPosition = '';
|
||||
String ubicacion = '';
|
||||
@@ -143,7 +158,7 @@ class _ServiceScreenState extends State<ServiceScreen> {
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
final userRef = FirebaseFirestore.instance.collection('users').doc(uid);
|
||||
_saveToken();
|
||||
|
||||
if (user == null) {
|
||||
UserModel.getUser(uid.toString()).then(
|
||||
|
||||
@@ -8,6 +8,14 @@ import 'package:prosappco/src/models/event_model.dart';
|
||||
import 'package:prosappco/src/models/scores_model.dart';
|
||||
import 'package:prosappco/src/screens/cita.dart';
|
||||
|
||||
// class name extends StatelessWidget {
|
||||
// const name({super.key});
|
||||
|
||||
// @override
|
||||
// Widget build(BuildContext context) {
|
||||
// return Container();
|
||||
// }
|
||||
// }
|
||||
class SolicitudScreen extends StatefulWidget {
|
||||
SolicitudScreen({super.key});
|
||||
|
||||
|
||||
+1
-1
@@ -61,12 +61,12 @@ dependencies:
|
||||
flutter_email_sender: ^5.2.0
|
||||
webview_flutter: ^4.2.0
|
||||
firebase_storage: ^11.2.2
|
||||
firebase_messaging: ^14.5.0
|
||||
responsive_builder: ^0.7.0
|
||||
flutter_local_notifications: ^14.1.1
|
||||
http: ^0.13.5
|
||||
flutter_dialogs: ^3.0.0
|
||||
universal_html: ^2.2.3
|
||||
firebase_messaging: ^14.6.3
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
|
||||
Reference in New Issue
Block a user