| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- import 'dart:async';
- import 'package:flutter/material.dart';
- import 'package:get/get.dart';
- import 'package:trackoffical_app/logger.dart';
- import 'package:trackoffical_app/pb.dart' as pb;
- import 'package:trackoffical_app/service/app.dart';
- import 'package:trackoffical_app/widget/will_exit_after_2_back.dart';
- import '../styles/theme.dart';
- class AppUpdateController extends GetxController {
- final downloadProcess = 0.0.obs;
- Timer? _ticker;
- @override
- void onReady() {
- var arg = Get.arguments;
- if (arg is pb.GetUpdateVersionReply){
- App.to.updateApp(arg).then((value){
- info('下载完成');
- }, onError: (e){
- warn('安装失败:', e);
- });
- }
- _ticker = Timer.periodic(100.milliseconds, (timer) {
- App.to.getUpdateAppProcess().then((value) => downloadProcess.value = value);
- });
- }
- @override
- void onClose(){
- _ticker?.cancel();
- }
- }
- class AppUpdateView extends GetView<AppUpdateController> {
- final pb.GetUpdateVersionReply data;
- const AppUpdateView(this.data, {super.key});
- static Bindings bindings() {
- return BindingsBuilder(() {
- Get.put<AppUpdateController>(AppUpdateController());
- });
- }
- static void show(pb.GetUpdateVersionReply updateInfo) {
- Get.offAll(
- AppUpdateView(updateInfo),
- binding: AppUpdateView.bindings(),
- arguments: updateInfo
- );
- }
- @override
- Widget build(BuildContext context) {
- return WillExitAfter2Back(child: Scaffold(
- body: Container(
- width: double.infinity,
- height: double.infinity,
- padding: const EdgeInsets.all(24),
- child: Center(
- child: Column(
- mainAxisSize: MainAxisSize.min,
- children: [
- const SizedBox(height: 100),
- Image.asset('assets/images/sign_in_logo.png', height: 45.77),
- const SizedBox(height: 45.35),
- Image.asset('assets/images/ic_logo_rect.png', height: 54),
- const SizedBox(height: 21),
- Text('小飞龙定向软件升级',
- style: context.textTheme.titleLarge?.copyWith(fontSize: 13, color: const Color(0xffaaaaaa))),
- const SizedBox(height: 24),
- Flexible(
- flex: 1,
- child: Container(
- padding: const EdgeInsets.all(24),
- height: 400,
- width: double.infinity,
- child: SizedBox(
- width: double.infinity,
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- const Text('更新内容:'),
- Text(data.vMemo)
- ],
- ) ,
- ) ,
- ),
- ),
- const SizedBox(height: 24),
- SizedBox(
- height: 17.42,
- child: ClipRRect(
- borderRadius: const BorderRadius.all(Radius.circular(8.71)),
- child: Obx(() => LinearProgressIndicator(
- value: controller.downloadProcess.value),
- ) )
- ),
- const SizedBox(height: 100)
- ],
- ),
- ),
- ),
- )) ;
- }
- }
- void main() async {
- var c = AppUpdateController();
- c.downloadProcess.value = 0.5;
- Get.put(c);
- runApp(GetMaterialApp(
- theme: appThemeData(),
- home: AppUpdateView(pb.GetUpdateVersionReply()..vMemo= "更新内容")));
- }
|