From cc0139a85c6fa8a340952b1e8d2867434bb386a3 Mon Sep 17 00:00:00 2001 From: open-trade Date: Tue, 17 Nov 2020 12:08:31 +0800 Subject: [PATCH] seems timer not work well, will try https://github.com/hanxu317317/flutter_plan_demo/blob/master/lib/src/enter.dart --- flutter_hbb/lib/main.dart | 3 +-- flutter_hbb/lib/remote_page.dart | 32 ++++++++++++++++++++++++++++---- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/flutter_hbb/lib/main.dart b/flutter_hbb/lib/main.dart index f2993d410..de0f03e07 100644 --- a/flutter_hbb/lib/main.dart +++ b/flutter_hbb/lib/main.dart @@ -2,7 +2,6 @@ import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; import 'common.dart'; import 'home_page.dart'; -import 'package:flutter_easyloading/flutter_easyloading.dart'; void main() { runApp(App()); @@ -20,7 +19,7 @@ class App extends StatelessWidget { primarySwatch: Colors.blue, visualDensity: VisualDensity.adaptivePlatformDensity, ), - home: FlutterEasyLoading(child: HomePage(title: 'RustDesk')), + home: HomePage(title: 'RustDesk'), )); } } diff --git a/flutter_hbb/lib/remote_page.dart b/flutter_hbb/lib/remote_page.dart index d110cd21f..e3004690d 100644 --- a/flutter_hbb/lib/remote_page.dart +++ b/flutter_hbb/lib/remote_page.dart @@ -2,6 +2,8 @@ import 'package:flutter/material.dart'; import 'common.dart'; import 'package:flutter/services.dart'; import 'dart:ui' as ui; +import 'package:flutter_easyloading/flutter_easyloading.dart'; +import 'dart:async'; class RemotePage extends StatefulWidget { RemotePage({Key key, this.id}) : super(key: key); @@ -12,20 +14,42 @@ class RemotePage extends StatefulWidget { _RemotePageState createState() => _RemotePageState(); } +// https://github.com/hanxu317317/flutter_plan_demo/blob/master/lib/src/enter.dart class _RemotePageState extends State { + Timer _interval; + @override void initState() { super.initState(); FFI.connect(widget.id); + WidgetsBinding.instance.addPostFrameCallback((_) { + showLoading("Connecting..."); + _interval = + Timer.periodic(Duration(milliseconds: 30), (timer) => interval()); + }); + } + + @override + void dispose() { + super.dispose(); + _interval.cancel(); + dismissLoading(); + FFI.close(); + } + + void interval() { + print(1); } @override Widget build(BuildContext context) { + // Size size = MediaQueryData.fromWindow(ui.window).size; // https://stackoverflow.com/questions/46640116/make-flutter-application-fullscreen SystemChrome.setEnabledSystemUIOverlays([]); - return CustomPaint( + return FlutterEasyLoading( + child: CustomPaint( painter: new ImageEditor(image: null), - ); + )); } } @@ -38,12 +62,12 @@ class ImageEditor extends CustomPainter { @override void paint(Canvas canvas, Size size) { - if (image = null) return; + if (image == null) return; canvas.drawImage(image, new Offset(0.0, 0.0), new Paint()); } @override bool shouldRepaint(CustomPainter oldDelegate) { - return false; + return oldDelegate != this; } }