From e61597b3ce170ec0fa2db49a2245c08036fd89f7 Mon Sep 17 00:00:00 2001 From: Thomas <77213338+its-tom@users.noreply.github.com> Date: Sat, 6 May 2023 12:53:32 +0200 Subject: [PATCH] use Material3, changed color selection --- .dart_tool/flutter_gen/gen_l10n/l10n.dart | 2 +- .dart_tool/flutter_gen/gen_l10n/l10n_en.dart | 2 +- android/build.gradle | 2 +- .../gradle/wrapper/gradle-wrapper.properties | 2 +- lib/app.dart | 66 +++----------- lib/core/utils/ui.dart | 1 + lib/l10n/app_en.arb | 2 +- lib/view/page/home.dart | 89 +++++++------------ lib/view/page/server/tab.dart | 2 +- lib/view/page/setting.dart | 4 +- pubspec.lock | 8 +- pubspec.yaml | 8 +- 12 files changed, 67 insertions(+), 121 deletions(-) diff --git a/.dart_tool/flutter_gen/gen_l10n/l10n.dart b/.dart_tool/flutter_gen/gen_l10n/l10n.dart index f25e29ad..d647a84c 100644 --- a/.dart_tool/flutter_gen/gen_l10n/l10n.dart +++ b/.dart_tool/flutter_gen/gen_l10n/l10n.dart @@ -942,7 +942,7 @@ abstract class S { /// No description provided for @setting. /// /// In en, this message translates to: - /// **'Setting'** + /// **'Settings'** String get setting; /// No description provided for @sftpDlPrepare. diff --git a/.dart_tool/flutter_gen/gen_l10n/l10n_en.dart b/.dart_tool/flutter_gen/gen_l10n/l10n_en.dart index 2cb8a019..67f0e8fc 100644 --- a/.dart_tool/flutter_gen/gen_l10n/l10n_en.dart +++ b/.dart_tool/flutter_gen/gen_l10n/l10n_en.dart @@ -454,7 +454,7 @@ class SEn extends S { String get serverTabUnkown => 'Unknown state'; @override - String get setting => 'Setting'; + String get setting => 'Settings'; @override String get sftpDlPrepare => 'Preparing to connect...'; diff --git a/android/build.gradle b/android/build.gradle index eb5aaba6..4202c400 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -1,5 +1,5 @@ buildscript { - ext.kotlin_version = '1.6.10' + ext.kotlin_version = '1.8.0' repositories { google() mavenCentral() diff --git a/android/gradle/wrapper/gradle-wrapper.properties b/android/gradle/wrapper/gradle-wrapper.properties index b8793d3c..02e5f581 100644 --- a/android/gradle/wrapper/gradle-wrapper.properties +++ b/android/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-all.zip diff --git a/lib/app.dart b/lib/app.dart index c61f708e..26bf30d9 100644 --- a/lib/app.dart +++ b/lib/app.dart @@ -19,26 +19,6 @@ class MyApp extends StatelessWidget { setTransparentNavigationBar(context); primaryColor = Color(_setting.primaryColor.fetch()!); - final textStyle = TextStyle(color: primaryColor); - final materialColor = primaryColor.materialStateColor; - final materialColorAlpha = primaryColor.withOpacity(0.7).materialStateColor; - final fabTheme = - FloatingActionButtonThemeData(backgroundColor: primaryColor); - final switchTheme = SwitchThemeData( - thumbColor: materialColor, - trackColor: materialColorAlpha, - ); - final appBarTheme = AppBarTheme(backgroundColor: primaryColor); - final iconTheme = IconThemeData(color: primaryColor); - final inputDecorationTheme = InputDecorationTheme( - labelStyle: textStyle, - focusedBorder: UnderlineInputBorder( - borderSide: BorderSide(color: primaryColor), - ), - ); - final radioTheme = RadioThemeData( - fillColor: materialColor, - ); final primarySwatch = primaryColor.materialColor; return ValueListenableBuilder( @@ -47,44 +27,26 @@ class MyApp extends StatelessWidget { final ok = tMode >= 0 && tMode <= ThemeMode.values.length - 1; final themeMode = ok ? ThemeMode.values[tMode] : ThemeMode.system; - final theme = ThemeData( - useMaterial3: false, - primaryColor: primaryColor, - primarySwatch: primarySwatch, - appBarTheme: appBarTheme, - floatingActionButtonTheme: fabTheme, - iconTheme: iconTheme, - primaryIconTheme: iconTheme, - switchTheme: switchTheme, - inputDecorationTheme: inputDecorationTheme, - radioTheme: radioTheme, - ); - final darkTheme = ThemeData( - useMaterial3: false, - primaryColor: primaryColor, - primarySwatch: primarySwatch, - floatingActionButtonTheme: fabTheme, - iconTheme: iconTheme, - primaryIconTheme: iconTheme, - switchTheme: switchTheme, - inputDecorationTheme: inputDecorationTheme, - radioTheme: radioTheme, - brightness: Brightness.dark, - colorScheme: ColorScheme.fromSwatch( - primarySwatch: primaryColor.materialColor, - brightness: Brightness.dark, - accentColor: primaryColor, - ), - ); - return MaterialApp( debugShowCheckedModeBanner: false, localizationsDelegates: S.localizationsDelegates, supportedLocales: S.supportedLocales, title: BuildData.name, themeMode: themeMode, - theme: theme, - darkTheme: darkTheme, + theme: ThemeData.light(useMaterial3: true).copyWith( + colorScheme: ColorScheme.fromSwatch( + primarySwatch: primarySwatch, + accentColor: primaryColor, + ), + switchTheme: ThemeData.light(useMaterial3: true).switchTheme, + ), + darkTheme: ThemeData.dark(useMaterial3: true).copyWith( + colorScheme: ColorScheme.fromSwatch( + brightness: Brightness.dark, + primarySwatch: primarySwatch, + accentColor: primaryColor, + ), + ), home: const MyHomePage(), ); }, diff --git a/lib/core/utils/ui.dart b/lib/core/utils/ui.dart index 6d5b3b9b..0a2c789a 100644 --- a/lib/core/utils/ui.dart +++ b/lib/core/utils/ui.dart @@ -29,6 +29,7 @@ void showSnackBarWithAction(BuildContext context, String content, String action, GestureTapCallback onTap) { ScaffoldMessenger.of(context).showSnackBar(SnackBar( content: Text(content), + behavior: SnackBarBehavior.floating, action: SnackBarAction( label: action, onPressed: onTap, diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index 51ce94b1..73601691 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -140,7 +140,7 @@ "serverTabLoading": "Loading...", "serverTabPlzSave": "Please 'save' this private key again.", "serverTabUnkown": "Unknown state", - "setting": "Setting", + "setting": "Settings", "sftpDlPrepare": "Preparing to connect...", "sftpNoDownloadTask": "No download task.", "sftpSSHConnected": "SFTP Connected", diff --git a/lib/view/page/home.dart b/lib/view/page/home.dart index 99bfa935..1e5933b0 100644 --- a/lib/view/page/home.dart +++ b/lib/view/page/home.dart @@ -110,7 +110,7 @@ class _MyHomePageState extends State return Scaffold( drawer: _buildDrawer(), appBar: AppBar( - title: Text(tabTitleName(context, _selectIndex), style: textSize18), + title: Text(tabTitleName(context, _selectIndex)), actions: [ IconButton( icon: const Icon(Icons.developer_mode, size: 23), @@ -123,68 +123,47 @@ class _MyHomePageState extends State body: PageView( physics: const ClampingScrollPhysics(), controller: _pageController, - onPageChanged: (i) { - FocusScope.of(context).requestFocus(FocusNode()); - _selectIndex = i; - setState(() {}); + onPageChanged: (index) { + setState(() { + _selectIndex = index; + FocusScope.of(context).requestFocus(FocusNode()); + }); }, children: const [ServerPage(), ConvertPage(), PingPage()], ), - bottomNavigationBar: _buildBottom(context), + bottomNavigationBar: _buildBottomBar(context), ); } - Widget _buildBottomItem(int idx, NavigationItem item, bool isSelected) { - final width = _width / tabItems.length; - return AnimatedContainer( - duration: const Duration(milliseconds: 377), - curve: Curves.fastOutSlowIn, - height: 50, - width: isSelected ? width : width - 17, - decoration: BoxDecoration( - color: isSelected - ? _bottomItemOverlayColor.resolve(context) - : Colors.transparent, - borderRadius: const BorderRadius.all( - Radius.circular(50), + Widget _buildBottomBar(BuildContext context){ + return NavigationBar( + selectedIndex: _selectIndex, + animationDuration: const Duration(milliseconds: 250), + onDestinationSelected: (int index) { + setState(() { + _selectIndex = index; + _pageController.animateToPage(index, + duration: const Duration(milliseconds: 677), + curve: Curves.fastLinearToSlowEaseIn); + }); + }, + labelBehavior: NavigationDestinationLabelBehavior.onlyShowSelected, + destinations: const [ + NavigationDestination( + icon: Icon(Icons.cloud_outlined), + label: 'Server', + selectedIcon: Icon(Icons.cloud), ), - ), - child: IconButton( - icon: Icon(item.icon), - tooltip: tabTitleName(context, idx), - splashRadius: width / 3.3, - padding: const EdgeInsets.only(left: 17, right: 17), - onPressed: () { - setState(() { - _pageController.animateToPage(idx, - duration: const Duration(milliseconds: 677), - curve: Curves.fastLinearToSlowEaseIn); - }); - }, - ), - ); - } - - Widget _buildBottom(BuildContext context) { - return SafeArea( - child: Container( - height: 56, - padding: const EdgeInsets.only(left: 8, top: 4, bottom: 4, right: 8), - width: _width, - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceEvenly, - children: tabItems.map( - (item) { - int itemIndex = tabItems.indexOf(item); - return _buildBottomItem( - itemIndex, - item, - _selectIndex == itemIndex, - ); - }, - ).toList(), + NavigationDestination( + icon: Icon(Icons.code), + label: 'Convert', ), - ), + NavigationDestination( + icon: Icon(Icons.leak_add), + label: 'Ping', + selectedIcon: Icon(Icons.leak_add_outlined), + ), + ], ); } diff --git a/lib/view/page/server/tab.dart b/lib/view/page/server/tab.dart index 1eec302c..620c4b2e 100644 --- a/lib/view/page/server/tab.dart +++ b/lib/view/page/server/tab.dart @@ -77,7 +77,7 @@ class _ServerPageState extends State } final keys = pro.servers.keys.toList(); return ListView.separated( - padding: const EdgeInsets.all(7), + padding: const EdgeInsets.fromLTRB(7, 10, 7, 7), controller: ScrollController(), physics: const AlwaysScrollableScrollPhysics(), itemBuilder: (ctx, idx) { diff --git a/lib/view/page/setting.dart b/lib/view/page/setting.dart index b65989af..e08ae230 100644 --- a/lib/view/page/setting.dart +++ b/lib/view/page/setting.dart @@ -243,7 +243,9 @@ class _SettingPageState extends State { Widget _buildAppColorPicker() { return MaterialColorPicker( shrinkWrap: true, - onColorChange: (Color color) { + allowShades: false, + onMainColorChange: (ColorSwatch? color) { + if(color == null) return; _selectedColorValue = color.value; }, selectedColor: primaryColor, diff --git a/pubspec.lock b/pubspec.lock index ed0ed72a..9083888b 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1006,9 +1006,11 @@ packages: xterm: dependency: "direct main" description: - path: "../xterm.dart" - relative: true - source: path + path: "." + ref: master + resolved-ref: "8039a582d855428cec49b23641bcfcafd6682574" + url: "https://github.com/lollipopkit/xterm.dart" + source: git version: "3.4.1" yaml: dependency: transitive diff --git a/pubspec.yaml b/pubspec.yaml index 2f0681f5..845d8bb9 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -57,10 +57,10 @@ dependencies: share_plus_web: ^3.1.0 # xterm: ^3.4.1 xterm: - path: ../xterm.dart - # git: - # ref: master - # url: https://github.com/lollipopkit/xterm.dart + #path: ../xterm.dart + git: + ref: master + url: https://github.com/lollipopkit/xterm.dart file_picker: ^5.2.5 plain_notification_token: ^0.0.4