Skip to content

Commit 7e94fee

Browse files
committed
added update checker
1 parent 4b7571b commit 7e94fee

File tree

2 files changed

+42
-17
lines changed

2 files changed

+42
-17
lines changed

lib/main.dart

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import 'package:flutter/material.dart';
66
import 'package:flutter/services.dart';
77
import 'package:get/get.dart';
88
import 'package:home_widget/home_widget.dart';
9+
import 'package:in_app_update/in_app_update.dart';
910

1011
import 'package:loggy/loggy.dart';
1112
import 'package:path_provider/path_provider.dart';
@@ -66,7 +67,6 @@ Future main([List<String> args = const []]) async {
6667
return const AppSetupPlaceholder();
6768
}
6869
})));
69-
7070
}
7171

7272
Future<List<Directory>> getDirectories() async {
@@ -76,7 +76,6 @@ Future<List<Directory>> getDirectories() async {
7676
Directory baseDirectory =
7777
(directory != null) ? Directory(directory) : defaultDirectory;
7878
return [defaultDirectory, baseDirectory];
79-
8079
}
8180

8281
Future init() async {
@@ -115,6 +114,28 @@ class _MyAppState extends State<MyApp> {
115114
helperFunction();
116115
}
117116

117+
Future<void> checkForUpdate() async {
118+
// print('checking for Update');
119+
InAppUpdate.checkForUpdate().then((info) {
120+
setState(() {
121+
if (info.updateAvailability == UpdateAvailability.updateAvailable) {
122+
// print('update available');
123+
update();
124+
}
125+
});
126+
}).catchError((e) {
127+
// print(e.toString());
128+
});
129+
}
130+
131+
void update() async {
132+
// print('Updating');
133+
await InAppUpdate.startFlexibleUpdate();
134+
InAppUpdate.completeFlexibleUpdate().then((_) {}).catchError((e) {
135+
// print(e.toString());
136+
});
137+
}
138+
118139
void helperFunction() async {
119140
Uri? myUri = await HomeWidget.initiallyLaunchedFromHomeWidget();
120141
if (myUri != null) {
@@ -165,15 +186,19 @@ class _MyAppState extends State<MyApp> {
165186

166187
home: isHomeWidgetTaskTapped == false
167188
? CheckOnboardingStatus()
168-
: FutureBuilder(future: Future.delayed(const Duration(seconds: 2)), builder: (context, snapshot) {
169-
if (snapshot.connectionState == ConnectionState.waiting) {
170-
return Scaffold(
171-
backgroundColor:
172-
AppSettings.isDarkMode ? Palette.kToDark.shade200 : Colors.white,
173-
body: const Center(child: CircularProgressIndicator()));
174-
}
175-
return DetailRoute(uuid);
176-
},),
189+
: FutureBuilder(
190+
future: Future.delayed(const Duration(seconds: 2)),
191+
builder: (context, snapshot) {
192+
if (snapshot.connectionState == ConnectionState.waiting) {
193+
return Scaffold(
194+
backgroundColor: AppSettings.isDarkMode
195+
? Palette.kToDark.shade200
196+
: Colors.white,
197+
body: const Center(child: CircularProgressIndicator()));
198+
}
199+
return DetailRoute(uuid);
200+
},
201+
),
177202
);
178203
}));
179204
}

pubspec.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: taskwarrior
22
description: A new Flutter project.
3-
version: 1.0.0+1
3+
version: 2.0.0+2
44
publish_to: "none" # Remove this line if you wish to publish to pub.dev
55

66
environment:
@@ -14,9 +14,11 @@ environment:
1414
# versions available, run `flutter pub outdated`.
1515
dependencies:
1616
connectivity_plus: ^5.0.2
17+
crypto: ^3.0.1
1718
cupertino_icons: ^1.0.5
1819
date_format: ^2.0.6
1920
double_back_to_close_app: ^2.1.0
21+
file_picker: ^6.1.1
2022
file_picker_writable: ^2.0.3
2123
file_selector: ^0.9.4
2224
flutter:
@@ -25,20 +27,21 @@ dependencies:
2527
flutter_local_notifications: ^16.2.0
2628
flutter_native_splash: ^2.1.2+1
2729
flutter_native_timezone: ^2.0.0
30+
flutter_platform_widgets: ^6.0.2
2831
flutter_slidable: ^3.0.1
2932
flutter_svg: ^2.0.7
3033
get: ^4.6.5
3134
google_fonts: ^6.1.0
3235
hive: ^2.2.1
3336
hive_flutter: ^1.1.0
34-
home_widget: ^0.4.0
37+
home_widget: ^0.6.0
3538
http: ^1.1.0
3639
import_sorter: ^4.6.0
40+
in_app_update: ^4.2.3
3741
intl: ^0.18.0
3842
loggy: ^2.0.1+1
3943
package_info_plus: ^4.0.2
4044
pem: ^2.0.1
41-
# permission_handler: ^10.2.0
4245
permission_handler:
4346
git:
4447
url: https://github.com/bvoq/flutter-permission-handler.git
@@ -53,9 +56,6 @@ dependencies:
5356
tutorial_coach_mark: ^1.2.11
5457
url_launcher: ^6.1.14
5558
uuid: ^4.2.2
56-
crypto: ^3.0.1
57-
flutter_platform_widgets: ^6.0.2
58-
file_picker: ^6.1.1
5959

6060
dev_dependencies:
6161
build_runner: ^2.1.11

0 commit comments

Comments
 (0)