diff --git a/example/lib/example_button.dart b/example/lib/example_button.dart index ad2d00d..ea64db4 100644 --- a/example/lib/example_button.dart +++ b/example/lib/example_button.dart @@ -50,7 +50,7 @@ class _ExampleButtonState extends State { title: '立即下单', onPressed: () {}, )), - ListTile( + ListTile( title: Text('order'), subtitle: Text('null function'), trailing: ASButton.order( @@ -84,11 +84,9 @@ class _ExampleButtonState extends State { onPressed: () {}, ), ), - ListTile( - trailing: Padding( - padding: EdgeInsets.symmetric(horizontal: 100.w), - child: ASLongButton.solid(title: 'adaptable', onPressed: () {}), - ), + Padding( + padding: EdgeInsets.symmetric(horizontal: 100.w), + child: ASLongButton.solid(title: 'adaptable', onPressed: () {}), ), SizedBox( height: 12.w, diff --git a/example/lib/example_numeric_button.dart b/example/lib/example_numeric_button.dart index 4dc034e..6ded4e3 100644 --- a/example/lib/example_numeric_button.dart +++ b/example/lib/example_numeric_button.dart @@ -15,6 +15,8 @@ class _ExampleNumericButtonState extends State { ); } + int _pickedValue = 0; + @override Widget build(BuildContext context) { return ASScaffold( @@ -23,17 +25,25 @@ class _ExampleNumericButtonState extends State { builder: (context) { return ListView( children: [ - ASNumericButton( - initValue: 0, - maxValue: 10, - onChange: (value) {}, - reachMax: (value) { - _showSnack(context, 'reach max'); - }, - reachMin: (value) { - _showSnack(context, 'reach min'); - }, - ) + ListTile( + title: Text(_pickedValue.toString()), + subtitle: Text('一般用法'), + trailing: ASNumericButton( + initValue: _pickedValue, + maxValue: 10, + onChange: (value) { + setState(() { + _pickedValue = value; + }); + }, + reachMax: (value) { + _showSnack(context, 'reach max'); + }, + reachMin: (value) { + _showSnack(context, 'reach min'); + }, + ), + ), ], ); }, diff --git a/example/lib/example_picker.dart b/example/lib/example_picker.dart index c409ced..6d261dc 100644 --- a/example/lib/example_picker.dart +++ b/example/lib/example_picker.dart @@ -16,21 +16,29 @@ class _ExamplePickerState extends State { title: '选择器', body: ListView( children: [ - ASButton( - title: '日期选择器 DatePicker', - onPressed: () async { - DateTime date = await asDatePicker(context); - Get.snackbar(date.toString(), 'MESSAGE'); - }, + ListTile( + title: Text('日期选择器'), + subtitle: Text('DatePicker'), + trailing: ASButton( + title: '日期选择器', + onPressed: () async { + DateTime date = await asDatePicker(context); + Get.snackbar(date.toString(), 'MESSAGE'); + }, + ), ), - ASButton( - title: '自定义选择器', - onPressed: () async { - Get.bottomSheet(ASPickerBox( - title: '自定义选择器', - child: Text('CHILD'), - )); - }, + ListTile( + title: Text('自定义选择器'), + subtitle: Text('CustomPicker'), + trailing: ASButton( + title: '自定义选择器', + onPressed: () async { + Get.bottomSheet(ASPickerBox( + title: '自定义选择器', + child: Text('CHILD'), + )); + }, + ), ), ], ), diff --git a/example/lib/example_style_color.dart b/example/lib/example_style_color.dart index 059ca73..4bf0b5d 100644 --- a/example/lib/example_style_color.dart +++ b/example/lib/example_style_color.dart @@ -11,24 +11,13 @@ class ExampleStyleColor extends StatefulWidget { class _ExampleStyleColorState extends State { _buildCard(ColorObject object) { - return Column( - children: [ - Text(object.name), - Text(object.codeName), - Text( - object.color.toString(), - style: TextStyle( - color: object.color, - backgroundColor: - object.color.value > 0xFFAAAAAA ? Colors.black : Colors.white, - ), - ), - Card( - color: object.color, - child: SizedBox(height: 50.w, width: double.infinity), - ), - SizedBox(height: 16.w), - ], + return ListTile( + title: Text('${object.name} ${object.color.toString().substring(6, 16)}'), + subtitle: Text(object.codeName), + trailing: Card( + color: object.color, + child: SizedBox(height: 50.w, width: 50.w), + ), ); } diff --git a/example/lib/example_text_field.dart b/example/lib/example_text_field.dart new file mode 100644 index 0000000..4c19f8b --- /dev/null +++ b/example/lib/example_text_field.dart @@ -0,0 +1,23 @@ +import 'package:ansu_ui/ansu_ui.dart'; +import 'package:flutter/material.dart'; + +class ExampleTextFiled extends StatefulWidget { + ExampleTextFiled({Key key}) : super(key: key); + + @override + _ExampleTextFiledState createState() => _ExampleTextFiledState(); +} + +class _ExampleTextFiledState extends State { + TextEditingController _controller; + @override + Widget build(BuildContext context) { + return ASScaffold( + title: '文本框 TextFiled', + appBarBottom: ASSearchTextField( + controller: _controller, + hintText: '搜索', + ), + ); + } +} diff --git a/example/lib/main.dart b/example/lib/main.dart index 1e470a4..18b917e 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -4,6 +4,7 @@ import 'package:example/example_dialog.dart'; import 'package:example/example_drawer.dart'; import 'package:example/example_listtile.dart'; import 'package:example/example_tag.dart'; +import 'package:example/example_text_field.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_localizations/flutter_localizations.dart'; @@ -108,9 +109,14 @@ class _MyHomePageState extends State { title: '对话框 Dialog', onPressed: () => Get.to(ExampleDialog()), ), - ASButton.info(title:'列表内容项 ListTile', - onPressed: () => Get.to(ExampleListTile()), - ) + ASButton.info( + title: '列表内容项 ListTile', + onPressed: () => Get.to(ExampleListTile()), + ), + ASButton.info( + title: '文本框 TextField', + onPressed: () => Get.to(ExampleTextFiled()), + ), ], ), ); diff --git a/lib/ansu_ui.dart b/lib/ansu_ui.dart index ac0c380..725ef0f 100644 --- a/lib/ansu_ui.dart +++ b/lib/ansu_ui.dart @@ -17,6 +17,7 @@ export 'pickers/as_picker_box.dart'; export 'dialog/as_dialog.dart'; export 'divider/as_divider.dart'; export 'tag/as_tag.dart'; +export 'text_field/as_search_text_field.dart'; export 'utils/screen_adapter.dart'; diff --git a/lib/text_field/as_search_text_field.dart b/lib/text_field/as_search_text_field.dart new file mode 100644 index 0000000..e2bce4b --- /dev/null +++ b/lib/text_field/as_search_text_field.dart @@ -0,0 +1,85 @@ +import 'package:ansu_ui/styles/as_colors.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_screenutil/flutter_screenutil.dart'; + +///TextFiled +class ASSearchTextField extends StatefulWidget implements PreferredSizeWidget { + ASSearchTextField({ + Key key, + this.controller, + this.hintText, + this.onChanged, + this.focusNode, + this.onSubmitted, + }) : super(key: key); + + ///控制器 + final TextEditingController controller; + + ///hint Text + final String hintText; + + ///文字变化回调 + final ValueChanged onChanged; + + ///完成输入回调 + final ValueChanged onSubmitted; + + ///焦点 + final FocusNode focusNode; + + @override + _ASSearchTextFieldState createState() => _ASSearchTextFieldState(); + + @override + Size get preferredSize => Size.fromHeight(42.w); +} + +class _ASSearchTextFieldState extends State { + get _border => OutlineInputBorder( + borderRadius: BorderRadius.circular(21.w), + borderSide: BorderSide( + color: Color(0xFF979797), + ), + ); + + @override + Widget build(BuildContext context) { + return Container( + height: 42.w, + padding: EdgeInsets.symmetric( + horizontal: 15.w, + vertical: 3.w, + ), + child: TextField( + controller: widget.controller, + onChanged: widget.onChanged, + onSubmitted: widget.onSubmitted, + focusNode: widget.focusNode, + cursorColor: kPrimaryColor, + textInputAction: TextInputAction.search, + decoration: InputDecoration( + hintText: widget.hintText, + hintStyle: TextStyle( + color: kTextSubColor, + fontSize: 14.sp, + ), + border: _border, + enabledBorder: _border, + focusedBorder: _border, + focusedErrorBorder: _border, + prefixIcon: Padding( + padding: EdgeInsets.only(left: 13.w, right: 8.w), + child: Icon( + Icons.search, + size: 16.w, + color: Colors.black, + ), + ), + prefixIconConstraints: BoxConstraints(minWidth: 0, minHeight: 0), + contentPadding: EdgeInsets.zero, + ), + ), + ); + } +} diff --git a/pubspec.yaml b/pubspec.yaml index 13eaab7..abf9172 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: ansu_ui description: A new Flutter package. -version: 0.0.3 +version: 0.0.4 author: environment: