splash screen error handling added
This commit is contained in:
parent
fdbbc914af
commit
0553cc75ae
|
|
@ -10,10 +10,12 @@ import 'package:didvan/services/app_initalizer.dart';
|
||||||
import 'package:didvan/services/network/request.dart';
|
import 'package:didvan/services/network/request.dart';
|
||||||
import 'package:didvan/services/storage/storage.dart';
|
import 'package:didvan/services/storage/storage.dart';
|
||||||
import 'package:didvan/utils/action_sheet.dart';
|
import 'package:didvan/utils/action_sheet.dart';
|
||||||
|
import 'package:didvan/widgets/didvan/button.dart';
|
||||||
import 'package:didvan/widgets/logos/didvan_horizontal_logo.dart';
|
import 'package:didvan/widgets/logos/didvan_horizontal_logo.dart';
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
|
import 'package:flutter_spinkit/flutter_spinkit.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
import 'package:universal_html/html.dart' as html;
|
import 'package:universal_html/html.dart' as html;
|
||||||
|
|
||||||
|
|
@ -26,6 +28,7 @@ class Splash extends StatefulWidget {
|
||||||
|
|
||||||
class _SplashState extends State<Splash> {
|
class _SplashState extends State<Splash> {
|
||||||
bool _isGettingThemeData = true;
|
bool _isGettingThemeData = true;
|
||||||
|
bool _errorOccured = false;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
|
|
@ -51,13 +54,38 @@ class _SplashState extends State<Splash> {
|
||||||
alignment: Alignment.center,
|
alignment: Alignment.center,
|
||||||
padding: const EdgeInsets.all(60),
|
padding: const EdgeInsets.all(60),
|
||||||
color: Theme.of(context).colorScheme.background,
|
color: Theme.of(context).colorScheme.background,
|
||||||
child: const DidvanVerticalLogo(),
|
child: Column(
|
||||||
|
children: [
|
||||||
|
const SizedBox(height: 70),
|
||||||
|
const Expanded(
|
||||||
|
child: DidvanVerticalLogo(),
|
||||||
|
),
|
||||||
|
if (!_errorOccured)
|
||||||
|
SpinKitSpinningLines(
|
||||||
|
color: Theme.of(context).colorScheme.primary,
|
||||||
|
),
|
||||||
|
if (_errorOccured) const SizedBox(height: 38),
|
||||||
|
if (_errorOccured)
|
||||||
|
DidvanButton(
|
||||||
|
width: 120,
|
||||||
|
height: 40,
|
||||||
|
title: 'تلاش مجدد',
|
||||||
|
onPressed: () {
|
||||||
|
setState(() {
|
||||||
|
_errorOccured = false;
|
||||||
|
});
|
||||||
|
_initialize();
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _initialize() async {
|
Future<void> _initialize() async {
|
||||||
|
try {
|
||||||
ActionSheetUtils.context = navigatorKey.currentContext!;
|
ActionSheetUtils.context = navigatorKey.currentContext!;
|
||||||
if (kIsWeb) {
|
if (kIsWeb) {
|
||||||
html.window.onBeforeUnload.listen((event) {
|
html.window.onBeforeUnload.listen((event) {
|
||||||
|
|
@ -86,5 +114,10 @@ class _SplashState extends State<Splash> {
|
||||||
token == null ? Routes.authenticaion : Routes.home,
|
token == null ? Routes.authenticaion : Routes.home,
|
||||||
arguments: token == null ? false : null,
|
arguments: token == null ? false : null,
|
||||||
);
|
);
|
||||||
|
} catch (e) {
|
||||||
|
setState(() {
|
||||||
|
_errorOccured = true;
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue