Skip to content

Commit

Permalink
Merge pull request #381 from inderjeet-developer7/internet-check
Browse files Browse the repository at this point in the history
Internet State Management #337
  • Loading branch information
gtalha07 authored Nov 25, 2022
2 parents 0fced8a + 71f491c commit a0617c3
Show file tree
Hide file tree
Showing 12 changed files with 544 additions and 336 deletions.
Binary file added app/assets/images/no_internet.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
58 changes: 58 additions & 0 deletions app/lib/controllers/network_controller.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import 'dart:async';

import 'package:connectivity_plus/connectivity_plus.dart';
import 'package:flutter/services.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

class NetworkController extends GetxController {
static NetworkController to = Get.find();

var connectionType = ''.obs;
final Connectivity _connectivity = Connectivity();
late StreamSubscription _streamSubscription;

@override
void onInit() {
super.onInit();
_getConnectionType();
_streamSubscription =
_connectivity.onConnectivityChanged.listen(_updateState);
}

Future<void> _getConnectionType() async {
ConnectivityResult? connectivityResult;
try {
connectivityResult = await (_connectivity.checkConnectivity());
} on PlatformException catch (e) {
debugPrint(e.toString());
}
return _updateState(connectivityResult!);
}

void _updateState(ConnectivityResult result) {
switch (result) {
case ConnectivityResult.wifi:
connectionType = '1'.obs;
update();
break;
case ConnectivityResult.mobile:
connectionType = '2'.obs;
update();
break;
case ConnectivityResult.none:
connectionType = '0'.obs;
update();
break;
default:
Get.snackbar('Network Error', 'Failed to get Network Status');
break;
}
}

@override
void onClose() {
_streamSubscription.cancel();
super.onClose();
}
}
10 changes: 8 additions & 2 deletions app/lib/screens/HomeScreens/chat/ChatScreen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:effektio/common/store/themes/ChatTheme.dart';
import 'package:effektio/common/store/themes/SeperatedThemes.dart';
import 'package:effektio/controllers/chat_list_controller.dart';
import 'package:effektio/controllers/chat_room_controller.dart';
import 'package:effektio/controllers/network_controller.dart';
import 'package:effektio/screens/HomeScreens/chat/ChatProfile.dart';
import 'package:effektio/widgets/AppCommon.dart';
import 'package:effektio/widgets/ChatBubbleBuilder.dart';
Expand Down Expand Up @@ -48,12 +49,15 @@ class ChatScreen extends StatefulWidget {
class _ChatScreenState extends State<ChatScreen> {
ChatRoomController roomController = Get.find<ChatRoomController>();
ChatListController listController = Get.find<ChatListController>();
final networkController = Get.put(NetworkController());

@override
void initState() {
super.initState();

roomController.setCurrentRoom(widget.room);
if (networkController.connectionType.value != '0') {
roomController.setCurrentRoom(widget.room);
}
}

@override
Expand Down Expand Up @@ -297,7 +301,9 @@ class _ChatScreenState extends State<ChatScreen> {
body: Obx(
() => SafeArea(
bottom: false,
child: buildBody(context),
child: networkController.connectionType.value == '0'
? noInternetWidget()
: buildBody(context),
),
),
);
Expand Down
148 changes: 79 additions & 69 deletions app/lib/screens/HomeScreens/chat/Overview.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dart:ui';

import 'package:effektio/common/store/themes/SeperatedThemes.dart';
import 'package:effektio/controllers/chat_list_controller.dart';
import 'package:effektio/controllers/network_controller.dart';
import 'package:effektio/widgets/AppCommon.dart';
import 'package:effektio/widgets/ChatListItem.dart';
import 'package:effektio/widgets/InviteInfoWidget.dart';
Expand All @@ -25,78 +26,87 @@ class ChatOverview extends StatefulWidget {
}

class _ChatOverviewState extends State<ChatOverview> {
final networkController = Get.put(NetworkController());

@override
Widget build(BuildContext context) {
return Scaffold(
body: CustomScrollView(
physics: const BouncingScrollPhysics(),
slivers: [
SliverAppBar(
pinned: false,
snap: false,
floating: true,
leading: TextButton(
onPressed: () {},
child: Container(
margin: const EdgeInsets.only(right: 15),
child: Text(
AppLocalizations.of(context)!.chat,
style: AppCommonTheme.appBarTitleStyle,
),
),
),
leadingWidth: 100,
actions: [
IconButton(
onPressed: () {
showNotYetImplementedMsg(
context,
'Chat Search is not implemented yet',
);
},
padding: const EdgeInsets.only(right: 10, left: 5),
icon: const Icon(
FlutterIcons.search1_ant,
color: AppCommonTheme.svgIconColor,
),
),
IconButton(
onPressed: () {
showNotYetImplementedMsg(
context,
'Multiselect is not implemented yet',
);
},
padding: const EdgeInsets.only(right: 10, left: 5),
icon: const Icon(
FlutterIcons.select_mco,
color: AppCommonTheme.svgIconColor,
),
),
IconButton(
onPressed: () {
showNotYetImplementedMsg(
context,
'Starting a new chat is not implemented yet',
);
},
padding: const EdgeInsets.only(right: 10, left: 10),
icon: const Icon(
FlutterIcons.md_add_ion,
color: AppCommonTheme.svgIconColor,
),
return Obx(
() => Scaffold(
body: networkController.connectionType.value == '0'
? noInternetWidget()
: CustomScrollView(
physics: const BouncingScrollPhysics(),
slivers: [
SliverAppBar(
pinned: false,
snap: false,
floating: true,
leading: TextButton(
onPressed: () {},
child: Container(
margin: const EdgeInsets.only(right: 15),
child: Text(
AppLocalizations.of(context)!.chat,
style: AppCommonTheme.appBarTitleStyle,
),
),
),
leadingWidth: 100,
actions: [
IconButton(
onPressed: () {
showNotYetImplementedMsg(
context,
'Chat Search is not implemented yet',
);
},
padding: const EdgeInsets.only(right: 10, left: 5),
icon: const Icon(
FlutterIcons.search1_ant,
color: AppCommonTheme.svgIconColor,
),
),
IconButton(
onPressed: () {
showNotYetImplementedMsg(
context,
'Multiselect is not implemented yet',
);
},
padding: const EdgeInsets.only(right: 10, left: 5),
icon: const Icon(
FlutterIcons.select_mco,
color: AppCommonTheme.svgIconColor,
),
),
IconButton(
onPressed: () {
showNotYetImplementedMsg(
context,
'Starting a new chat is not implemented yet',
);
},
padding: const EdgeInsets.only(right: 10, left: 10),
icon: const Icon(
FlutterIcons.md_add_ion,
color: AppCommonTheme.svgIconColor,
),
),
],
),
SliverToBoxAdapter(
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
if (widget.client.isGuest())
empty
else
buildList(context),
],
),
),
],
),
],
),
SliverToBoxAdapter(
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
if (widget.client.isGuest()) empty else buildList(context),
],
),
),
],
),
);
}
Expand Down
Loading

0 comments on commit a0617c3

Please sign in to comment.