Skip to content

Commit

Permalink
Merge pull request #231 from sparcs-kaist/feature/internet-connectivi…
Browse files Browse the repository at this point in the history
…ty-check

Add Internet Connectivity Check
  • Loading branch information
thomaskim1130 authored Nov 7, 2024
2 parents c80b240 + fc026c8 commit c04bf5c
Show file tree
Hide file tree
Showing 9 changed files with 296 additions and 159 deletions.
10 changes: 10 additions & 0 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
PODS:
- connectivity_plus (0.0.1):
- Flutter
- ReachabilitySwift
- device_info_plus (0.0.1):
- Flutter
- DKImagePickerController/Core (4.3.9):
Expand Down Expand Up @@ -54,6 +57,7 @@ PODS:
- FlutterMacOS
- permission_handler_apple (9.3.0):
- Flutter
- ReachabilitySwift (5.2.3)
- quill_native_bridge (0.0.1):
- Flutter
- SDWebImage (5.19.2):
Expand All @@ -77,6 +81,7 @@ PODS:
- FlutterMacOS

DEPENDENCIES:
- connectivity_plus (from `.symlinks/plugins/connectivity_plus/ios`)
- device_info_plus (from `.symlinks/plugins/device_info_plus/ios`)
- file_picker (from `.symlinks/plugins/file_picker/ios`)
- Flutter (from `Flutter`)
Expand All @@ -100,10 +105,13 @@ SPEC REPOS:
trunk:
- DKImagePickerController
- DKPhotoGallery
- ReachabilitySwift
- SDWebImage
- SwiftyGif

EXTERNAL SOURCES:
connectivity_plus:
:path: ".symlinks/plugins/connectivity_plus/ios"
device_info_plus:
:path: ".symlinks/plugins/device_info_plus/ios"
file_picker:
Expand Down Expand Up @@ -142,6 +150,7 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/webview_flutter_wkwebview/darwin"

SPEC CHECKSUMS:
connectivity_plus: bf0076dd84a130856aa636df1c71ccaff908fa1d
device_info_plus: 97af1d7e84681a90d0693e63169a5d50e0839a0d
DKImagePickerController: 946cec48c7873164274ecc4624d19e3da4c1ef3c
DKPhotoGallery: b3834fecb755ee09a593d7c9e389d8b5d6deed60
Expand All @@ -155,6 +164,7 @@ SPEC CHECKSUMS:
irondash_engine_context: 3458bf979b90d616ffb8ae03a150bafe2e860cc9
path_provider_foundation: 2b6b4c569c0fb62ec74538f866245ac84301af46
permission_handler_apple: 9878588469a2b0d0fc1e048d9f43605f92e6cec2
ReachabilitySwift: 7f151ff156cea1481a8411701195ac6a984f4979
quill_native_bridge: e5afa7d49c08cf68c52a5e23bc272eba6925c622
SDWebImage: dfe95b2466a9823cf9f0c6d01217c06550d7b29a
shared_preferences_foundation: fcdcbc04712aee1108ac7fda236f363274528f78
Expand Down
3 changes: 3 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import 'package:connectivity_plus/connectivity_plus.dart';
import 'package:flutter/material.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:new_ara_app/constants/url_info.dart';
import 'package:new_ara_app/providers/connectivity_provider.dart';
import 'package:new_ara_app/translations/codegen_loader.g.dart';
import 'package:new_ara_app/utils/global_key.dart';
import 'package:new_ara_app/widgets/loading_indicator.dart';
Expand Down Expand Up @@ -55,6 +57,7 @@ void main() async {
..updateCookie(userProvider.getCookiesToString());
}),
ChangeNotifierProvider(create: (_) => BlockedProvider()),
ChangeNotifierProvider(create: (_) => ConnectivityProvider()),
],
child: const MyApp(),
),
Expand Down
238 changes: 130 additions & 108 deletions lib/pages/main_page.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import 'dart:async';

import 'package:connectivity_plus/connectivity_plus.dart';
import 'package:flutter/material.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:new_ara_app/pages/bulletin_search_page.dart';
import 'package:new_ara_app/providers/connectivity_provider.dart';
import 'package:new_ara_app/translations/locale_keys.g.dart';
import 'package:provider/provider.dart';

Expand Down Expand Up @@ -95,9 +99,16 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver {

@override
void didChangeAppLifecycleState(AppLifecycleState state) async {
super.didChangeAppLifecycleState(state);
// 앱이 포그라운드로 전환될 때 실행할 함수
if (state == AppLifecycleState.resumed) {
ConnectivityProvider connectivityProvider =
context.read<ConnectivityProvider>();

// 인터넷 연결 상태도 확인하기
if (state == AppLifecycleState.resumed &&
connectivityProvider.isConnected) {
//api를 호출 후 최신 데이터로 갱신
debugPrint('App in Foreground');
await _refreshAllPosts();
}
}
Expand Down Expand Up @@ -262,24 +273,32 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver {
Future<void> _refreshAllPosts() async {
debugPrint("main_page.dart: _refreshAllPosts() called.");
UserProvider userProvider = context.read<UserProvider>();
await Future.wait([
_refreshTopContents(userProvider, _dailyBestContents),
_refreshOtherContents(userProvider, "portal-notice", "", _portalContents),
_refreshOtherContents(
userProvider, "facility-notice", "", _facilityContents),
_refreshOtherContents(userProvider, "ara-notice", "", _newAraContents),
_refreshOtherContents(
userProvider, "students-group", "grad-assoc", _gradContents),
_refreshOtherContents(userProvider, "students-group", "undergrad-assoc",
_underGradContents),
_refreshOtherContents(userProvider, "students-group", "freshman-council",
_freshmanContents),
_refreshOtherContents(userProvider, "talk", "", _talksContents),
_refreshOtherContents(userProvider, "wanted", "", _wantedContents),
_refreshOtherContents(userProvider, "market", "", _marketContents),
_refreshOtherContents(
userProvider, "real-estate", "", _realEstateContents),
]);
ConnectivityProvider connectivityProvider =
context.read<ConnectivityProvider>();
if (connectivityProvider.isConnected) {
await Future.wait([
_refreshTopContents(userProvider, _dailyBestContents),
_refreshOtherContents(
userProvider, "portal-notice", "", _portalContents),
_refreshOtherContents(
userProvider, "facility-notice", "", _facilityContents),
_refreshOtherContents(userProvider, "ara-notice", "", _newAraContents),
_refreshOtherContents(
userProvider, "students-group", "grad-assoc", _gradContents),
_refreshOtherContents(userProvider, "students-group", "undergrad-assoc",
_underGradContents),
_refreshOtherContents(userProvider, "students-group",
"freshman-council", _freshmanContents),
_refreshOtherContents(userProvider, "talk", "", _talksContents),
_refreshOtherContents(userProvider, "wanted", "", _wantedContents),
_refreshOtherContents(userProvider, "market", "", _marketContents),
_refreshOtherContents(
userProvider, "real-estate", "", _realEstateContents),
]);
} else {
debugPrint(
"main_page.dart: _refreshAllPosts() denied by Internet error.");
}
}

/// 일일 베스트 컨텐츠 데이터를 api로 불러와 화면에 재빌드
Expand Down Expand Up @@ -363,102 +382,105 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver {

@override
Widget build(BuildContext context) {
// debugPrint("build invoked!!");
return Scaffold(
appBar: AppBar(
elevation: 0,
title: SvgPicture.asset(
'assets/images/logo.svg',
fit: BoxFit.cover,
),
actions: [
IconButton(
debugPrint("build invoked!!");
return Consumer<ConnectivityProvider>(
builder: (context, connectivityProvider, child) {
return Scaffold(
appBar: AppBar(
elevation: 0,
title: SvgPicture.asset(
'assets/images/logo.svg',
fit: BoxFit.cover,
),
actions: [
IconButton(
onPressed: () async {
if (context.locale == const Locale('ko')) {
await context.setLocale(const Locale('en'));
} else {
await context.setLocale(const Locale('ko'));
}
},
icon: const Icon(
Icons.language,
color: ColorsInfo.newara,
)),
IconButton(
icon: SvgPicture.asset(
'assets/icons/post.svg',
colorFilter:
const ColorFilter.mode(ColorsInfo.newara, BlendMode.srcIn),
width: 35,
height: 35,
),
onPressed: () async {
if (context.locale == const Locale('ko')) {
await context.setLocale(const Locale('en'));
} else {
await context.setLocale(const Locale('ko'));
}
await Navigator.of(context)
.push(slideRoute(const PostWritePage()));
await _refreshAllPosts();
},
icon: const Icon(
Icons.language,
color: ColorsInfo.newara,
)),
IconButton(
icon: SvgPicture.asset(
'assets/icons/post.svg',
colorFilter:
const ColorFilter.mode(ColorsInfo.newara, BlendMode.srcIn),
width: 35,
height: 35,
),
onPressed: () async {
await Navigator.of(context)
.push(slideRoute(const PostWritePage()));
await _refreshAllPosts();
},
),
IconButton(
icon: SvgPicture.asset(
'assets/icons/search.svg',
colorFilter:
const ColorFilter.mode(ColorsInfo.newara, BlendMode.srcIn),
width: 35,
height: 35,
IconButton(
icon: SvgPicture.asset(
'assets/icons/search.svg',
colorFilter:
const ColorFilter.mode(ColorsInfo.newara, BlendMode.srcIn),
width: 35,
height: 35,
),
onPressed: () async {
await Navigator.of(context).push(slideRoute(
const BulletinSearchPage(
boardType: BoardType.all, boardInfo: null)));
await _refreshAllPosts();
},
),
onPressed: () async {
await Navigator.of(context).push(slideRoute(
const BulletinSearchPage(
boardType: BoardType.all, boardInfo: null)));
await _refreshAllPosts();
},
),
],
),
body: SafeArea(
child: _isLoading[0] ||
_isLoading[1] ||
_isLoading[2] ||
_isLoading[3] ||
_isLoading[4] ||
_isLoading[5] ||
_isLoading[6] ||
_isLoading[7] ||
_isLoading[8] ||
_isLoading[9] ||
_isLoading[10] ||
_isLoading[11]
? const LoadingIndicator()
: RefreshIndicator.adaptive(
displacement: 0.0,
color: ColorsInfo.newara,
onRefresh: () async {
//api를 호출 후 최신 데이터로 갱신
await _refreshAllPosts();
},
child: SingleChildScrollView(
child: SizedBox(
width: MediaQuery.of(context).size.width,
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
_buildTopContents(),
const SizedBox(height: 20),
_buildTalkContents(),
const SizedBox(height: 20),
_buildNoticeContents(),
const SizedBox(height: 20),
_buildTradeContents(),
const SizedBox(height: 20),
_buildStuCommunityContents(),
const SizedBox(height: 20),
],
],
),
body: SafeArea(
child: _isLoading[0] ||
_isLoading[1] ||
_isLoading[2] ||
_isLoading[3] ||
_isLoading[4] ||
_isLoading[5] ||
_isLoading[6] ||
_isLoading[7] ||
_isLoading[8] ||
_isLoading[9] ||
_isLoading[10] ||
_isLoading[11]
? const LoadingIndicator()
: RefreshIndicator.adaptive(
displacement: 0.0,
color: ColorsInfo.newara,
onRefresh: () async {
//api를 호출 후 최신 데이터로 갱신
await _refreshAllPosts();
},
child: SingleChildScrollView(
child: SizedBox(
width: MediaQuery.of(context).size.width,
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
_buildTopContents(),
const SizedBox(height: 20),
_buildTalkContents(),
const SizedBox(height: 20),
_buildNoticeContents(),
const SizedBox(height: 20),
_buildTradeContents(),
const SizedBox(height: 20),
_buildStuCommunityContents(),
const SizedBox(height: 20),
],
),
),
),
),
),
),
);
),
);
});
}

Widget _buildTopContents() {
Expand Down
Loading

0 comments on commit c04bf5c

Please sign in to comment.