kidd3166 3 yıl önce
ebeveyn
işleme
c8e2f5f845
2 değiştirilmiş dosya ile 35 ekleme ve 13 silme
  1. 6 1
      lib/pages/home/home_info_page.dart
  2. 29 12
      lib/widgets/game_run.dart

+ 6 - 1
lib/pages/home/home_info_page.dart

@@ -36,6 +36,7 @@ import 'package:sport/widgets/decoration.dart';
 import 'package:sport/widgets/dialog/search_device.dart';
 import 'package:sport/widgets/dialog/share_popup.dart';
 import 'package:sport/widgets/error.dart';
+import 'package:sport/widgets/game_run.dart';
 import 'package:sport/widgets/image.dart';
 import 'package:sport/widgets/loading.dart';
 import 'package:sport/widgets/misc.dart';
@@ -891,7 +892,11 @@ class _PageState extends ViewStateLifecycle<HomeInfoPage, SportIndexModel> with
                     width: 72,
                     height: 35,
                     content: type == 0 ? "跑步" : "继续",
-                    callback: type == 0 ? () {} : () => startGame(context, game),
+                    callback: type == 0
+                        ? () {
+                            startRun(context);
+                          }
+                        : () => startGame(context, game),
                   )
                 ],
               ),

+ 29 - 12
lib/widgets/game_run.dart

@@ -1,8 +1,36 @@
+import 'dart:io';
+import 'package:device_apps/device_apps.dart' as app;
 import 'package:android_intent/android_intent.dart';
 import 'package:android_intent/flag.dart';
 import 'package:flutter/material.dart';
+import 'package:sport/utils/toast.dart';
 import 'package:sport/widgets/button_primary.dart';
 
+
+Future startRun(BuildContext context) async {
+  var package = "com.ouj.hiyd";
+  var componentName = "com.ouj.hiyd.SplashActivity_";
+
+  if (Platform.isAndroid) {
+    var sport = await app.DeviceApps.getApp(package);
+    if(sport == null) {
+      ToastUtil.show("你还没安装 Hi运动 app");
+      return;
+    }
+    AndroidIntent intent = AndroidIntent(
+        action: "android.intent.action.MAIN",
+        package: package,
+        componentName: componentName,
+        flags: [
+          Flag.FLAG_ACTIVITY_NEW_TASK
+        ],
+        arguments: {
+
+        });
+    intent.launch();
+  }
+}
+
 class GameRun extends StatelessWidget {
   @override
   Widget build(BuildContext context) {
@@ -42,18 +70,7 @@ class GameRun extends StatelessWidget {
               height: 35,
               content: "开始跑步",
               callback: () {
-                AndroidIntent intent = AndroidIntent(
-                    action: "android.intent.action.MAIN",
-                    package: "com.ouj.hiyd",
-                    componentName: "com.ouj.hiyd.SplashActivity_",
-                    // data: "oujgame://com.ouj.shoe",
-                    flags: [
-                      Flag.FLAG_ACTIVITY_NEW_TASK
-                    ],
-                    arguments: {
-
-                    });
-                intent.launch();
+                startRun(context);
               },
             ),
           )