91 lines
3.0 KiB
Dart
91 lines
3.0 KiB
Dart
import 'package:birzha/core/adaptix/adaptix.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:birzha/components/indicator.dart';
|
|
|
|
class MyButton extends StatefulWidget {
|
|
MyButton({
|
|
Key? key,
|
|
this.onDisabled,
|
|
this.color,
|
|
this.isDisabled = false,
|
|
this.onTap,
|
|
this.inProgress,
|
|
this.padding,
|
|
this.borderRadius,
|
|
this.text,
|
|
this.height,
|
|
this.indicatorSize,
|
|
this.textSpan,
|
|
}) : super(key: key);
|
|
|
|
final void Function()? onTap;
|
|
final EdgeInsets? padding;
|
|
final String? text;
|
|
final bool? inProgress;
|
|
final double? height;
|
|
final Widget? textSpan;
|
|
final bool isDisabled;
|
|
final void Function()? onDisabled;
|
|
final Color? color;
|
|
final double? indicatorSize;
|
|
final double? borderRadius;
|
|
|
|
@override
|
|
_MyButtonState createState() => _MyButtonState();
|
|
}
|
|
|
|
class _MyButtonState extends State<MyButton> with TickerProviderStateMixin {
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
Color? _backColor;
|
|
Color? _color;
|
|
|
|
if (widget.color != null) {
|
|
bool isDark = Theme.of(context).brightness == Brightness.dark;
|
|
_color = isDark ? widget.color : Theme.of(context).textTheme.button?.color;
|
|
_backColor = isDark ? Theme.of(context).buttonColor : widget.color;
|
|
} else {
|
|
_color = Theme.of(context).textTheme.button?.color;
|
|
_backColor = Theme.of(context).buttonColor;
|
|
}
|
|
|
|
return Opacity(
|
|
opacity: widget.isDisabled ? 0.5 : 1,
|
|
child: ClipRRect(
|
|
borderRadius: BorderRadius.circular(widget.borderRadius ?? 20.adaptedPx()),
|
|
child: Material(
|
|
color: _backColor,
|
|
child: InkWell(
|
|
onTap: () {
|
|
if (!(widget.inProgress ?? false) && widget.onTap != null && !widget.isDisabled) {
|
|
widget.onTap!();
|
|
} else if (widget.isDisabled && widget.onDisabled != null) {}
|
|
},
|
|
child: Container(
|
|
height: widget.height,
|
|
padding: widget.padding ?? EdgeInsets.symmetric(vertical: 5.adaptedPx(), horizontal: 15.adaptedPx()),
|
|
child: AnimatedSize(
|
|
duration: Duration(milliseconds: 200),
|
|
vsync: this,
|
|
child: (widget.inProgress ?? false)
|
|
? Center(
|
|
child: Indicator(
|
|
size: widget.indicatorSize ?? 0.4.adaptedPx(),
|
|
color: Colors.white,
|
|
))
|
|
: Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: <Widget>[
|
|
widget.textSpan == null
|
|
? Text('${widget.text}', style: TextStyle(color: _color, fontSize: 12.99.adaptedPx(), fontWeight: FontWeight.w500))
|
|
: widget.textSpan!
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
)),
|
|
);
|
|
}
|
|
}
|