-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #85 from humhub/82-js-of-external-modules-not-loaded
82 js of external modules not loaded
- Loading branch information
Showing
11 changed files
with
165 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import 'package:connectivity_plus/connectivity_plus.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
|
||
class ConnectivityPlugin extends ConsumerStatefulWidget { | ||
final Widget child; | ||
|
||
const ConnectivityPlugin({ | ||
Key? key, | ||
required this.child, | ||
}) : super(key: key); | ||
|
||
@override | ||
ConnectivityPluginState createState() => ConnectivityPluginState(); | ||
|
||
static Future<bool> get hasConnectivity async { | ||
ConnectivityResult connectivityResult = await Connectivity().checkConnectivity(); | ||
return connectivityResult != ConnectivityResult.none; | ||
} | ||
} | ||
|
||
class ConnectivityPluginState extends ConsumerState<ConnectivityPlugin> { | ||
@override | ||
Widget build(BuildContext context) { | ||
return StreamBuilder<ConnectivityResult?>( | ||
stream: Connectivity().onConnectivityChanged, | ||
builder: (context, snap) { | ||
if (snap.hasData) { | ||
// Process the data from the stream | ||
ConnectivityResult result = snap.data!; | ||
if (result == ConnectivityResult.none) { | ||
WidgetsBinding.instance.addPostFrameCallback((_) { | ||
// Use a small delay to show the dialog after the build phase | ||
NoConnectionDialog.show(context); | ||
}); | ||
} | ||
} | ||
return widget.child; | ||
}, | ||
); | ||
} | ||
} | ||
|
||
class NoConnectionDialog extends StatelessWidget { | ||
const NoConnectionDialog({super.key}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return AlertDialog( | ||
title: const Text('No Connection'), | ||
content: const Text('Please check your internet connection and try again.'), | ||
actions: [ | ||
TextButton( | ||
child: const Text('OK'), | ||
onPressed: () { | ||
Navigator.of(context).pop(); // Close the dialog | ||
}, | ||
), | ||
], | ||
); | ||
} | ||
|
||
static show(BuildContext context) { | ||
showDialog( | ||
context: context, | ||
builder: (BuildContext context) { | ||
return const NoConnectionDialog(); | ||
}, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.