Skip to content

Commit

Permalink
Huawei app gallery example updated
Browse files Browse the repository at this point in the history
  • Loading branch information
Shakila147 committed Sep 25, 2024
1 parent 39167f3 commit 0a2721e
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 2 deletions.
4 changes: 2 additions & 2 deletions example/android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
buildscript {
ext.kotlin_version = '1.6.10'
ext.kotlin_version = '1.8.21'
repositories {
google()
jcenter()
}

dependencies {
classpath 'com.android.tools.build:gradle:7.1.2'
classpath 'com.android.tools.build:gradle:7.3.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
Expand Down
74 changes: 74 additions & 0 deletions example/lib/main_huawei_app_gallery.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* Copyright (c) 2019-2024 Larry Aasen. All rights reserved.
*/

import 'package:flutter/material.dart';
import 'package:huawei_hmsavailability/huawei_hmsavailability.dart';
import 'package:upgrader/upgrader.dart';

//Add Your App id , clientId , clientSecret to Your Env file
String appId = "your_app_id";
String clientId = "your_client_id";
String clientSecret = "your_client_secret";

void main() async {
WidgetsFlutterBinding.ensureInitialized();
HmsApiAvailability client = HmsApiAvailability();

// 0: HMS Core (APK) is available.
// 1: No HMS Core (APK) is found on device.
// 2: HMS Core (APK) installed is out of date.
// 3: HMS Core (APK) installed on the device is unavailable.
// 9: HMS Core (APK) installed on the device is not the official version.
// 21: The device is too old to support HMS Core (APK).
int status = await client.isHMSAvailable();

// Clear any saved settings for testing purposes (REMOVE this line in production).
await Upgrader.clearSavedSettings(); // REMOVE this for release builds

// Start the app with the appropriate store controller based on Google Play availability.
runApp(MyApp(
isHuawei: status == 0, //change this as your need
));
}

class MyApp extends StatelessWidget {
final bool isHuawei;
const MyApp({
super.key,
required this.isHuawei,
});

@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Upgrader Huawei Example',
home: UpgradeAlert(
upgrader: Upgrader(
storeController: UpgraderStoreController(
onAndroid: () {
// If Google Play Services are unavailable, use Huawei AppGallery.
if (isHuawei) {
return UpgraderHuaweiStore(
appId: appId,
clientId: clientId,
clientSecret: clientSecret,
);
}
// Otherwise, default to Google Play Store.
return UpgraderPlayStore();
},
),
),
child: Scaffold(
appBar: AppBar(
title: const Text('Upgrader Huawei Example'),
),
body: const Center(
child: Text('Checking for updates...'),
),
),
),
);
}
}
1 change: 1 addition & 0 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ dependencies:

go_router: ^7.1.1
http: ^1.2.2
huawei_hmsavailability: ^6.12.0+300
path: ^1.9.0

upgrader:
Expand Down

0 comments on commit 0a2721e

Please sign in to comment.