From 76420edd8aa341ae76de9aa1a3a28d1add5d4db4 Mon Sep 17 00:00:00 2001 From: Caten Date: Sun, 3 Sep 2023 23:16:00 +0800 Subject: [PATCH] Change Page Structure MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修改页面结构,为编写“控制”页面做准备 --- android/gradle.properties | 2 +- lib/main.dart | 93 ++++++++++++------- lib/workflow.dart | 8 +- macos/Flutter/GeneratedPluginRegistrant.swift | 2 - pubspec.lock | 24 ----- pubspec.yaml | 3 +- 6 files changed, 70 insertions(+), 62 deletions(-) diff --git a/android/gradle.properties b/android/gradle.properties index 246fcb7..710351d 100644 --- a/android/gradle.properties +++ b/android/gradle.properties @@ -1,4 +1,4 @@ #org.gradle.jvmargs=-Xmx1536M -org.gradle.jvmargs=-Xmx8192m +org.gradle.jvmargs=-Xmx12288m android.useAndroidX=true android.enableJetifier=true diff --git a/lib/main.dart b/lib/main.dart index e902f6e..9de6457 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -188,34 +188,11 @@ debian系统里预装了WPS, VSCode和fcitx输入法 } } -class MyHomePage extends StatefulWidget { - const MyHomePage({super.key, required this.title}); - - final String title; - - @override - State createState() => _MyHomePageState(); -} - -class _MyHomePageState extends State { - +class LoadingPage extends StatelessWidget { + const LoadingPage({super.key}); @override Widget build(BuildContext context) { - - G.homePageStateContext = context; - - return Scaffold( - appBar: AppBar( - backgroundColor: Theme.of(context).colorScheme.inversePrimary, - title: Text(widget.title), - ), - body: FutureBuilder( - future: Workflow.workflow(), - builder: (BuildContext context, AsyncSnapshot snapshot) { - if (snapshot.connectionState == ConnectionState.done) { - return TerminalView(G.terminal); - } else { - return const Padding( + return const Padding( padding: EdgeInsets.all(8), child: Column( children: [ @@ -246,13 +223,65 @@ class _MyHomePageState extends State { ] ) ); - } - } + } +} + +class MyHomePage extends StatefulWidget { + const MyHomePage({super.key, required this.title}); + + final String title; + + @override + State createState() => _MyHomePageState(); +} + +class _MyHomePageState extends State { + + //安装完成了吗? + //完成后从加载界面切换到主界面 + bool isLoadingComplete = false; + //主界面索引 + int pageIndex = 0; + + @override + Widget build(BuildContext context) { + + G.homePageStateContext = context; + + if (!isLoadingComplete) { + Workflow.workflow().then((value) { + setState(() { + isLoadingComplete = true; + }); + }); + } + + + return Scaffold( + appBar: AppBar( + backgroundColor: Theme.of(context).colorScheme.inversePrimary, + title: Text(widget.title), ), - floatingActionButton: FloatingActionButton( - onPressed: () => Workflow.launchBrowser(), - tooltip: 'Increment', - child: const Icon(Icons.play_arrow), + body: isLoadingComplete?TerminalView(G.terminal):const LoadingPage(), + bottomNavigationBar: Visibility(visible: isLoadingComplete, + child: BottomNavigationBar(currentIndex: pageIndex, + onTap: (index) { + setState(() { + pageIndex = index; + }); + }, + items: const [ + BottomNavigationBarItem(icon: Icon(Icons.monitor), label: "终端"), + BottomNavigationBarItem(icon: Icon(Icons.video_settings), label: "控制"), + ], + ) + ), + floatingActionButton: Visibility(visible: isLoadingComplete && (pageIndex == 0), + child: FloatingActionButton( + onPressed: () => Workflow.launchBrowser(), + tooltip: "进入图形界面", + child: const Icon(Icons.play_arrow), + ), ), // This trailing comma makes auto-formatting nicer for build methods. ); } diff --git a/lib/workflow.dart b/lib/workflow.dart index 245c6b6..0eca640 100644 --- a/lib/workflow.dart +++ b/lib/workflow.dart @@ -33,6 +33,8 @@ import 'package:flutter_pty/flutter_pty.dart'; import 'package:path_provider/path_provider.dart'; import 'package:permission_handler/permission_handler.dart'; +import 'package:shared_preferences/shared_preferences.dart'; + class Util { static bool isFirstTime() { return (! Directory("${G.dataPath}/bin").existsSync()) || File("${G.dataPath}/xao").existsSync(); @@ -70,6 +72,9 @@ class G { static late WebViewController controller; static late BuildContext homePageStateContext; + static late SharedPreferences prefs; + + static const String vncUrl = "http://localhost:36080/vnc.html?host=localhost&port=36080&autoconnect=true&resize=remote"; } @@ -81,7 +86,8 @@ class Workflow { } static Future initData() async { - + + G.prefs = await SharedPreferences.getInstance(); } diff --git a/macos/Flutter/GeneratedPluginRegistrant.swift b/macos/Flutter/GeneratedPluginRegistrant.swift index d9c9036..b19945c 100644 --- a/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/macos/Flutter/GeneratedPluginRegistrant.swift @@ -5,13 +5,11 @@ import FlutterMacOS import Foundation -import device_info_plus import path_provider_foundation import shared_preferences_foundation import url_launcher_macos func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { - DeviceInfoPlusMacosPlugin.register(with: registry.registrar(forPlugin: "DeviceInfoPlusMacosPlugin")) PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin")) SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin")) UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin")) diff --git a/pubspec.lock b/pubspec.lock index 509dcf9..ef4202c 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -49,22 +49,6 @@ packages: url: "https://pub.dev" source: hosted version: "3.1.1" - device_info_plus: - dependency: "direct main" - description: - name: device_info_plus - sha256: "86add5ef97215562d2e090535b0a16f197902b10c369c558a100e74ea06e8659" - url: "https://pub.dev" - source: hosted - version: "9.0.3" - device_info_plus_platform_interface: - dependency: transitive - description: - name: device_info_plus_platform_interface - sha256: d3b01d5868b50ae571cd1dc6e502fc94d956b665756180f7b16ead09e836fd64 - url: "https://pub.dev" - source: hosted - version: "7.0.0" equatable: dependency: transitive description: @@ -549,14 +533,6 @@ packages: url: "https://pub.dev" source: hosted version: "5.0.7" - win32_registry: - dependency: transitive - description: - name: win32_registry - sha256: e4506d60b7244251bc59df15656a3093501c37fb5af02105a944d73eb95be4c9 - url: "https://pub.dev" - source: hosted - version: "1.1.1" xdg_directories: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 7aebdb4..9835618 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -16,7 +16,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html # In Windows, build-name is used as the major, minor, and patch parts # of the product and file versions while build-number is used as the build suffix. -version: 1.0.1+1 +version: 1.0.2+1 environment: sdk: '>=3.1.0 <4.0.0' @@ -38,7 +38,6 @@ dependencies: http: ^1.1.0 retry: ^3.1.2 url_launcher: ^6.1.12 - device_info_plus: ^9.0.3 shared_preferences: ^2.2.1