diff --git a/example/lib/main.dart b/example/lib/main.dart index 123db8d..2b1aaeb 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -57,6 +57,7 @@ class _MyHomePageState extends State with TickerProviderStateMixin { @override Widget build(BuildContext context) { + print(Theme.of(context).textTheme.headline1.fontFamily); return ASScaffold( leading: navigator.canPop() ? IconButton( diff --git a/example/lib/widgets/example_picker.dart b/example/lib/widgets/example_picker.dart index aba8c46..2d249cf 100644 --- a/example/lib/widgets/example_picker.dart +++ b/example/lib/widgets/example_picker.dart @@ -90,6 +90,16 @@ class _ExamplePickerState extends State { }, ), ), + ListTile( + title: Text('图片选择器'), + subtitle: Text('ImagePicker'), + trailing: ASButton( + title: '图片选择器', + onPressed: () async { + File file = await pickImageFile(); + }, + ), + ), // END ], ), diff --git a/lib/ansu_ui.dart b/lib/ansu_ui.dart index eaf9d47..202bfc0 100644 --- a/lib/ansu_ui.dart +++ b/lib/ansu_ui.dart @@ -9,6 +9,7 @@ export 'buttons/as_bottom_button.dart'; export 'buttons/as_gradient_button.dart'; export 'buttons/as_radio_button.dart'; export 'buttons/as_material_button.dart'; +export 'buttons/as_check_button.dart'; //scaffold export 'scaffold/as_scaffold.dart'; @@ -70,6 +71,8 @@ export 'extension/widget_extension.dart'; export 'extension/string_extension.dart'; export 'extension/text_style_extension.dart'; export 'extension/image_extension.dart'; -export 'package:velocity_x/velocity_x.dart'; export 'theme/as_theme.dart'; + +//third party +export 'package:velocity_x/velocity_x.dart'; diff --git a/lib/bar/as_tabbar.dart b/lib/bar/as_tabbar.dart index 06056e6..73cc5a8 100644 --- a/lib/bar/as_tabbar.dart +++ b/lib/bar/as_tabbar.dart @@ -21,12 +21,15 @@ class ASTabBar extends StatelessWidget implements PreferredSizeWidget { ///可滚动 final bool isScrollable; - ASTabBar( - {Key? key, - required this.items, - required this.controller, - this.isScrollable = false}) - : tabItems = null, + + final ValueChanged? onTap; + ASTabBar({ + Key? key, + required this.items, + required this.controller, + this.isScrollable = false, + this.onTap, + }) : tabItems = null, super(key: key); /// ## TabBar with tag @@ -41,12 +44,13 @@ class ASTabBar extends StatelessWidget implements PreferredSizeWidget { /// ) ///``` /// - ASTabBar.tag( - {Key? key, - required this.tabItems, - required this.controller, - this.isScrollable = false}) - : items = null, + ASTabBar.tag({ + Key? key, + required this.tabItems, + required this.controller, + this.isScrollable = false, + this.onTap, + }) : items = null, super(key: key); bool get isTag => items?.isEmpty ?? true; @@ -57,6 +61,7 @@ class ASTabBar extends StatelessWidget implements PreferredSizeWidget { child: TabBar( isScrollable: isScrollable, controller: controller, + onTap: onTap, tabs: isTag ? tabItems!.map((e) { return Tab( diff --git a/lib/buttons/as_back_button.dart b/lib/buttons/as_back_button.dart index 5731fc4..b49967e 100644 --- a/lib/buttons/as_back_button.dart +++ b/lib/buttons/as_back_button.dart @@ -24,7 +24,11 @@ class ASBackButton extends StatelessWidget { size: 24, color: color, ), - onPressed: () => Navigator.pop(context), + onPressed: () { + if (Navigator.canPop(context)) { + Navigator.pop(context); + } + }, ) : SizedBox(); } diff --git a/lib/buttons/as_check_button.dart b/lib/buttons/as_check_button.dart new file mode 100644 index 0000000..ed8fda0 --- /dev/null +++ b/lib/buttons/as_check_button.dart @@ -0,0 +1,36 @@ +import 'package:ansu_ui/styles/as_colors.dart'; +import 'package:flutter_screenutil/flutter_screenutil.dart'; +import 'package:flutter/material.dart'; + +class ASCheckButton extends StatelessWidget { + final T object; + final bool checked; + final VoidCallback onTap; + + final String title; + const ASCheckButton({ + Key? key, + required this.object, + required this.onTap, + this.checked = false, + required this.title, + }) : super(key: key); + + @override + Widget build(BuildContext context) { + return MaterialButton( + materialTapTargetSize: MaterialTapTargetSize.shrinkWrap, + height: 31.w, + onPressed: onTap, + shape: StadiumBorder(), + color: checked ? kPrimaryColor : Color(0xFFF2F2F2), + elevation: 0, + child: Text( + title, + style: TextStyle( + color: checked ? kLightTextColor : kTextColor, + ), + ), + ); + } +} diff --git a/lib/dialog/as_bottom_dialog_item.dart b/lib/dialog/as_bottom_dialog_item.dart index 5561fb8..833cc91 100644 --- a/lib/dialog/as_bottom_dialog_item.dart +++ b/lib/dialog/as_bottom_dialog_item.dart @@ -17,7 +17,6 @@ class ASBottomDialogItem extends StatelessWidget { height: 48.w, color: kForegroundColor, onPressed: () { - Navigator.pop(context); onPressed!(); }, child: DefaultTextStyle( diff --git a/lib/list_tile/as_edit_tile.dart b/lib/list_tile/as_edit_tile.dart index 339d128..7f5dc1c 100644 --- a/lib/list_tile/as_edit_tile.dart +++ b/lib/list_tile/as_edit_tile.dart @@ -5,67 +5,62 @@ import 'package:ansu_ui/extension/num_extension.dart'; class ASEditTile extends StatelessWidget { final Widget? title; - final FocusNode? node; final String? hintText; + final Widget? prefix; final TextEditingController? controller; + final Function(String text)? onChange; + final Function(String text)? onSubmitted; ASEditTile({ Key? key, this.title, - this.node, this.hintText, this.controller, + this.prefix, + this.onChange, + this.onSubmitted, }) : super(key: key); - - final FocusNode? _node = FocusNode(); @override Widget build(BuildContext context) { - return GestureDetector( - onTap: () { - if (node != null) { - node?.requestFocus(); - } else { - _node?.requestFocus(); - } - }, - child: ConstrainedBox( - constraints: BoxConstraints(minHeight: 46.w), - child: Row( - children: [ - 10.wb, - InkWell( - child: DefaultTextStyle( - style: TextStyle( - color: Colors.black.withOpacity(0.65), - fontSize: 14.sp, - ), - child: title ?? Text(''), + return ConstrainedBox( + constraints: BoxConstraints(minHeight: 46.w), + child: Row( + children: [ + 10.wb, + InkWell( + child: DefaultTextStyle( + style: TextStyle( + color: Colors.black.withOpacity(0.65), + fontSize: 14.sp, ), + child: title ?? Text(''), ), - Expanded( - child: TextField( - focusNode: node ?? _node, - controller: controller, - textAlign: TextAlign.end, - style: TextStyle( + ), + prefix ?? SizedBox(), + Expanded( + child: TextField( + controller: controller, + onChanged: onChange, + onSubmitted: onSubmitted, + textAlign: TextAlign.end, + style: TextStyle( + fontSize: 14.sp, + color: kTextColor, + fontWeight: FontWeight.bold, + ), + decoration: InputDecoration( + border: InputBorder.none, + isDense: true, + contentPadding: EdgeInsets.zero, + hintText: hintText, + hintStyle: TextStyle( + color: kTextSubColor, fontSize: 14.sp, - color: kTextColor, - fontWeight: FontWeight.bold, - ), - decoration: InputDecoration( - border: InputBorder.none, - isDense: true, - contentPadding: EdgeInsets.zero, - hintText: hintText, - hintStyle: TextStyle( - color: kTextSubColor, - fontSize: 14.sp, - ), ), ), ), - 10.wb, - ], - ), + ), + 10.wb, + ], ), ); } diff --git a/lib/theme/as_theme.dart b/lib/theme/as_theme.dart index 435c9da..c3e470a 100644 --- a/lib/theme/as_theme.dart +++ b/lib/theme/as_theme.dart @@ -9,15 +9,22 @@ class ASTheme { } static SystemUiOverlayStyle get defaultSystemStyle => SystemUiOverlayStyle( - systemNavigationBarColor: Colors.white, + systemNavigationBarColor: kBackgroundColor, statusBarColor: Colors.transparent, statusBarIconBrightness: Brightness.light, statusBarBrightness: Brightness.light, ); + static SystemUiOverlayStyle get yellow => + defaultSystemStyle.copyWith(systemNavigationBarColor: kPrimaryColor); + static ThemeData get lightTheme => ThemeData(primarySwatch: Colors.yellow).copyWith( - textTheme: TextTheme().apply(displayColor: Color(0xFF333333)), + textTheme: ThemeData.light().textTheme.apply( + displayColor: Color(0xFF333333), + bodyColor: Color(0xFF333333), + ), + inputDecorationTheme: InputDecorationTheme(), primaryColor: kPrimaryColor, textButtonTheme: TextButtonThemeData( style: ButtonStyle( diff --git a/lib/utils/camera_util.dart b/lib/utils/camera_util.dart index 09f9d8d..fb8ca0f 100644 --- a/lib/utils/camera_util.dart +++ b/lib/utils/camera_util.dart @@ -1,9 +1,42 @@ import 'dart:io'; +import 'package:ansu_ui/dialog/as_bottom_dialog.dart'; +import 'package:ansu_ui/dialog/as_bottom_dialog_item.dart'; import 'package:flutter/material.dart'; +import 'package:get/get.dart'; import 'package:image_picker/image_picker.dart'; import 'package:ansu_ui/utils/camera_view.dart'; +Future pickImageFile( + {double maxHeight = 3000, double maxWidth = 3000}) async { + File? file = await Get.bottomSheet(ASBottomDialog( + items: [ + ASBottomDialogItem( + title: Text('相机'), + onPressed: () async { + Get.back(result: await camFile()); + }, + ), + ASBottomDialogItem( + title: Text('相册'), + onPressed: () async { + var pickedFile = await ImagePicker().getImage( + source: ImageSource.gallery, + maxHeight: maxHeight, + maxWidth: maxWidth, + ); + if (pickedFile != null) { + Get.back(result: File(pickedFile.path)); + } else { + Get.back(); + } + }, + ), + ], + )); + return file; +} + ///获取相机文件 Future camFile({double maxHeight = 3000, double maxWidth = 3000}) async { var pickedFile = await ImagePicker().getImage( diff --git a/pubspec.yaml b/pubspec.yaml index b680946..3ee9f9e 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -4,7 +4,7 @@ version: 0.0.4 author: environment: - sdk: '>=2.12.0 <3.0.0' + sdk: ">=2.12.0 <3.0.0" flutter: ">=1.17.0" dependencies: @@ -25,4 +25,3 @@ dependencies: dev_dependencies: flutter_test: sdk: flutter -flutter: