87 lines
2.5 KiB
Dart
87 lines
2.5 KiB
Dart
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
import 'package:lamiter/Component/Button/my_text_button.dart';
|
|
import 'package:lamiter/Component/bottom_popup_message.dart';
|
|
import 'package:lamiter/Extension/build_context.dart';
|
|
|
|
class SubmitButton extends StatefulWidget {
|
|
final String text;
|
|
final bool enabled;
|
|
final bool submitting;
|
|
final Function()? onTap;
|
|
|
|
const SubmitButton({
|
|
super.key,
|
|
required this.text,
|
|
this.enabled = true,
|
|
this.submitting = false,
|
|
this.onTap,
|
|
});
|
|
|
|
@override
|
|
State<SubmitButton> createState() => SubmitButtonState();
|
|
}
|
|
|
|
class SubmitButtonState extends State<SubmitButton> {
|
|
final GlobalKey<BottomPopupMessageState> errorMessageKey =
|
|
GlobalKey<BottomPopupMessageState>();
|
|
|
|
void showMessage(String message, Color color) {
|
|
errorMessageKey.currentState?.showMessage(message, color);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final width = context.width(0.4);
|
|
final height = 36.sp;
|
|
|
|
return SizedBox(
|
|
width: context.width(1),
|
|
height: context.height(0.2),
|
|
child: Stack(
|
|
alignment: Alignment.bottomCenter,
|
|
children: [
|
|
// Error message
|
|
BottomPopupMessage(
|
|
key: errorMessageKey,
|
|
height: context.height(0.1) + 12.sp,
|
|
),
|
|
// Button
|
|
Container(
|
|
width: context.width(1),
|
|
height: context.height(0.1),
|
|
decoration: BoxDecoration(
|
|
color: context.surface,
|
|
boxShadow: [
|
|
BoxShadow(
|
|
color: Colors.black.withOpacity(0.3),
|
|
spreadRadius: 5,
|
|
blurRadius: 7,
|
|
offset: const Offset(0, 3), // changes position of shadow
|
|
),
|
|
],
|
|
),
|
|
child: Center(
|
|
child: Padding(
|
|
padding: EdgeInsets.only(bottom: 6.sp),
|
|
child: MyTextButton(
|
|
width: width,
|
|
height: height,
|
|
prefixIcon: widget.submitting
|
|
? CupertinoActivityIndicator(color: context.surface)
|
|
: null,
|
|
text: widget.text,
|
|
fontSize: 13.sp,
|
|
enabled: !widget.submitting && widget.enabled,
|
|
onTap: widget.onTap,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|