migrate checkBox and button from stateful to stateless

null_safety
小赖 4 years ago
parent 16f63d4f4b
commit 011b25b5ba

@ -1,7 +1,7 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart';
class ASCheckBox extends StatefulWidget { class ASCheckBox extends StatelessWidget {
final bool value; final bool value;
/// ///
@ -17,11 +17,6 @@ class ASCheckBox extends StatefulWidget {
: checkStyle = true, : checkStyle = true,
super(key: key); super(key: key);
@override
_ASCheckBoxState createState() => _ASCheckBoxState();
}
class _ASCheckBoxState extends State<ASCheckBox> {
_renderDefault() { _renderDefault() {
return Container( return Container(
height: 17.w, height: 17.w,
@ -37,11 +32,10 @@ class _ASCheckBoxState extends State<ASCheckBox> {
child: AnimatedContainer( child: AnimatedContainer(
duration: Duration(milliseconds: 300), duration: Duration(milliseconds: 300),
curve: Curves.fastOutSlowIn, curve: Curves.fastOutSlowIn,
height: widget.value ? 13.w : 5.w, height: value ? 13.w : 5.w,
width: widget.value ? 13.w : 5.w, width: value ? 13.w : 5.w,
decoration: BoxDecoration( decoration: BoxDecoration(
color: (widget.color ?? Color(0xFFF69A2D)) color: (color ?? Color(0xFFF69A2D)).withOpacity(value ? 1 : 0),
.withOpacity(widget.value ? 1 : 0),
borderRadius: BorderRadius.circular(13.w), borderRadius: BorderRadius.circular(13.w),
), ),
), ),
@ -58,22 +52,21 @@ class _ASCheckBoxState extends State<ASCheckBox> {
decoration: BoxDecoration( decoration: BoxDecoration(
border: Border.all( border: Border.all(
color: Color(0xFFD5D5D5), color: Color(0xFFD5D5D5),
width: widget.value ? 0 : 1.w, width: value ? 0 : 1.w,
), ),
borderRadius: BorderRadius.circular(27.w), borderRadius: BorderRadius.circular(27.w),
color: (widget.color ?? Color(0xFFFFBD32)) color: (color ?? Color(0xFFFFBD32)).withOpacity(value ? 1 : 0),
.withOpacity(widget.value ? 1 : 0),
), ),
child: AnimatedOpacity( child: AnimatedOpacity(
duration: Duration(milliseconds: 300), duration: Duration(milliseconds: 300),
curve: Curves.fastOutSlowIn, curve: Curves.fastOutSlowIn,
opacity: widget.value ? 1 : 0, opacity: value ? 1 : 0,
child: FittedBox( child: FittedBox(
child: Padding( child: Padding(
padding: EdgeInsets.all(5.w), padding: EdgeInsets.all(5.w),
child: Icon( child: Icon(
Icons.check, Icons.check,
color: widget.color != null ? Colors.white : Colors.black, color: color != null ? Colors.white : Colors.black,
), ),
), ),
), ),
@ -83,6 +76,6 @@ class _ASCheckBoxState extends State<ASCheckBox> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return widget.checkStyle ? _renderCheck() : _renderDefault(); return checkStyle ? _renderCheck() : _renderDefault();
} }
} }

@ -2,7 +2,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:ansu_ui/styles/as_colors.dart'; import 'package:ansu_ui/styles/as_colors.dart';
class ASBottomButton extends StatefulWidget { class ASBottomButton extends StatelessWidget {
/// ///
final dynamic title; final dynamic title;
@ -102,28 +102,23 @@ class ASBottomButton extends StatefulWidget {
width = double.infinity, width = double.infinity,
super(key: key); super(key: key);
@override
_ASBottomButtonState createState() => _ASBottomButtonState();
}
class _ASBottomButtonState extends State<ASBottomButton> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Container( return Container(
padding: EdgeInsets.only(bottom: MediaQuery.of(context).padding.bottom), padding: EdgeInsets.only(bottom: MediaQuery.of(context).padding.bottom),
width: widget.width ?? double.infinity, width: width ?? double.infinity,
decoration: BoxDecoration( decoration: BoxDecoration(
gradient: LinearGradient( gradient: LinearGradient(
begin: widget.begin ?? Alignment.bottomRight, begin: begin ?? Alignment.bottomRight,
end: widget.end ?? Alignment.topLeft, end: end ?? Alignment.topLeft,
colors: widget.colors ?? [widget.bgcolor, widget.bgcolor]), colors: colors ?? [bgcolor, bgcolor]),
), ),
child: MaterialButton( child: MaterialButton(
onPressed: widget.onPressed, onPressed: onPressed,
textColor: widget.textColor ?? kLightTextColor, textColor: textColor ?? kLightTextColor,
disabledColor: widget.disableColor, disabledColor: disableColor,
disabledTextColor: widget.disableTextColor, disabledTextColor: disableTextColor,
padding: widget.padding ?? padding: padding ??
EdgeInsets.symmetric( EdgeInsets.symmetric(
vertical: 13.w, vertical: 13.w,
), ),
@ -132,11 +127,11 @@ class _ASBottomButtonState extends State<ASBottomButton> {
highlightElevation: 0, highlightElevation: 0,
focusElevation: 0, focusElevation: 0,
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap, materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
child: widget.title is String child: title is String
? Text(widget.title, ? Text(title,
style: widget.textStyle ?? style: textStyle ??
TextStyle(fontSize: 20.sp, fontWeight: FontWeight.bold)) TextStyle(fontSize: 20.sp, fontWeight: FontWeight.bold))
: widget.title, : title,
), ),
); );
} }

Loading…
Cancel
Save