Compare commits

..

No commits in common. "b2961ca7d813e23d08beed89ce94d54de214fae9" and "86913a973bad96c060ec92a12176dbc512558236" have entirely different histories.

10 changed files with 135 additions and 228 deletions

15
.vscode/launch.json vendored
View File

@ -1,15 +0,0 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "chrome",
"request": "launch",
"name": "Launch Chrome against localhost",
"url": "http://localhost:8080",
"webRoot": "${workspaceFolder}"
}
]
}

BIN
build.zip

Binary file not shown.

View File

@ -1,5 +1,3 @@
// lib/main.dart
// ignore_for_file: deprecated_member_use // ignore_for_file: deprecated_member_use
import 'dart:async'; import 'dart:async';
@ -9,8 +7,6 @@ import 'package:bot_toast/bot_toast.dart';
import 'package:didvan/config/theme_data.dart'; import 'package:didvan/config/theme_data.dart';
import 'package:didvan/firebase_options.dart'; import 'package:didvan/firebase_options.dart';
import 'package:didvan/models/notification_message.dart'; import 'package:didvan/models/notification_message.dart';
import 'package:didvan/models/requests/news.dart';
import 'package:didvan/models/requests/radar.dart';
import 'package:didvan/providers/media.dart'; import 'package:didvan/providers/media.dart';
import 'package:didvan/providers/theme.dart'; import 'package:didvan/providers/theme.dart';
import 'package:didvan/providers/user.dart'; import 'package:didvan/providers/user.dart';
@ -36,56 +32,56 @@ import 'package:home_widget/home_widget.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'package:flutter_downloader/flutter_downloader.dart'; import 'package:flutter_downloader/flutter_downloader.dart';
import 'package:sentry_flutter/sentry_flutter.dart'; import 'package:sentry_flutter/sentry_flutter.dart';
// پکیج جدید برای Deep Linking
import 'package:app_links/app_links.dart'; import 'package:app_links/app_links.dart';
import 'services/network/request.dart';
final GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>(); final GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();
// متغیر استاتیک برای نگهداری لینک اولیه
Uri? initialURI; Uri? initialURI;
@pragma('vm:entry-point') @pragma('vm:entry-point')
Future<void> _backgroundCallbackHomeWidget(Uri? uri) async { Future<void> _backgroundCallbackHomeWidget(Uri? uri) async {
if (uri != null) { if (uri != null) {
await HomeWidget.saveWidgetData("uri", uri.host); await HomeWidget.saveWidgetData("uri", uri.host);
} }
} }
void main() async { void main() async {
runZonedGuarded( WidgetsFlutterBinding.ensureInitialized();
() async { try {
WidgetsFlutterBinding.ensureInitialized(); if (!kIsWeb) {
HomeWidget.registerBackgroundCallback(_backgroundCallbackHomeWidget);
HomeWidget.registerInteractivityCallback(_backgroundCallbackHomeWidget);
await NotificationService.initializeNotification();
try { try {
if (!kIsWeb) { if (Platform.isAndroid) {
HomeWidget.registerBackgroundCallback(_backgroundCallbackHomeWidget); await FlutterDownloader.initialize(
HomeWidget.registerInteractivityCallback(_backgroundCallbackHomeWidget); debug: true,
await NotificationService.initializeNotification(); ignoreSsl: true
try { );
if (Platform.isAndroid) {
await FlutterDownloader.initialize(debug: true, ignoreSsl: true);
}
} catch (e) {
e.printError();
}
} }
await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);
await FirebaseApi().initNotification();
} catch (e) { } catch (e) {
debugPrint(e.toString()); e.printError();
} }
}
await SentryFlutter.init( await Firebase.initializeApp(
(options) { options: DefaultFirebaseOptions.currentPlatform);
options.dsn = 'https://a4cfcaa7d67471240d295c25c968d91d@o4508585857384448.ingest.de.sentry.io/4508585886548048'; await FirebaseApi().initNotification();
options.tracesSampleRate = 1.0; } catch (e) {
options.profilesSampleRate = 1.0; debugPrint(e.toString());
}, }
appRunner: () => runApp(const Didvan()),
); await SentryFlutter.init(
}, (options) {
(error, stack) { options.dsn =
Sentry.captureException(error, stackTrace: stack); 'https://a4cfcaa7d67471240d295c25c968d91d@o4508585857384448.ingest.de.sentry.io/4508585886548048';
options.tracesSampleRate = 1.0;
options.profilesSampleRate = 1.0;
}, },
appRunner: () => runApp(const Didvan()),
); );
} }
@ -104,57 +100,41 @@ class _DidvanState extends State<Didvan> with WidgetsBindingObserver {
void initState() { void initState() {
super.initState(); super.initState();
WidgetsBinding.instance.addObserver(this); WidgetsBinding.instance.addObserver(this);
// مقداردهی اولیه و گوش دادن به لینکها در اینجا انجام میشود
_initDeepLinks(); _initDeepLinks();
} }
@override @override
void dispose() { void dispose() {
WidgetsBinding.instance.removeObserver(this); WidgetsBinding.instance.removeObserver(this);
_linkSubscription?.cancel(); _linkSubscription?.cancel(); // لغو کردن subscription
if (MediaService.currentPodcast != null) { if (MediaService.currentPodcast != null) {
MediaService.audioPlayer.dispose(); MediaService.audioPlayer.dispose();
} }
super.dispose(); super.dispose();
} }
/// منطق جدید برای مدیریت لینکها با app_links
Future<void> _initDeepLinks() async { Future<void> _initDeepLinks() async {
_appLinks = AppLinks(); _appLinks = AppLinks();
// لینک اولیه را فقط در متغیر ذخیره میکنیم
initialURI = await _appLinks.getInitialLink(); initialURI = await _appLinks.getInitialLink();
// به لینکهای جدید زمانی که اپلیکیشن باز است گوش میدهیم
_linkSubscription = _appLinks.uriLinkStream.listen((uri) { _linkSubscription = _appLinks.uriLinkStream.listen((uri) {
_navigateTo(uri); _navigateTo(uri);
}); });
} }
/// تابع کمکی برای ناوبری
void _navigateTo(Uri uri) { void _navigateTo(Uri uri) {
if (mounted) { if (mounted) {
String path = uri.path; String path = uri.path;
final Map<String, String> params = uri.queryParameters; if (uri.fragment.isNotEmpty) {
path = "/${uri.fragment}";
final String? token = params['token'];
if (token != null) {
//todo: this didnt work
print("DEBUG: received token in url, token: $token, path: $path");
RequestService.token = token;
}
if (path.startsWith('/news/')) {
final id = path.split('/news/').last;
if (id.isNotEmpty) {
navigatorKey.currentState?.pushNamed(
Routes.newsDetails,
arguments: {'id': int.parse(id), 'args': const NewsRequestArgs(page: 0)},
);
}
} else if (path.startsWith('/radar/')) {
final id = path.split('/radar/').last;
if (id.isNotEmpty) {
navigatorKey.currentState?.pushNamed(
Routes.radarDetails,
arguments: {'id': int.parse(id), 'args': const RadarRequestArgs(page: 0)},
);
}
} }
navigatorKey.currentState?.pushNamed(path);
} }
} }
@ -163,9 +143,11 @@ class _DidvanState extends State<Didvan> with WidgetsBindingObserver {
if (!kIsWeb) { if (!kIsWeb) {
if (state == AppLifecycleState.resumed) { if (state == AppLifecycleState.resumed) {
var r = await HomeWidget.getWidgetData("cRoute", defaultValue: ''); var r = await HomeWidget.getWidgetData("cRoute", defaultValue: '');
if (r.toString() != Routes.splash) { if (r!.toString() != Routes.splash) {
await HomeWidgetRepository.decideWhereToGo(); await HomeWidgetRepository.decideWhereToGo();
NotificationMessage? data = HomeWidgetRepository.data; NotificationMessage? data = HomeWidgetRepository.data;
if (data != null) { if (data != null) {
await HomeWidgetRepository.decideWhereToGoNotif(); await HomeWidgetRepository.decideWhereToGoNotif();
} }
@ -193,43 +175,43 @@ class _DidvanState extends State<Didvan> with WidgetsBindingObserver {
color: Theme.of(context).colorScheme.surface, color: Theme.of(context).colorScheme.surface,
child: SafeArea( child: SafeArea(
child: MaterialApp( child: MaterialApp(
scrollBehavior: MyCustomScrollBehavior(), scrollBehavior: MyCustomScrollBehavior(),
navigatorKey: navigatorKey, navigatorKey: navigatorKey,
debugShowCheckedModeBanner: false, debugShowCheckedModeBanner: false,
title: 'Didvan', title: 'Didvan',
theme: LightThemeConfig.themeData.copyWith( theme: LightThemeConfig.themeData.copyWith(
bottomSheetTheme: const BottomSheetThemeData( bottomSheetTheme: const BottomSheetThemeData(
surfaceTintColor: Colors.transparent, surfaceTintColor: Colors.transparent,
backgroundColor: Colors.transparent), backgroundColor: Colors.transparent),
textTheme: LightThemeConfig.themeData.textTheme.apply( textTheme: LightThemeConfig.themeData.textTheme.apply(
fontFamily: themeProvider.fontFamily, fontFamily: themeProvider.fontFamily,
)), )),
darkTheme: DarkThemeConfig.themeData.copyWith( darkTheme: DarkThemeConfig.themeData.copyWith(
bottomSheetTheme: const BottomSheetThemeData( bottomSheetTheme: const BottomSheetThemeData(
surfaceTintColor: Colors.transparent, surfaceTintColor: Colors.transparent,
backgroundColor: Colors.transparent), backgroundColor: Colors.transparent),
textTheme: DarkThemeConfig.themeData.textTheme.apply( textTheme: DarkThemeConfig.themeData.textTheme.apply(
fontFamily: themeProvider.fontFamily, fontFamily: themeProvider.fontFamily,
)), )),
color: LightThemeConfig.themeData.primaryColor, color: LightThemeConfig.themeData.primaryColor,
themeMode: themeProvider.themeMode, themeMode: themeProvider.themeMode,
onGenerateRoute: (settings) => onGenerateRoute: (settings) =>
RouteGenerator.generateRoute(settings), RouteGenerator.generateRoute(settings),
builder: BotToastInit(), builder: BotToastInit(),
navigatorObservers: [BotToastNavigatorObserver()], navigatorObservers: [BotToastNavigatorObserver()],
initialRoute: "/", initialRoute: "/",
localizationsDelegates: const [ localizationsDelegates: const [
GlobalCupertinoLocalizations.delegate, GlobalCupertinoLocalizations.delegate,
GlobalMaterialLocalizations.delegate, GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate, GlobalWidgetsLocalizations.delegate,
], ],
supportedLocales: const [ supportedLocales: const [
Locale("fa", "IR"), Locale("fa", "IR"),
], ],
locale: const Locale("fa", "IR"), locale: const Locale("fa", "IR"),
)), )),
), ),
), ),
); );
} }
} }

View File

@ -1,5 +1,3 @@
// lib/services/network/request.dart
// ignore_for_file: empty_catches // ignore_for_file: empty_catches
import 'dart:convert'; import 'dart:convert';
@ -17,7 +15,7 @@ import 'package:mime/mime.dart';
import 'package:permission_handler/permission_handler.dart'; import 'package:permission_handler/permission_handler.dart';
class RequestService { class RequestService {
static String? token; // Made token nullable static late String token;
int? statusCode; int? statusCode;
dynamic data(String s) { dynamic data(String s) {
@ -50,9 +48,12 @@ class RequestService {
}) { }) {
if (body != null) _requestBody = body; if (body != null) _requestBody = body;
if (requestHeaders != null) _headers.addAll(requestHeaders); if (requestHeaders != null) _headers.addAll(requestHeaders);
if (useAutherization && token != null) { // Check if token is not null if (useAutherization) _headers.addAll({'Authorization': 'Bearer $token'});
_headers.addAll({'Authorization': 'Bearer $token'}); // if (kDebugMode) {
} // try {
// print('Authorization : Bearer $token');
// } catch (e) {}
// }
if (body != null) _requestBody = body; if (body != null) _requestBody = body;
} }

View File

@ -82,7 +82,6 @@ class HomeState extends CoreProvier {
); );
await service.httpGet(); await service.httpGet();
if (service.isSuccess) { if (service.isSuccess) {
print("DEBUG : Homestate is succes");
lastPage = service.result['lastPage']; lastPage = service.result['lastPage'];
results.addAll( results.addAll(
List<OverviewData>.from( List<OverviewData>.from(
@ -95,14 +94,12 @@ class HomeState extends CoreProvier {
appState = AppState.idle; appState = AppState.idle;
return; return;
} }
print("DEBUG : Homestate is NOT succes");
appState = AppState.failed; appState = AppState.failed;
} }
Future<void> searchAll({required int page}) async { Future<void> searchAll({required int page}) async {
this.page = page; this.page = page;
if (page == 1) { if (page == 1) {
print("DEBUG : serach is busy");
results.clear(); results.clear();
appState = AppState.busy; appState = AppState.busy;
} }
@ -118,7 +115,6 @@ class HomeState extends CoreProvier {
); );
await service.httpGet(); await service.httpGet();
if (service.isSuccess) { if (service.isSuccess) {
print("DEBUG : HTTPget Home is succes");
lastPage = service.result['lastPage']; lastPage = service.result['lastPage'];
unreadCount = service.result['unread'] ?? unreadCount; unreadCount = service.result['unread'] ?? unreadCount;
results.addAll( results.addAll(
@ -132,7 +128,6 @@ class HomeState extends CoreProvier {
appState = AppState.idle; appState = AppState.idle;
return; return;
} }
print("DEBUG : Homestate is faild");
appState = AppState.failed; appState = AppState.failed;
} }

View File

@ -33,44 +33,30 @@ class MainPage extends StatefulWidget {
class _MainPageState extends State<MainPage> { class _MainPageState extends State<MainPage> {
@override @override
void initState() { void initState() {
super.initState(); context.read<MainPageState>().init();
print("DEBUG: _MainPageState initstate called");
WidgetsBinding.instance.addPostFrameCallback((_) {
print("DEBUG: addPostFrameCallback called");
context.read<MainPageState>().init();
});
super.initState(); super.initState();
} }
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
print("DEBUG: _MainPageState build called");
return StateHandler<MainPageState>( return StateHandler<MainPageState>(
onRetry: () => { onRetry: context.read<MainPageState>().init,
print("DEBUG: _MainPageState onRetry called"),
context.read<MainPageState>().init
},
state: context.watch<MainPageState>(), state: context.watch<MainPageState>(),
builder: (context, state) { builder: (context, state) => ListView(
print("DEBUG: FutureBuilder waiting");
print("DEBUG: FutureBuilder state.stories.isNotEmpty: ${state.stories.isNotEmpty}");
print("DEBUG: FutureBuilder state.content: ${state.content!.lists}");
print("DEBUG: FutureBuilder state.content != null: ${state.content != null}");
print("DEBUG: FutureBuilder state.content!.lists.isNotEmpty: ${state.content!.lists.isNotEmpty}");
return ListView(
padding: const EdgeInsets.symmetric(vertical: 16), padding: const EdgeInsets.symmetric(vertical: 16),
children: [ children: [
if (state.stories.isNotEmpty) StorySection(stories: state.stories), if (state.stories.isNotEmpty) StorySection(stories: state.stories),
const SizedBox(height: 12), const SizedBox(height: 12),
const MainPageMainContent(), const MainPageMainContent(),
Builder(builder: (context) { Builder(builder: (context) {
final List<Widget> pageContent = []; final List<Widget> pageContent = [];
if (state.content != null && state.content!.lists.isNotEmpty) { if (state.content != null && state.content!.lists.isNotEmpty) {
final lists = state.content!.lists; final lists = state.content!.lists;
for (int i = 0; i < lists.length; i++) { for (int i = 0; i < lists.length; i++) {
final currentList = lists[i]; final currentList = lists[i];
if (i == 4) { if (i == 4) {
pageContent.add( pageContent.add(
Padding( Padding(
@ -121,23 +107,21 @@ class _MainPageState extends State<MainPage> {
), ),
); );
} }
pageContent.add(_MainPageSection( pageContent.add(_MainPageSection(
list: currentList, list: currentList,
isLast: i == lists.length - 1, isLast: i == lists.length - 1,
)); ));
if (currentList.type == 'startup') { if (currentList.type == 'startup') {
pageContent.add(_SwotSection(swotItems: state.swotItems)); pageContent.add(_SwotSection(swotItems: state.swotItems));
} }
} }
} }
print("DEBUG: FutureBuilder error");
return Column(children: pageContent); return Column(children: pageContent);
}), }),
], ],
); ),
},
); );
} }
} }
@ -151,7 +135,7 @@ class _SwotSection extends StatelessWidget {
if (swotItems.isEmpty) { if (swotItems.isEmpty) {
return const SizedBox.shrink(); return const SizedBox.shrink();
} }
return Padding( return Padding(
padding: const EdgeInsets.all(0.0), padding: const EdgeInsets.all(0.0),
child: Column( child: Column(
@ -304,7 +288,8 @@ class _MainPageSection extends StatelessWidget {
if (list.contents.isEmpty) { if (list.contents.isEmpty) {
return const SizedBox(); return const SizedBox();
} }
// This condition handles the "Soha" module, which should not display the Opportunity/Threat module.
if (list.type == 'delphi') { if (list.type == 'delphi') {
return Column( return Column(
children: [ children: [
@ -313,7 +298,8 @@ class _MainPageSection extends StatelessWidget {
], ],
); );
} }
// For all other modules, display as before.
return Column( return Column(
children: [ children: [
_buildSectionHeader(context, icon), _buildSectionHeader(context, icon),
@ -400,4 +386,4 @@ class _MainPageSection extends StatelessWidget {
), ),
); );
} }
} }

View File

@ -24,19 +24,12 @@ class MainPageState extends CoreProvier {
List<SwotItem> swotItems = []; List<SwotItem> swotItems = [];
Future<void> _getMainPageContent() async { Future<void> _getMainPageContent() async {
print("DEBUG: _getMainPageContent started");
final service = RequestService(RequestHelper.mainPageContent); final service = RequestService(RequestHelper.mainPageContent);
await service.httpGet(); await service.httpGet();
if (service.isSuccess) { if (service.isSuccess) {
print("DEBUG: _getMainPageContent success");
content = MainPageContent.fromJson(service.result); content = MainPageContent.fromJson(service.result);
print("DEBUG: _getMainPageContent service.result: ${service.result}");
unread = service.result['unread']; unread = service.result['unread'];
print("DEBUG: __getMainPageContent unread: $unread, content: $content");
notifyListeners();
} else { } else {
print("DEBUG: _getMainPageContent failed state");
notifyListeners();
throw Exception('Failed to load main page content'); throw Exception('Failed to load main page content');
} }
} }
@ -50,14 +43,14 @@ class MainPageState extends CoreProvier {
try { try {
swotItems = await SwotService.fetchSwotItems(); swotItems = await SwotService.fetchSwotItems();
} catch (e) { } catch (e) {
print(e);
} }
} }
Future<void> _fetchStories() async { Future<void> _fetchStories() async {
try { try {
stories = await StoryService.getStories(); stories = await StoryService.getStories();
// print("Fetched ${stories.length} stories."); print("Fetched ${stories.length} stories.");
} catch (e) { } catch (e) {
stories = []; stories = [];
debugPrint("Could not fetch stories: $e"); debugPrint("Could not fetch stories: $e");
@ -65,7 +58,6 @@ class MainPageState extends CoreProvier {
} }
void init() { void init() {
print("DEBUG: MainPageState init called");
Future.delayed(Duration.zero, () async { Future.delayed(Duration.zero, () async {
appState = AppState.busy; appState = AppState.busy;
try { try {
@ -79,7 +71,6 @@ class MainPageState extends CoreProvier {
appState = AppState.failed; appState = AppState.failed;
} }
}); });
_getMainPageContent();
} }
void markChangeHandler(String type, int id, bool value) { void markChangeHandler(String type, int id, bool value) {

View File

@ -1,5 +1,3 @@
// lib/views/news/news_details/news_details_state.dart
import 'dart:async'; import 'dart:async';
import 'dart:math'; import 'dart:math';
@ -10,8 +8,6 @@ import 'package:didvan/models/requests/news.dart';
import 'package:didvan/providers/core.dart'; import 'package:didvan/providers/core.dart';
import 'package:didvan/services/network/request.dart'; import 'package:didvan/services/network/request.dart';
import 'package:didvan/services/network/request_helper.dart'; import 'package:didvan/services/network/request_helper.dart';
import 'package:didvan/services/storage/storage.dart';
import 'package:flutter/material.dart';
class NewsDetailsState extends CoreProvier { class NewsDetailsState extends CoreProvier {
final List<NewsDetailsData?> news = []; final List<NewsDetailsData?> news = [];
@ -29,24 +25,12 @@ class NewsDetailsState extends CoreProvier {
NewsDetailsData get currentNews => news[_currentIndex]!; NewsDetailsData get currentNews => news[_currentIndex]!;
Future<void> getNewsDetails(int id, {bool? isForward}) async { Future<void> getNewsDetails(int id, {bool? isForward}) async {
debugPrint('requset token ${RequestService.token}'); if (isForward == null) {
// **FIX: Ensure the token is available before making a request.** appState = AppState.busy;
if (RequestService.token == null) { } else {
final token = await StorageService.getValue(key: 'token'); isFetchingNewItem = true;
if (token != null) { notifyListeners();
RequestService.token = token;
} else {
// If no token, fail gracefully. You might want to navigate
// to the login screen here in a real-world scenario.
appState = AppState.failed;
notifyListeners();
return;
}
} }
isFetchingNewItem = true;
notifyListeners();
final service = RequestService(RequestHelper.newsDetails(id, args)); final service = RequestService(RequestHelper.newsDetails(id, args));
await service.httpGet(); await service.httpGet();
_handleTracking(sendRequest: isForward != null); _handleTracking(sendRequest: isForward != null);
@ -57,7 +41,6 @@ class NewsDetailsState extends CoreProvier {
news.add(newsItem); news.add(newsItem);
initialIndex = 0; initialIndex = 0;
appState = AppState.idle; appState = AppState.idle;
notifyListeners(); // Notify listeners after state change
return; return;
} }
NewsDetailsData? prevNews; NewsDetailsData? prevNews;
@ -94,12 +77,11 @@ class NewsDetailsState extends CoreProvier {
getRelatedContents(); getRelatedContents();
} }
appState = AppState.idle; appState = AppState.idle;
notifyListeners(); // Notify listeners after state change
return; return;
} }
if (isForward == null) {
appState = AppState.failed; appState = AppState.failed;
notifyListeners(); // Notify listeners on failure }
} }
bool exists(NewsDetailsData? newsItem) => bool exists(NewsDetailsData? newsItem) =>

View File

@ -87,9 +87,7 @@ class _SplashState extends State<Splash> {
Future<void> _initialize(ThemeProvider themeProvider, Future<void> _initialize(ThemeProvider themeProvider,
UserProvider userProvider, MediaProvider mediaProvider) async { UserProvider userProvider, MediaProvider mediaProvider) async {
try { try {
print("checking if is in browser");
if (kIsWeb) { if (kIsWeb) {
print("detected browser");
html.window.onBeforeUnload.listen((event) { html.window.onBeforeUnload.listen((event) {
StorageService.webStorage StorageService.webStorage
.removeWhere((key, value) => key == 'image-cache'); .removeWhere((key, value) => key == 'image-cache');
@ -105,22 +103,20 @@ class _SplashState extends State<Splash> {
await AppInitializer.setupServices(navigatorKey.currentContext!); await AppInitializer.setupServices(navigatorKey.currentContext!);
final String? token = await userProvider.setAndGetToken(); final String? token = await userProvider.setAndGetToken();
print("detected token as $token");
if (token != null) { if (token != null) {
RequestService.token = token;
if (!kIsWeb) { if (!kIsWeb) {
await mediaProvider.getDownloadsList(); await mediaProvider.getDownloadsList();
} }
RequestService.token = token;
final result = await userProvider.getUserInfo(); final result = await userProvider.getUserInfo();
if (!result) { if (!result) {
print("no results were returned for user info");
try { try {
StorageService.delete(key: 'token'); StorageService.delete(key: 'token');
} catch (e) { } catch (e) {
print("error in case of no user info result: $e");
// catch // catch
} }
@ -131,32 +127,28 @@ class _SplashState extends State<Splash> {
return; return;
} }
print("got results for user info: $result");
await ServerDataProvider.getData(); await ServerDataProvider.getData();
} }
// --- بخش اصلاح شده ---
// ابتدا بررسی میکنیم که کاربر باید به کدام صفحه اصلی برود
final String destinationRoute = token == null ? Routes.authenticaion : Routes.home;
final dynamic routeArguments = token == null ? false : {'showDialogs': true};
print("token route is $token, initalURI.path: ${initialURI?.path}, intitlPath: ${initialURI?.path}"); // اگر لینک ورودی وجود داشت، آن را به عنوان آرگومان به صفحه Home میفرستیم
String extractedPath = initialURI?.path.toString() == '/' ? Routes.home : initialURI?.path.toString() ?? Routes.home; if (destinationRoute == Routes.home && initialURI != null) {
final String destinationRoute = token == null ? Routes.authenticaion : extractedPath; (routeArguments as Map)['deepLinkUri'] = initialURI;
dynamic routeArguments = token == null ? {'isResetPassword': false} : {'showDialogs': true}; initialURI = null; // لینک را مصرف میکنیم تا دوباره استفاده نشود
if (destinationRoute == Routes.home) {
print("destination route was home and init uri is $initialURI");
// (routeArguments as Map)['deepLinkUri'] = initialURI;
initialURI = null;
} }
if(destinationRoute == Routes.authenticaion){ // در نهایت به مسیر تعیین شده میرویم
print("destination route is auth route");
routeArguments = false;
}
print("destination route: $destinationRoute, route args: $routeArguments");
await navigatorKey.currentState!.pushReplacementNamed( await navigatorKey.currentState!.pushReplacementNamed(
destinationRoute, destinationRoute,
arguments: token == null ? false : null, arguments: routeArguments,
); );
// --- پایان بخش اصلاح شده ---
} catch (e) { } catch (e) {
setState(() { setState(() {
_errorOccured = true; _errorOccured = true;

View File

@ -1,9 +1,2 @@
update_js: update_js:
cp ./lib/assets/js/main.js ./build/flutter_assets/lib/assets/js/main.js cp ./lib/assets/js/main.js ./build/flutter_assets/lib/assets/js/main.js
zip_web:
powershell Compress-Archive -Path build\web\* -DestinationPath build.zip -Force
build_web:
flutter build web