diff --git a/android/app/build.gradle b/android/app/build.gradle index 0b47941..a8078dc 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -73,6 +73,8 @@ android { buildTypes { release { signingConfig signingConfigs.release + minifyEnabled false + shrinkResources false } } diff --git a/lib/main.dart b/lib/main.dart index f5b00bf..011224a 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -3,6 +3,7 @@ import 'dart:async'; import 'package:android_intent_plus/android_intent.dart'; +import 'package:awesome_notifications/awesome_notifications.dart'; import 'package:bot_toast/bot_toast.dart'; import 'package:didvan/config/theme_data.dart'; import 'package:didvan/firebase_options.dart'; @@ -33,16 +34,20 @@ final GlobalKey navigatorKey = GlobalKey(); @pragma('vm:entry-point') Future _initPushNotification(RemoteMessage message) async { - await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform); - if (kDebugMode) { - print("background: ${NotificationData.fromJson(message.data).toJson()}"); + if (!kIsWeb) { + await NotificationService.initializeNotification(); } + await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform); + // if (kDebugMode) { + print("background: ${NotificationData.fromJson(message.data).toJson()}"); + // } try { NotificationService.showFirebaseNotification(message); + NotificationService.startListeningNotificationEvents(); } catch (e) { - if (kDebugMode) { - print(e); - } + // if (kDebugMode) { + print(e); + // } } } @@ -98,6 +103,7 @@ class _DidvanState extends State with WidgetsBindingObserver { NotificationService.startListeningNotificationEvents(); } WidgetsBinding.instance.addObserver(this); + NotificationService.startListeningNotificationEvents(); super.initState(); } diff --git a/lib/services/app_home_widget/home_widget_repository.dart b/lib/services/app_home_widget/home_widget_repository.dart index a2a369e..43eb7ad 100644 --- a/lib/services/app_home_widget/home_widget_repository.dart +++ b/lib/services/app_home_widget/home_widget_repository.dart @@ -1,5 +1,6 @@ import 'package:didvan/models/notification_message.dart'; import 'package:didvan/services/app_initalizer.dart'; +import 'package:firebase_messaging/firebase_messaging.dart'; import 'package:flutter/cupertino.dart'; import 'package:home_widget/home_widget.dart'; import 'package:persian_number_utility/persian_number_utility.dart'; @@ -226,7 +227,10 @@ class HomeWidgetRepository { } if (route.isNotEmpty) { navigatorKey.currentState!.pushNamed(route, arguments: args); + print("Push: $route"); } + print("Push: empty"); + return; } } diff --git a/lib/services/app_initalizer.dart b/lib/services/app_initalizer.dart index a55f951..0d41682 100644 --- a/lib/services/app_initalizer.dart +++ b/lib/services/app_initalizer.dart @@ -13,13 +13,15 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:path_provider/path_provider.dart'; import 'package:provider/provider.dart'; -import 'package:url_launcher/url_launcher_string.dart'; +import 'package:url_launcher/url_launcher.dart'; enum LaunchMode { inAppWebView } -void openInWebView(String src, {dynamic mode}) { +void openInWebView(String src, {dynamic mode}) async { if (kIsWeb) { - launchUrlString(src); + if (!await launchUrl(Uri.parse(src))) { + throw Exception('Could not launch $src'); + } return; } navigatorKey.currentState!.pushNamed(Routes.web, arguments: src); diff --git a/lib/services/notification/firebase_api.dart b/lib/services/notification/firebase_api.dart index 170497c..578caec 100644 --- a/lib/services/notification/firebase_api.dart +++ b/lib/services/notification/firebase_api.dart @@ -1,5 +1,10 @@ +import 'package:awesome_notifications/awesome_notifications.dart'; import 'package:didvan/models/notification_data.dart'; +import 'package:didvan/models/notification_message.dart'; +import 'package:didvan/services/app_home_widget/home_widget_repository.dart'; +import 'package:didvan/services/app_initalizer.dart'; import 'package:didvan/services/notification/notification_service.dart'; +import 'package:didvan/services/storage/storage.dart'; import 'package:firebase_messaging/firebase_messaging.dart'; import 'package:flutter/foundation.dart'; import 'package:get/get.dart'; @@ -28,7 +33,10 @@ class FirebaseApi { sound: true, ); - FirebaseMessaging.instance.getInitialMessage(); + FirebaseMessaging.instance + .getInitialMessage() + .asStream() + .listen((event) async {}); FirebaseMessaging.onMessageOpenedApp.listen((event) {}); FirebaseMessaging.onMessage.listen((event) => handleMessage(event)); } @@ -36,13 +44,13 @@ class FirebaseApi { void handleMessage(RemoteMessage? message) async { if (message == null) return; //do ever you want with message - if (kDebugMode) { - print("forground: ${NotificationData.fromJson(message.data).toJson()}"); - } + // if (kDebugMode) { + print("forground: ${NotificationData.fromJson(message.data).toJson()}"); + // } try { await NotificationService.showFirebaseNotification(message); } catch (e) { - rethrow; + e.printError(); } } } diff --git a/lib/services/notification/notification_service.dart b/lib/services/notification/notification_service.dart index d1cdfff..46ceb8b 100644 --- a/lib/services/notification/notification_service.dart +++ b/lib/services/notification/notification_service.dart @@ -70,6 +70,7 @@ class NotificationService { NotificationMessage data = NotificationMessage.fromJson(receivedAction.payload!); HomeWidgetRepository.data = data; + print("data: ${HomeWidgetRepository.data}"); await HomeWidgetRepository.decideWhereToGoNotif(); await StorageService.delete( key: 'notification${AppInitializer.createNotificationId(data)}'); diff --git a/lib/views/ai/ai.dart b/lib/views/ai/ai.dart index 20e07a7..caa32a4 100644 --- a/lib/views/ai/ai.dart +++ b/lib/views/ai/ai.dart @@ -12,6 +12,7 @@ import 'package:didvan/views/ai/history_ai_chat_state.dart'; import 'package:didvan/views/home/home.dart'; import 'package:didvan/views/widgets/didvan/text.dart'; import 'package:flutter/material.dart'; +import 'package:flutter/widgets.dart'; import 'package:provider/provider.dart'; class Ai extends StatefulWidget { @@ -53,70 +54,102 @@ class _AiState extends State { ); } final bot = state.bot!; - return Stack( + return Column( + mainAxisAlignment: MainAxisAlignment.end, children: [ - Column( - children: [ - const SizedBox( - height: 24, - ), - Icon( - DidvanIcons.ai_solid, - size: MediaQuery.sizeOf(context).width / 5, - color: Theme.of(context).colorScheme.title, - ), - DidvanText( - 'هوشان', - color: Theme.of(context).colorScheme.title, - ), - const SizedBox( - height: 24, - ), - InkWell( - onTap: () => ActionSheetUtils(context) - .botsDialogSelect(context: context, state: state), - child: Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Icon( - DidvanIcons.caret_down_solid, - color: Theme.of(context).colorScheme.title, + Expanded( + child: Stack( + children: [ + SingleChildScrollView( + child: Padding( + padding: const EdgeInsets.only(bottom: 24), + child: Column( + children: [ + const SizedBox( + height: 24, + ), + Icon( + DidvanIcons.ai_solid, + size: MediaQuery.sizeOf(context).width / 5, + color: Theme.of(context).colorScheme.title, + ), + DidvanText( + 'هوشان', + color: Theme.of(context).colorScheme.title, + ), + const SizedBox( + height: 24, + ), + InkWell( + onTap: () => ActionSheetUtils(context) + .botsDialogSelect( + context: context, state: state), + child: Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Icon( + DidvanIcons.caret_down_solid, + color: Theme.of(context).colorScheme.title, + ), + DidvanText(bot.name.toString(), + color: Theme.of(context).colorScheme.title), + ], + ), + ), + const SizedBox( + height: 8, + ), + Container( + width: MediaQuery.sizeOf(context).height / 5, + height: MediaQuery.sizeOf(context).height / 5, + decoration: BoxDecoration( + borderRadius: DesignConfig.highBorderRadius, + color: Theme.of(context).colorScheme.focused), + padding: const EdgeInsets.all(12), + child: CachedNetworkImage( + imageUrl: bot.image.toString(), + ), + ), + const SizedBox( + height: 24, + ), + Padding( + padding: + const EdgeInsets.symmetric(horizontal: 20.0), + child: Text( + "به هوشان, هوش مصنوعی دیدوان خوش آمدید. \nبرای شروع گفتگو پیام مورد نظر خود را در کادر زیر بنویسید.\n دریافت پاسخ از: ${bot.name}", + textAlign: TextAlign.center, + ), + ) + ], ), - DidvanText(bot.name.toString(), - color: Theme.of(context).colorScheme.title), - ], + ), ), - ), - const SizedBox( - height: 8, - ), - Container( - width: MediaQuery.sizeOf(context).height / 5, - height: MediaQuery.sizeOf(context).height / 5, - decoration: BoxDecoration( - borderRadius: DesignConfig.highBorderRadius, - color: Theme.of(context).colorScheme.focused), - padding: const EdgeInsets.all(12), - child: CachedNetworkImage( - imageUrl: bot.image.toString(), - ), - ), - const SizedBox( - height: 24, - ), - Padding( - padding: const EdgeInsets.symmetric(horizontal: 20.0), - child: Text( - "به هوشان, هوش مصنوعی دیدوان خوش آمدید. \nبرای شروع گفتگو پیام مورد نظر خود را در کادر زیر بنویسید.\n دریافت پاسخ از: ${bot.name}", - textAlign: TextAlign.center, - ), - ) - ], + Positioned( + top: 32, + right: 0, + child: InkWell( + onTap: () => homeScaffKey.currentState!.openDrawer(), + child: Container( + width: 46, + height: 46, + decoration: BoxDecoration( + color: Theme.of(context).colorScheme.surface, + borderRadius: const BorderRadius.only( + topLeft: Radius.circular(12), + bottomLeft: Radius.circular(12)), + boxShadow: DesignConfig.defaultShadow), + child: Icon( + DidvanIcons.angle_left_light, + color: Theme.of(context).colorScheme.title, + ), + )), + ) + ], + ), ), - Positioned( - bottom: 32, - left: 20, - right: 20, + Padding( + padding: const EdgeInsets.fromLTRB(20, 0, 20, 32), child: InkWell( onTap: () => Navigator.of(context).pushNamed(Routes.aiChat, arguments: AiChatArgs( @@ -161,26 +194,6 @@ class _AiState extends State { ), )), ), - Positioned( - top: 32, - right: 0, - child: InkWell( - onTap: () => homeScaffKey.currentState!.openDrawer(), - child: Container( - width: 46, - height: 46, - decoration: BoxDecoration( - color: Theme.of(context).colorScheme.surface, - borderRadius: const BorderRadius.only( - topLeft: Radius.circular(12), - bottomLeft: Radius.circular(12)), - boxShadow: DesignConfig.defaultShadow), - child: Icon( - DidvanIcons.angle_left_light, - color: Theme.of(context).colorScheme.title, - ), - )), - ) ], ); }, diff --git a/lib/views/direct/widgets/message_box.dart b/lib/views/direct/widgets/message_box.dart index beb47b7..74cd9fa 100644 --- a/lib/views/direct/widgets/message_box.dart +++ b/lib/views/direct/widgets/message_box.dart @@ -156,7 +156,8 @@ class _TypingState extends State<_Typing> { style: Theme.of(context).textTheme.bodyMedium, decoration: InputDecoration( border: InputBorder.none, - hintText: 'بنویسید یا پیام صوتی بگذارید...', + hintText: + kIsWeb ? 'بنویسید...' : 'بنویسید یا پیام صوتی بگذارید...', hintStyle: Theme.of(context).textTheme.bodySmall!.copyWith( color: Theme.of(context).colorScheme.disabledText), ), diff --git a/lib/views/home/categories/categories_page.dart b/lib/views/home/categories/categories_page.dart index d73cbeb..13480a7 100644 --- a/lib/views/home/categories/categories_page.dart +++ b/lib/views/home/categories/categories_page.dart @@ -9,15 +9,17 @@ class CategoriesPage extends StatelessWidget { Widget build(BuildContext context) { return Padding( padding: const EdgeInsets.all(16.0), - child: Column( - children: [ - DidvanText( - 'دسته‌بندی‌ها', - style: Theme.of(context).textTheme.titleMedium, - ), - const SizedBox(height: 20), - const MainCategories(), - ], + child: SingleChildScrollView( + child: Column( + children: [ + DidvanText( + 'دسته‌بندی‌ها', + style: Theme.of(context).textTheme.titleMedium, + ), + const SizedBox(height: 20), + const MainCategories(), + ], + ), ), ); } diff --git a/lib/views/home/home.dart b/lib/views/home/home.dart index 5bde1ae..0b25bec 100644 --- a/lib/views/home/home.dart +++ b/lib/views/home/home.dart @@ -36,6 +36,7 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; +import 'package:flutter_svg/flutter_svg.dart'; import 'package:provider/provider.dart'; import '../../services/app_home_widget/home_widget_repository.dart'; @@ -320,9 +321,21 @@ class _HomeState extends State ? Padding( padding: const EdgeInsets.all(12.0), - child: EmptyState( - asset: Assets.emptyResult, - title: 'لیست خالی است', + child: Column( + children: [ + SvgPicture.asset( + Assets.emptyResult, + height: MediaQuery.sizeOf( + context) + .height / + 10, + ), + const DidvanText( + 'لیست خالی است', + fontSize: 14, + fontWeight: FontWeight.bold, + ) + ], ), ) : state.loadingdeleteAll || @@ -450,6 +463,9 @@ class _HomeState extends State body: WillPopScope( onWillPop: () async { if (context.read().tabController.index == 0) { + if (kIsWeb) { + return true; + } ActionSheetUtils(context).openDialog( data: ActionSheetData( content: const DidvanText(