edit dialogs

This commit is contained in:
mohamadmahdi jebeli 2025-07-16 15:25:48 +03:30
parent ff18f13786
commit f14be3879d
8 changed files with 239 additions and 181 deletions

View File

@ -142,9 +142,10 @@ class _HomeState extends State<Home>
@override
void initState() {
if (widget.showDialogs ?? false) {
_showDialog(context);
}
// Remove dialog showing logic to prevent welcome popups
// if (widget.showDialogs ?? false) {
// _showDialog(context);
// }
final state = context.read<HomeState>();
DesignConfig.updateSystemUiOverlayStyle();

View File

@ -42,7 +42,8 @@ class _NewsDetailsState extends State<NewsDetails> {
return Scaffold(
body: Consumer<NewsDetailsState>(
builder: (context, state, child) => StateHandler<NewsDetailsState>(
onRetry: () => state.getNewsDetails(state.currentNews.id),
onRetry: () =>
state.getNewsDetails(widget.pageData['id']),
state: state,
builder: (context, state) => Stack(
children: [

View File

@ -1,5 +1,3 @@
// lib/views/news/news_details/news_details_state.dart
import 'dart:async';
import 'dart:math';
@ -10,8 +8,6 @@ import 'package:didvan/models/requests/news.dart';
import 'package:didvan/providers/core.dart';
import 'package:didvan/services/network/request.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 {
final List<NewsDetailsData?> news = [];
@ -21,6 +17,7 @@ class NewsDetailsState extends CoreProvier {
int _trackingTimerCounter = 0;
bool isFetchingNewItem = false;
final List<int> relatedQueue = [];
bool _isRequestInProgress = false;
int _currentIndex = 0;
int get currentIndex => _currentIndex;
@ -29,27 +26,33 @@ class NewsDetailsState extends CoreProvier {
NewsDetailsData get currentNews => news[_currentIndex]!;
Future<void> getNewsDetails(int id, {bool? isForward}) async {
debugPrint('requset token ${RequestService.token}');
// **FIX: Ensure the token is available before making a request.**
if (RequestService.token == null) {
final token = await StorageService.getValue(key: 'token');
if (token != null) {
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();
// Prevent duplicate requests
if (_isRequestInProgress) {
return;
}
}
_isRequestInProgress = true;
// Set loading state
if (isForward == null) {
appState = AppState.busy;
} else {
isFetchingNewItem = true;
notifyListeners();
}
try {
// Wait for token to be ready
if (RequestService.token == null || RequestService.token!.isEmpty) {
await Future.delayed(const Duration(milliseconds: 500));
if (RequestService.token == null || RequestService.token!.isEmpty) {
throw Exception('Token not available');
}
}
final service = RequestService(RequestHelper.newsDetails(id, args));
await service.httpGet();
_handleTracking(sendRequest: isForward != null);
if (service.isSuccess) {
final result = service.result;
final newsItem = NewsDetailsData.fromJson(result['news']);
@ -57,7 +60,8 @@ class NewsDetailsState extends CoreProvier {
news.add(newsItem);
initialIndex = 0;
appState = AppState.idle;
notifyListeners(); // Notify listeners after state change
isFetchingNewItem = false;
_isRequestInProgress = false;
return;
}
NewsDetailsData? prevNews;
@ -94,12 +98,24 @@ class NewsDetailsState extends CoreProvier {
getRelatedContents();
}
appState = AppState.idle;
notifyListeners(); // Notify listeners after state change
return;
}
} else {
isFetchingNewItem = false;
if (isForward == null) {
appState = AppState.failed;
notifyListeners(); // Notify listeners on failure
} else {
notifyListeners();
}
}
} catch (e) {
print('Error fetching news details: $e');
isFetchingNewItem = false;
if (isForward == null) {
appState = AppState.failed;
}
notifyListeners();
} finally {
_isRequestInProgress = false;
}
}
bool exists(NewsDetailsData? newsItem) =>

View File

@ -56,7 +56,8 @@ class _GeneralSettingsState extends State<GeneralSettings> {
appBarData: AppBarData(hasBack: true, title: 'تنظیمات'),
children: [
DidvanCard(
child: MenuOption(
child:
MenuOption(
title: 'زمان دریافت اعلان',
onTap: () => Navigator.of(context).pushNamed(
Routes.notificationTime,

View File

@ -94,47 +94,47 @@ class _ProfilePageState extends State<ProfilePage> {
padding: const EdgeInsets.only(right: 8.0, top: 8),
child: Column(
children: [
Padding(
padding: const EdgeInsets.symmetric(
vertical: 12.0),
child: MenuOption(
title: 'زمان دریافت اعلان',
onTap: () =>
Navigator.of(context).pushNamed(
Routes.notificationTime,
arguments: {
"fromFav": false,
'onTimeChanged': () => Future.delayed(
Duration.zero,
() => state.getTime(),
)
},
),
icon: DidvanIcons.notification_regular,
suffix: state.time,
// suffix: 'از${DateTimeUtils.normalizeTimeDuration(
// Duration(minutes: state.notificationTimeRange[0]),
// )} تا ${DateTimeUtils.normalizeTimeDuration(
// Duration(minutes: state.notificationTimeRange[1]),
// )}',
),
),
Padding(
padding: const EdgeInsets.symmetric(
vertical: 12.0),
child: MenuOption(
title: 'شخصی سازی محتوا',
onTap: () => Navigator.of(context)
.pushNamed(Routes.favouritesStep,
arguments: {"toTimer": false}),
icon: DidvanIcons.note_regular,
// suffix: 'از${DateTimeUtils.normalizeTimeDuration(
// Duration(minutes: state.notificationTimeRange[0]),
// )} تا ${DateTimeUtils.normalizeTimeDuration(
// Duration(minutes: state.notificationTimeRange[1]),
// )}',
),
),
// Padding(
// padding: const EdgeInsets.symmetric(
// vertical: 12.0),
// child: MenuOption(
// title: 'زمان دریافت اعلان',
// onTap: () =>
// Navigator.of(context).pushNamed(
// Routes.notificationTime,
// arguments: {
// "fromFav": false,
// 'onTimeChanged': () => Future.delayed(
// Duration.zero,
// () => state.getTime(),
// )
// },
// ),
// icon: DidvanIcons.notification_regular,
// suffix: state.time,
// // suffix: 'از${DateTimeUtils.normalizeTimeDuration(
// // Duration(minutes: state.notificationTimeRange[0]),
// // )} تا ${DateTimeUtils.normalizeTimeDuration(
// // Duration(minutes: state.notificationTimeRange[1]),
// // )}',
// ),
// ),
// Padding(
// padding: const EdgeInsets.symmetric(
// vertical: 12.0),
// child: MenuOption(
// title: 'شخصی سازی محتوا',
// onTap: () => Navigator.of(context)
// .pushNamed(Routes.favouritesStep,
// arguments: {"toTimer": false}),
// icon: DidvanIcons.note_regular,
// // suffix: 'از${DateTimeUtils.normalizeTimeDuration(
// // Duration(minutes: state.notificationTimeRange[0]),
// // )} تا ${DateTimeUtils.normalizeTimeDuration(
// // Duration(minutes: state.notificationTimeRange[1]),
// // )}',
// ),
// ),
Padding(
padding: const EdgeInsets.symmetric(
vertical: 12.0),

View File

@ -18,6 +18,7 @@ class RadarDetailsState extends CoreProvier {
bool isFetchingNewItem = false;
final List<int> relatedQueue = [];
bool openComments = false;
bool _isRequestInProgress = false;
int _currentIndex = 0;
int get currentIndex => _currentIndex;
@ -31,15 +32,33 @@ class RadarDetailsState extends CoreProvier {
}
Future<void> getRadarDetails(int id, {bool? isForward}) async {
// Prevent duplicate requests
if (_isRequestInProgress) {
return;
}
_isRequestInProgress = true;
// Set loading state
if (isForward == null) {
appState = AppState.busy;
} else {
isFetchingNewItem = true;
notifyListeners();
}
try {
// Wait for token to be ready
if (RequestService.token == null || RequestService.token!.isEmpty) {
await Future.delayed(const Duration(milliseconds: 500));
if (RequestService.token == null || RequestService.token!.isEmpty) {
throw Exception('Token not available');
}
}
final service = RequestService(RequestHelper.radarDetails(id, args));
await service.httpGet();
_handleTracking(sendRequest: isForward != null);
if (service.isSuccess) {
final result = service.result;
final radar = RadarDetailsData.fromJson(result['radar']);
@ -47,6 +66,8 @@ class RadarDetailsState extends CoreProvier {
radars.add(radar);
initialIndex = 0;
appState = AppState.idle;
isFetchingNewItem = false;
_isRequestInProgress = false;
return;
}
@ -86,11 +107,23 @@ class RadarDetailsState extends CoreProvier {
getRelatedContents();
}
appState = AppState.idle;
return;
}
//why? total page state shouldn't die!
} else {
isFetchingNewItem = false;
if (isForward == null) {
appState = AppState.failed;
} else {
notifyListeners();
}
}
} catch (e) {
print('Error fetching radar details: $e');
isFetchingNewItem = false;
if (isForward == null) {
appState = AppState.failed;
}
notifyListeners();
} finally {
_isRequestInProgress = false;
}
}

View File

@ -135,10 +135,11 @@ class _SplashState extends State<Splash> {
await ServerDataProvider.getData();
}
print("token route is $token, initalURI.path: ${initialURI?.path}, intitlPath: ${initialURI?.path}");
print("token route is $token");
String extractedPath = initialURI?.path.toString() == '/' ? Routes.home : initialURI?.path.toString() ?? Routes.home;
final String destinationRoute = token == null ? Routes.authenticaion : extractedPath;
dynamic routeArguments = token == null ? {'isResetPassword': false} : {'showDialogs': true};
// Set showDialogs to false to prevent welcome popups
dynamic routeArguments = token == null ? {'isResetPassword': false} : {'showDialogs': false};
if (destinationRoute == Routes.home) {
@ -155,7 +156,7 @@ class _SplashState extends State<Splash> {
print("destination route: $destinationRoute, route args: $routeArguments");
await navigatorKey.currentState!.pushReplacementNamed(
destinationRoute,
arguments: token == null ? false : null,
arguments: routeArguments,
);
} catch (e) {
setState(() {

View File

@ -26,12 +26,14 @@ class _WebViewState extends State<WebView> {
};
void _onProgress(int progress) {
print('🌐 WebView loading progress: $progress%'); // Add logging
setState(() {
this.progress = progress;
});
}
void _onPageFinished(String url) async {
print('✅ WebView finished loading: $url'); // Add logging
await Future.delayed(const Duration(seconds: 2));
setState(() {
if (progress == 100) loading = false;
@ -40,21 +42,24 @@ class _WebViewState extends State<WebView> {
@override
void initState() {
print('🔄 Initializing WebView with URL: ${widget.src}'); // Add logging
controller = WebViewController()
..setJavaScriptMode(JavaScriptMode.unrestricted)
..setNavigationDelegate(
NavigationDelegate(
onProgress: _onProgress,
onPageStarted: (String url) {},
onPageStarted: (String url) {
print('▶️ WebView started loading: $url'); // Add logging
},
onPageFinished: _onPageFinished,
onHttpError: (HttpResponseError error) {},
onHttpError: (HttpResponseError error) {
// print('❌ WebView HTTP error: ${error.statusCode} on ${error.url}'); // Add logging
},
onWebResourceError: (WebResourceError error) {
// navigatorKey.currentState!.pop();
// print('❌ WebView resource error: ${error.description} on ${error.failingUrl}'); // Add logging
},
onNavigationRequest: (NavigationRequest request) {
// if (request.url.startsWith('https://www.youtube.com/')) {
// return NavigationDecision.prevent;
// }
print('🔀 WebView navigation request to: ${request.url}'); // Add logging
return NavigationDecision.navigate;
},
),
@ -77,7 +82,7 @@ class _WebViewState extends State<WebView> {
child: Scaffold(
appBar: AppBar(
title: const DidvanText(
'بازگشت به دیدوان',
'بازگشت',
),
leading: const BackButton(),
),