From e403b62ec0b6a1dae9fd42074960ae3ef49aa094 Mon Sep 17 00:00:00 2001 From: laiiihz Date: Mon, 8 Mar 2021 17:34:18 +0800 Subject: [PATCH] fix color issue --- example/pubspec.lock | 7 ++ lib/src/power_logger_view.dart | 102 +++++++++++++++------------- lib/src/view/dio_response_view.dart | 1 - lib/src/views/info_view.dart | 90 +++++++++++------------- pubspec.lock | 7 ++ pubspec.yaml | 1 + 6 files changed, 109 insertions(+), 99 deletions(-) diff --git a/example/pubspec.lock b/example/pubspec.lock index b69be84..12ad2af 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -8,6 +8,13 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "2.5.0-nullsafety.1" + auto_size_text: + dependency: transitive + description: + name: auto_size_text + url: "https://pub.flutter-io.cn" + source: hosted + version: "2.1.0" boolean_selector: dependency: transitive description: diff --git a/lib/src/power_logger_view.dart b/lib/src/power_logger_view.dart index dd1207f..f505e04 100644 --- a/lib/src/power_logger_view.dart +++ b/lib/src/power_logger_view.dart @@ -18,55 +18,59 @@ class _PowerLoggerViewState extends State { void Function(void Function()) _setState; @override Widget build(BuildContext context) { - return Scaffold( - appBar: AppBar( - title: Text('Logger View'), - actions: [ - IconButton( - icon: Icon(Icons.clear_all_rounded), - onPressed: () { - LoggerData.clear(); - setState(() {}); - }, - ), - ], - ), - body: PageView( - controller: _pageController, - onPageChanged: (index) { - _currentIndex = index; - if (_setState != null) _setState(() {}); - }, - children: [ - LoggerView(), - InfoView(), - SettingsView(), - ], - ), - bottomNavigationBar: StatefulBuilder( - builder: (context, kSetState) { - _setState = kSetState; - return BottomNavigationBar( - currentIndex: _currentIndex, - backgroundColor: Colors.white, - onTap: (index) { - _currentIndex = index; - kSetState(() {}); - _pageController.animateToPage( - index, - duration: Duration(milliseconds: 300), - curve: Curves.easeInOutCubic, - ); - }, - items: [ - BottomNavigationBarItem( - icon: Icon(Icons.assessment), label: '日志'), - BottomNavigationBarItem( - icon: Icon(Icons.perm_device_information), label: '信息'), - BottomNavigationBarItem(icon: Icon(Icons.settings), label: '设置'), - ], - ); - }, + return Theme( + data: ThemeData.light(), + child: Scaffold( + appBar: AppBar( + title: Text('Logger View'), + actions: [ + IconButton( + icon: Icon(Icons.clear_all_rounded), + onPressed: () { + LoggerData.clear(); + setState(() {}); + }, + ), + ], + ), + body: PageView( + controller: _pageController, + onPageChanged: (index) { + _currentIndex = index; + if (_setState != null) _setState(() {}); + }, + children: [ + LoggerView(), + InfoView(), + SettingsView(), + ], + ), + bottomNavigationBar: StatefulBuilder( + builder: (context, kSetState) { + _setState = kSetState; + return BottomNavigationBar( + currentIndex: _currentIndex, + backgroundColor: Colors.white, + onTap: (index) { + _currentIndex = index; + kSetState(() {}); + _pageController.animateToPage( + index, + duration: Duration(milliseconds: 300), + curve: Curves.easeInOutCubic, + ); + }, + items: [ + BottomNavigationBarItem( + icon: Icon(Icons.assessment), label: '日志'), + BottomNavigationBarItem( + icon: Icon(Icons.perm_device_information), label: '信息'), + BottomNavigationBarItem( + icon: Icon(Icons.settings), label: '设置'), + ], + ); + }, + ), ), ); } diff --git a/lib/src/view/dio_response_view.dart b/lib/src/view/dio_response_view.dart index 477a15d..721c9b6 100644 --- a/lib/src/view/dio_response_view.dart +++ b/lib/src/view/dio_response_view.dart @@ -1,6 +1,5 @@ import 'dart:convert'; import 'dart:io'; -import 'dart:typed_data'; import 'package:dio/dio.dart'; import 'package:flutter/material.dart'; diff --git a/lib/src/views/info_view.dart b/lib/src/views/info_view.dart index 5a464f7..97af09a 100644 --- a/lib/src/views/info_view.dart +++ b/lib/src/views/info_view.dart @@ -1,5 +1,6 @@ import 'dart:io'; +import 'package:auto_size_text/auto_size_text.dart'; import 'package:device_info/device_info.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; @@ -30,57 +31,39 @@ class _InfoViewState extends State packageInfo != null && (androidInfo != null || iosInfo != null); _buildGridItem(String title, String subTitle) { - return CupertinoContextMenu( - actions: [ - CupertinoContextMenuAction( - child: Text('复制'), - onPressed: () { - Clipboard.setData(ClipboardData(text: subTitle)); - Navigator.pop(context); - }, - ), - ], - previewBuilder: (context, animation, child) { - return Material( - borderRadius: BorderRadius.circular(8), - child: Container( - width: MediaQuery.of(context).size.width - 100, - constraints: BoxConstraints(minHeight: 300), - padding: const EdgeInsets.all(8.0), - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.start, - mainAxisSize: MainAxisSize.min, - children: [ - Text(title), - Text( - subTitle, - style: TextStyle(fontSize: 22), - ), - ], - ), + return MaterialButton( + elevation: 2, + onPressed: () {}, + onLongPress: () { + Scaffold.of(context).hideCurrentSnackBar(); + Clipboard.setData(ClipboardData(text: subTitle)); + Scaffold.of(context).showSnackBar(SnackBar( + content: Text('已复制'), + action: SnackBarAction( + label: '确定', + onPressed: () { + Scaffold.of(context).hideCurrentSnackBar(); + }, ), - ); + )); }, - child: Material( - color: Colors.white, + shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(5), - elevation: 3, - child: Padding( - padding: const EdgeInsets.all(8.0), - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text(title), - Text( - subTitle ?? '', - style: TextStyle(fontSize: 22), - maxLines: 2, - overflow: TextOverflow.ellipsis, - ), - ], - ), + ), + color: Theme.of(context).scaffoldBackgroundColor, + child: Padding( + padding: const EdgeInsets.all(8.0), + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text(title), + AutoSizeText( + subTitle ?? '', + style: TextStyle(fontSize: 26), + maxLines: 2, + ), + ], ), ), ); @@ -93,8 +76,17 @@ class _InfoViewState extends State title: Text(title), subtitle: Text(subTitle ?? ''), onLongPress: () { + Scaffold.of(context).hideCurrentSnackBar(); Clipboard.setData(ClipboardData(text: subTitle)); - Scaffold.of(context).showSnackBar(SnackBar(content: Text('已复制'))); + Scaffold.of(context).showSnackBar(SnackBar( + content: Text('已复制'), + action: SnackBarAction( + label: '确定', + onPressed: () { + Scaffold.of(context).hideCurrentSnackBar(); + }, + ), + )); }, ), ); diff --git a/pubspec.lock b/pubspec.lock index 98819d8..8bef622 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -8,6 +8,13 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "2.5.0-nullsafety.1" + auto_size_text: + dependency: "direct main" + description: + name: auto_size_text + url: "https://pub.flutter-io.cn" + source: hosted + version: "2.1.0" boolean_selector: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index dfc3f8b..4c72c88 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -15,6 +15,7 @@ dependencies: flutter_highlight: ^0.6.0 device_info: ^1.0.0 package_info: ^0.4.3+4 + auto_size_text: ^2.1.0 dev_dependencies: flutter_test: