From 984041c75f4fb7774d11774863d3de52d5e58116 Mon Sep 17 00:00:00 2001 From: Felipe Bueno Date: Mon, 19 Jun 2023 14:28:59 -0300 Subject: [PATCH] 1.0.1+3: In app update (Google Play) --- README.md | 4 +-- android/build.gradle | 4 +-- lib/main.dart | 2 ++ lib/utils.dart | 42 +++++++++++++++++++++++++++++++ lib/widgets/base_tab.dart | 2 +- lib/widgets/posts/post_utils.dart | 2 +- pubspec.lock | 8 ++++++ pubspec.yaml | 3 ++- 8 files changed, 60 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 6fb2f57..1d24885 100644 --- a/README.md +++ b/README.md @@ -59,9 +59,9 @@ Not implemented yet. - [ ] Fix mardown rendering issues - - [ ] Android in_app_update (https://pub.dev/packages/in_app_update) + - [x] Android in_app_update (https://pub.dev/packages/in_app_update) - - [ ] Search + - [ ] Handle in_app_update errors - [ ] Better light theme diff --git a/android/build.gradle b/android/build.gradle index f7eb7f6..2611d1c 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -1,5 +1,5 @@ buildscript { - ext.kotlin_version = '1.7.10' + ext.kotlin_version = '1.8.22' repositories { google() mavenCentral() @@ -26,6 +26,6 @@ subprojects { project.evaluationDependsOn(':app') } -tasks.register("clean", Delete) { +tasks.register('clean', Delete) { delete rootProject.buildDir } diff --git a/lib/main.dart b/lib/main.dart index afb3cd2..45ed3cc 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,10 +1,12 @@ import 'package:flutter/material.dart'; import 'package:stacker_news/pages/home_page.dart'; import 'package:stacker_news/sn_router.dart'; +import 'package:stacker_news/utils.dart'; import 'colors.dart'; void main() { + Utils.checkForUpdate(); runApp(const StackerNewsApp()); } diff --git a/lib/utils.dart b/lib/utils.dart index e6436e5..79339a5 100644 --- a/lib/utils.dart +++ b/lib/utils.dart @@ -1,4 +1,8 @@ +import 'dart:io'; + +import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; +import 'package:in_app_update/in_app_update.dart'; import 'package:url_launcher/url_launcher.dart'; class Utils { @@ -19,4 +23,42 @@ class Utils { SnackBar(content: Text(message)), ); } + + static void showWarning(BuildContext context, String message) { + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + content: Text(message), + backgroundColor: Colors.orange, + ), + ); + } + + static void showError(BuildContext context, String message) { + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + content: Text(message), + backgroundColor: Colors.red, + ), + ); + } + + static Future checkForUpdate() async { + if (kIsWeb || kDebugMode || !Platform.isAndroid) { + return; + } + + try { + final info = await InAppUpdate.checkForUpdate(); + if (info.updateAvailability == UpdateAvailability.updateAvailable && + info.immediateUpdateAllowed) { + await InAppUpdate.performImmediateUpdate(); + } + } catch (e, st) { + debugPrintStack( + label: e.toString(), + stackTrace: st, + ); + // TODO: Do something with this error + } + } } diff --git a/lib/widgets/base_tab.dart b/lib/widgets/base_tab.dart index 913019c..e06b6bf 100644 --- a/lib/widgets/base_tab.dart +++ b/lib/widgets/base_tab.dart @@ -55,7 +55,7 @@ class _BaseTabState> icon: const Icon(Icons.add), label: const Text('MORE'), onPressed: () { - Utils.showInfo(context, 'Not implemented yet'); + Utils.showWarning(context, 'Not implemented yet'); }, ), ), diff --git a/lib/widgets/posts/post_utils.dart b/lib/widgets/posts/post_utils.dart index 50817b2..41c8691 100644 --- a/lib/widgets/posts/post_utils.dart +++ b/lib/widgets/posts/post_utils.dart @@ -40,7 +40,7 @@ class PostListUtils { ); static Widget buildErrorState(context, String message) { - return Center( + return SingleChildScrollView( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ diff --git a/pubspec.lock b/pubspec.lock index cb7a622..94fc7bc 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -224,6 +224,14 @@ packages: url: "https://pub.dev" source: hosted version: "4.0.17" + in_app_update: + dependency: "direct main" + description: + name: in_app_update + sha256: "22953dfbe317e22f7e860a1790ba86926b208740ddd5b6b487ed430a360a9e4a" + url: "https://pub.dev" + source: hosted + version: "4.1.3" intl: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 09cbbce..e9d0b79 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -11,7 +11,7 @@ description: A new Flutter project. # In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion. # Read more about iOS versioning at # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html -version: 1.0.0+2 +version: 1.0.1+3 environment: sdk: '>=3.0.1 <4.0.0' @@ -29,6 +29,7 @@ dependencies: flutter_markdown: ^0.6.15 shared_preferences: ^2.1.2 qr_flutter: ^4.1.0 + in_app_update: ^4.1.3 dev_dependencies: flutter_test: