From c6311000aef74501da56e8279954095cf72883a5 Mon Sep 17 00:00:00 2001 From: zhang <494089941@qq.com> Date: Tue, 29 Dec 2020 17:35:30 +0800 Subject: [PATCH] update checkbox --- example/lib/example_box.dart | 11 +++++++++++ lib/box/as_check_box.dart | 19 +++++++++++++------ 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/example/lib/example_box.dart b/example/lib/example_box.dart index 24cf880..7e3cccb 100644 --- a/example/lib/example_box.dart +++ b/example/lib/example_box.dart @@ -1,5 +1,6 @@ import 'package:ansu_ui/ansu_ui.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_screenutil/flutter_screenutil.dart'; class ExampleBox extends StatefulWidget { ExampleBox({Key key}) : super(key: key); @@ -35,6 +36,16 @@ class _ExampleBoxState extends State { }); }, ), + ListTile( + leading: SizedBox(width: 20.w,height: 20.w, child: ASCheckBox.checkStyle(value: _state,color: Colors.red,)), + title: Text('CheckBox'), + subtitle: Text('with redcolor'), + onTap: () { + setState(() { + _state = !_state; + }); + }, + ), ], ), ); diff --git a/lib/box/as_check_box.dart b/lib/box/as_check_box.dart index 68cedcc..f166d4e 100644 --- a/lib/box/as_check_box.dart +++ b/lib/box/as_check_box.dart @@ -3,10 +3,12 @@ import 'package:flutter_screenutil/flutter_screenutil.dart'; class ASCheckBox extends StatefulWidget { final bool value; + ///控制选中时的样式 final bool checkStyle; + ///选中时颜色 -final Color color; + final Color color; ASCheckBox({Key key, this.value = false, this.color}) : checkStyle = false, super(key: key); @@ -38,7 +40,8 @@ class _ASCheckBoxState extends State { height: widget.value ? 13.w : 5.w, width: widget.value ? 13.w : 5.w, decoration: BoxDecoration( - color:widget.color?? Color(0xFFF69A2D).withOpacity(widget.value ? 1 : 0), + color: (widget.color ?? Color(0xFFF69A2D)) + .withOpacity(widget.value ? 1 : 0), borderRadius: BorderRadius.circular(13.w), ), ), @@ -58,16 +61,20 @@ class _ASCheckBoxState extends State { width: widget.value ? 0 : 1.w, ), borderRadius: BorderRadius.circular(27.w), - color:widget.color?? Color(0xFFFFBD32).withOpacity(widget.value ? 1 : 0), + color: (widget.color ?? Color(0xFFFFBD32)) + .withOpacity(widget.value ? 1 : 0), ), child: AnimatedOpacity( duration: Duration(milliseconds: 300), curve: Curves.fastOutSlowIn, opacity: widget.value ? 1 : 0, child: FittedBox( - child: Icon( - Icons.check, - size: 18.w, + child: Padding( + padding: EdgeInsets.all(5.w), + child: Icon( + Icons.check, + color: widget.color != null ? Colors.white : Colors.black, + ), ), ), ),