mirror of
https://github.com/nostrlabs-io/zap-stream-flutter.git
synced 2025-06-15 11:48:21 +00:00
85 lines
2.1 KiB
Dart
85 lines
2.1 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:zap_stream_flutter/theme.dart';
|
|
|
|
class BasicButton extends StatelessWidget {
|
|
final Widget? child;
|
|
final Color? color;
|
|
final BoxDecoration? decoration;
|
|
final EdgeInsetsGeometry? padding;
|
|
final EdgeInsetsGeometry? margin;
|
|
final void Function(BuildContext)? onTap;
|
|
final bool? disabled;
|
|
|
|
const BasicButton(
|
|
this.child, {
|
|
super.key,
|
|
this.color,
|
|
this.decoration,
|
|
this.padding,
|
|
this.margin,
|
|
this.onTap,
|
|
this.disabled,
|
|
});
|
|
|
|
static Widget text(
|
|
String text, {
|
|
Color? color,
|
|
BoxDecoration? decoration,
|
|
EdgeInsetsGeometry? padding,
|
|
EdgeInsetsGeometry? margin,
|
|
void Function(BuildContext)? onTap,
|
|
double? fontSize,
|
|
bool? disabled,
|
|
Icon? icon,
|
|
}) {
|
|
return BasicButton(
|
|
Text.rich(
|
|
TextSpan(
|
|
style: TextStyle(
|
|
color: Color.fromARGB(255, 255, 255, 255),
|
|
fontSize: fontSize,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
children: [
|
|
if (icon != null)
|
|
WidgetSpan(child: icon, alignment: PlaceholderAlignment.middle),
|
|
if (icon != null) TextSpan(text: " "),
|
|
TextSpan(text: text),
|
|
],
|
|
),
|
|
),
|
|
disabled: disabled,
|
|
color: color,
|
|
decoration: decoration,
|
|
padding: padding ?? EdgeInsets.symmetric(vertical: 4, horizontal: 12),
|
|
margin: margin,
|
|
onTap: onTap,
|
|
);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
assert(
|
|
!(color != null && decoration != null),
|
|
"Cant set both 'color' and 'decoration'",
|
|
);
|
|
final defaultBr = BorderRadius.all(Radius.circular(100));
|
|
final inner = Container(
|
|
padding: padding,
|
|
margin: margin,
|
|
decoration:
|
|
decoration ??
|
|
BoxDecoration(color: color ?? LAYER_2, borderRadius: defaultBr),
|
|
child: Center(child: child),
|
|
);
|
|
return GestureDetector(
|
|
onTap: () {
|
|
if (!(disabled ?? false) && onTap != null) {
|
|
onTap!(context);
|
|
}
|
|
},
|
|
child: (disabled ?? false) ? Opacity(opacity: 0.5, child: inner) : inner,
|
|
);
|
|
}
|
|
}
|