@@ -7,31 +7,34 @@ import 'package:flutter/material.dart';
7
7
import 'package:mvc_flutter/data/utils/log_tags.dart' ;
8
8
import 'package:mvc_flutter/my_app/my_app.dart' ;
9
9
import 'package:mvc_flutter/ui/utils/base_class/inetrnet_connection_interupt.dart' ;
10
+ import 'package:mvc_flutter/ui/utils/base_class/toasts.dart' ;
10
11
11
12
class NetworkConnection {
12
- NetworkConnection ._();
13
-
13
+ static final Queue <Function > _functionQueue = Queue ();
14
14
static late StreamSubscription streamSubscription;
15
15
static ValueNotifier <bool > isNetworkAvailable = ValueNotifier (false );
16
16
static bool isAvailable = false ;
17
17
18
18
static void networkStreaming () {
19
19
streamSubscription = Connectivity ().onConnectivityChanged.listen ((event) {
20
- BuildContext ? context = navigatorKey.currentContext;
20
+ // BuildContext? context = navigatorKey.currentContext;
21
21
if (event == ConnectivityResult .none) {
22
- isNetworkAvailable.value = false ;
23
22
isAvailable = false ;
24
- if (context != null ) {
25
- Navigator .pushNamed (context, InternetConnection .route);
26
- }
23
+ isNetworkAvailable.value = false ;
24
+ errorToast ("Internet Not Connected!" );
25
+ // if (context != null) {
26
+ // Navigator.pushNamed(context, InternetConnection.route);
27
+ // }
27
28
} else {
28
- isNetworkAvailable.value = true ;
29
29
isAvailable = true ;
30
- if (context != null ) {
31
- if (Navigator .canPop (context)) {
32
- Navigator .pop (context);
33
- }
34
- }
30
+ isNetworkAvailable.value = true ;
31
+ _executeQueuedFunctions ();
32
+ successToast ("Internet Connection Restored!" );
33
+ // if (context != null) {
34
+ // if (Navigator.canPop(context)) {
35
+ // Navigator.pop(context);
36
+ // }
37
+ // }
35
38
}
36
39
log (
37
40
"Network Changed: isNetworkOn- $isAvailable Type ${event .name }" ,
@@ -48,29 +51,25 @@ class NetworkConnection {
48
51
}
49
52
}
50
53
}
51
- }
52
-
53
- mixin InternetConnectionQueue {
54
- final Queue <Function > _functionQueue = Queue ();
55
54
56
- void addToQueue (Function function) {
55
+ static void addToQueue (Function function) {
57
56
if (! _functionQueue.contains (function)) {
58
57
_functionQueue.add (function);
59
58
}
60
59
log ("addToQueue working" , name: LogTags .internetQueue);
61
60
if (_functionQueue.length == 1 ) {
62
- executeQueuedFunctions ();
61
+ _executeQueuedFunctions ();
63
62
}
64
63
}
65
64
66
- Future <void > executeQueuedFunctions () async {
65
+ static Future <void > _executeQueuedFunctions () async {
67
66
log (
68
67
"Checking Function In Pending ${_functionQueue .length }" ,
69
68
name: LogTags .internetQueue,
70
69
);
71
- if (NetworkConnection .isNetworkAvailable.value ) {
70
+ if (NetworkConnection .isAvailable ) {
72
71
while (_functionQueue.isNotEmpty) {
73
- final function = _functionQueue.first;
72
+ final function = _functionQueue.first;
74
73
try {
75
74
await function ();
76
75
log ("executeQueuedFunctions working" , name: LogTags .internetQueue);
0 commit comments