feat(push notifications): test implemintation of push notifcations

This commit is contained in:
Username1548
2025-03-26 19:48:02 +07:00
parent fd089e0206
commit b54deb66e7
26 changed files with 580 additions and 355 deletions

View File

@@ -1,9 +1,15 @@
import 'dart:io';
import 'package:dio/dio.dart';
import 'package:eatvio_app/core/const.dart';
import 'package:eatvio_app/core/firebase_api.dart';
import 'package:eatvio_app/core/locator_service.dart';
import 'package:eatvio_app/core/utils/toasts.dart';
import 'package:eatvio_app/core/widgets/custom_outlined_button.dart';
import 'package:eatvio_app/core/widgets/custom_text_form_field.dart';
import 'package:eatvio_app/features/dev_tools/test_cases.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
class DevToolsScreen extends StatelessWidget {
const DevToolsScreen({super.key});
@@ -61,9 +67,7 @@ class _DevToolsScreenContentState extends State<DevToolsScreenContent> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Для разработчиков'),
),
appBar: AppBar(title: Text('Для разработчиков')),
body: SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 10),
@@ -99,6 +103,7 @@ class _DevToolsScreenContentState extends State<DevToolsScreenContent> {
ListView.builder(
shrinkWrap: true,
itemCount: testCases.length,
physics: NeverScrollableScrollPhysics(),
itemBuilder:
(context, index) => Padding(
padding: const EdgeInsets.only(bottom: 10.0),
@@ -151,6 +156,80 @@ class _DevToolsScreenContentState extends State<DevToolsScreenContent> {
),
),
),
const SizedBox(height: 10),
CustomOutlinedButton(
text: 'add token to server',
buttonStyle: ButtonStyle(),
onPressed: () async {
try {
final dio = sl<Dio>();
final String platform;
if (Platform.isAndroid) {
platform = 'android';
} else {
platform = 'ios';
}
await dio.post('/api/profile/notification/token/register', data: {'token': await FirebaseApi().getToken(), 'platform': platform});
showInfoToast('Токен добавлен');
} catch (e) {
showInfoToast('Не удалось добавть токен');
}
},
),
const SizedBox(height: 10),
CustomOutlinedButton(
text: 'copy token',
buttonStyle: ButtonStyle(),
onPressed: () async {
try {
final token = await FirebaseApi().getToken();
if (token != null) {
Clipboard.setData(ClipboardData(text: token));
showInfoToast('Токен скопирован');
} else {
showInfoToast('Token is null');
}
} catch (e) {
showInfoToast('Не получилось скопировать токен');
}
},
),
const SizedBox(height: 10),
CustomOutlinedButton(
text: 'remove token from server',
buttonStyle: ButtonStyle(),
onPressed: () async {
try {
final dio = sl<Dio>();
final String platform;
if (Platform.isAndroid) {
platform = 'android';
} else {
platform = 'ios';
}
await dio.post('/api/profile/notification/token/unregister', data: {'token': await FirebaseApi().getToken(), 'platform': platform});
showInfoToast('Токен удалён');
} catch (e) {
showInfoToast('Не удалось удалить токен');
}
},
),
const SizedBox(height: 10),
CustomOutlinedButton(
text: 'send notification',
buttonStyle: ButtonStyle(),
onPressed: () async {
try {
final dio = sl<Dio>();
Future.delayed(Duration(seconds: 3), () async {
await dio.post('/api/profile/notification/token/test');
});
} catch (e) {
showInfoToast('Не удалось добавть токен');
}
},
),
const SizedBox(height: 300),
],
),
),