Skip to content

Commit

Permalink
feat: alerting the user incase of network connection changes
Browse files Browse the repository at this point in the history
  • Loading branch information
IamMuuo committed Dec 16, 2024
1 parent 9575f6d commit 2be151e
Showing 1 changed file with 39 additions and 3 deletions.
42 changes: 39 additions & 3 deletions lib/features/home/views/layout.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import 'dart:async';

import 'package:academia/features/features.dart';
import 'package:academia/features/profile/profile_page_desktop.dart';
import 'package:academia/utils/responsive/responsive.dart';
import 'package:connectivity_plus/connectivity_plus.dart';
import 'package:flutter/material.dart';
import 'package:icons_plus/icons_plus.dart';

Expand All @@ -18,16 +20,50 @@ class _LayoutState extends State<Layout> {
child: Text("Statistics"),
),
Center(
child: Text("Statistics"),
child: Text("Courses"),
),
Center(
child: Text("Statistics"),
child: Text("Social"),
),
Center(
child: Text("Statistics"),
),
ProfilePage()
];

// Stream subscription for network notification
@override
void initState() {
super.initState();
StreamSubscription<List<ConnectivityResult>> subscription = Connectivity()
.onConnectivityChanged
.listen((List<ConnectivityResult> result) {
// Received changes in available connectivity types!
if (result.contains(ConnectivityResult.none)) {
if (!mounted) return;
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
duration: Duration(days: 30),
showCloseIcon: true,
content: Text(
"Your internet connection has been lost some features may not work"),
),
);
return;
}
if (!result.contains(ConnectivityResult.none)) {
if (!mounted) return;
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
showCloseIcon: true,
content: Text("Your internet connection has been restored"),
),
);
return;
}
});
}

@override
Widget build(BuildContext context) {
return LayoutBuilder(
Expand Down

0 comments on commit 2be151e

Please sign in to comment.