Skip to content

Commit

Permalink
1.0.1+3: In app update (Google Play)
Browse files Browse the repository at this point in the history
  • Loading branch information
felipebueno committed Jun 19, 2023
1 parent 7d36591 commit 984041c
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 7 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
buildscript {
ext.kotlin_version = '1.7.10'
ext.kotlin_version = '1.8.22'
repositories {
google()
mavenCentral()
Expand All @@ -26,6 +26,6 @@ subprojects {
project.evaluationDependsOn(':app')
}

tasks.register("clean", Delete) {
tasks.register('clean', Delete) {
delete rootProject.buildDir
}
2 changes: 2 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -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());
}

Expand Down
42 changes: 42 additions & 0 deletions lib/utils.dart
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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<void> 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
}
}
}
2 changes: 1 addition & 1 deletion lib/widgets/base_tab.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class _BaseTabState<TBloc extends Bloc<dynamic, dynamic>>
icon: const Icon(Icons.add),
label: const Text('MORE'),
onPressed: () {
Utils.showInfo(context, 'Not implemented yet');
Utils.showWarning(context, 'Not implemented yet');
},
),
),
Expand Down
2 changes: 1 addition & 1 deletion lib/widgets/posts/post_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class PostListUtils {
);

static Widget buildErrorState(context, String message) {
return Center(
return SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Expand Down
8 changes: 8 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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:
Expand Down

0 comments on commit 984041c

Please sign in to comment.