game_run.dart 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import 'dart:io';
  2. import 'package:device_apps/device_apps.dart' as app;
  3. import 'package:android_intent/android_intent.dart';
  4. import 'package:android_intent/flag.dart';
  5. import 'package:flutter/material.dart';
  6. import 'package:sport/utils/toast.dart';
  7. import 'package:sport/widgets/button_primary.dart';
  8. Future startRun(BuildContext context) async {
  9. var package = "com.ouj.hiyd";
  10. var componentName = "com.ouj.hiyd.SplashActivity_";
  11. if (Platform.isAndroid) {
  12. var sport = await app.DeviceApps.getApp(package);
  13. if(sport == null) {
  14. ToastUtil.show("你还没安装 Hi运动 app");
  15. return;
  16. }
  17. AndroidIntent intent = AndroidIntent(
  18. action: "android.intent.action.MAIN",
  19. package: package,
  20. componentName: componentName,
  21. flags: [
  22. Flag.FLAG_ACTIVITY_NEW_TASK
  23. ],
  24. arguments: {
  25. });
  26. intent.launch();
  27. }
  28. }
  29. class GameRun extends StatelessWidget {
  30. @override
  31. Widget build(BuildContext context) {
  32. return GestureDetector(
  33. behavior: HitTestBehavior.opaque,
  34. onTap: () {},
  35. child: Row(
  36. children: <Widget>[
  37. Container(
  38. width: 50.0,
  39. height: 50.0,
  40. margin: const EdgeInsets.all(12.0),
  41. child: Image.asset("lib/assets/img/home_game_run.png"),
  42. ),
  43. Expanded(
  44. child: Column(
  45. crossAxisAlignment: CrossAxisAlignment.start,
  46. children: <Widget>[
  47. Text(
  48. "跑步训练",
  49. style: Theme.of(context).textTheme.subtitle1.copyWith(fontSize: 16.0, fontWeight: FontWeight.w600),
  50. ),
  51. SizedBox(
  52. height: 3,
  53. ),
  54. Text("125514人在练", style: Theme.of(context).textTheme.bodyText1, maxLines: 1),
  55. SizedBox(
  56. height: 6,
  57. )
  58. ],
  59. ),
  60. ),
  61. Padding(
  62. padding: const EdgeInsets.all(12.0),
  63. child: PrimaryButton(
  64. width: 93,
  65. height: 35,
  66. content: "开始跑步",
  67. callback: () {
  68. startRun(context);
  69. },
  70. ),
  71. )
  72. ],
  73. ),
  74. );
  75. }
  76. }