bottom sheet
parent
4d76b34608
commit
ea15bd9152
@ -0,0 +1,145 @@
|
|||||||
|
import 'dart:io';
|
||||||
|
import 'package:easy_localization/easy_localization.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:hmg_patient_app_new/core/app_assets.dart';
|
||||||
|
import 'package:hmg_patient_app_new/core/enums.dart';
|
||||||
|
import 'package:hmg_patient_app_new/core/utils/utils.dart';
|
||||||
|
import 'package:hmg_patient_app_new/extensions/string_extensions.dart';
|
||||||
|
import 'package:hmg_patient_app_new/generated/locale_keys.g.dart';
|
||||||
|
import 'package:hmg_patient_app_new/widgets/input_widget.dart';
|
||||||
|
|
||||||
|
class GenericBottomSheet extends StatefulWidget {
|
||||||
|
String? countryCode;
|
||||||
|
String? initialPhoneNumber;
|
||||||
|
final List<Widget> buttons;
|
||||||
|
TextEditingController? textController;
|
||||||
|
final bool isForEmail;
|
||||||
|
Function(Country)? onCountryChange;
|
||||||
|
final bool isEnableCountryDropdown;
|
||||||
|
final bool isFromSavedLogin;
|
||||||
|
Function(String?)? onChange;
|
||||||
|
// FocusNode myFocusNode;
|
||||||
|
|
||||||
|
GenericBottomSheet(
|
||||||
|
{this.countryCode = "",
|
||||||
|
this.initialPhoneNumber = "",
|
||||||
|
required this.buttons,
|
||||||
|
this.textController,
|
||||||
|
this.isForEmail = false,
|
||||||
|
this.onCountryChange,
|
||||||
|
this.isEnableCountryDropdown = false,
|
||||||
|
this.isFromSavedLogin = false,
|
||||||
|
this.onChange,
|
||||||
|
// required this.myFocusNode
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
_GenericBottomSheetState createState() => _GenericBottomSheetState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _GenericBottomSheetState extends State<GenericBottomSheet> {
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
|
||||||
|
if (!widget.isForEmail) {
|
||||||
|
widget.textController = TextEditingController(text: widget.initialPhoneNumber);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return SafeArea(
|
||||||
|
top: false,
|
||||||
|
bottom: Platform.isIOS ? false : true,
|
||||||
|
child: GestureDetector(
|
||||||
|
onTap: () {
|
||||||
|
FocusScope.of(context).unfocus();
|
||||||
|
},
|
||||||
|
child: Directionality(
|
||||||
|
textDirection: Directionality.of(context),
|
||||||
|
child: Container(
|
||||||
|
padding: const EdgeInsets.all(24),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Color(0xFFF8F8FA),
|
||||||
|
borderRadius: const BorderRadius.vertical(top: Radius.circular(16)),
|
||||||
|
),
|
||||||
|
child: Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
mainAxisAlignment: MainAxisAlignment.start,
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
|
children: [
|
||||||
|
// Title
|
||||||
|
Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Flexible(
|
||||||
|
child: widget.isFromSavedLogin
|
||||||
|
? LocaleKeys.receiveOtpToast.tr().toText24()
|
||||||
|
: widget.isForEmail
|
||||||
|
? LocaleKeys.enterEmail.tr().toText24()
|
||||||
|
: LocaleKeys.enterPhoneNumber.tr().toText24()),
|
||||||
|
InkWell(
|
||||||
|
onTap: () {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
},
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.only(top: 10),
|
||||||
|
child: Utils.buildSvgWithAssets(
|
||||||
|
icon: AppAssets.cross_circle,
|
||||||
|
),
|
||||||
|
)),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
const SizedBox(height: 8),
|
||||||
|
// Subtitle
|
||||||
|
widget.isFromSavedLogin
|
||||||
|
? LocaleKeys.pleaseChooseOption.tr().toText16()
|
||||||
|
: widget.isForEmail
|
||||||
|
? LocaleKeys.enterEmailDesc.tr().toText16()
|
||||||
|
: LocaleKeys.enterPhoneDesc.tr().toText16(),
|
||||||
|
|
||||||
|
if (widget.isFromSavedLogin)
|
||||||
|
...[]
|
||||||
|
else ...[
|
||||||
|
widget.textController != null
|
||||||
|
? TextInputWidget(
|
||||||
|
labelText: widget.isForEmail ? LocaleKeys.email : LocaleKeys.phoneNumber,
|
||||||
|
hintText: widget.isForEmail ? "demo@gmail.com" : "5xxxxxxxx",
|
||||||
|
controller: widget.textController!,
|
||||||
|
padding: EdgeInsets.only(top: 8, bottom: 8, left: 8, right: 8),
|
||||||
|
keyboardType: widget.isForEmail ? TextInputType.emailAddress : TextInputType.number,
|
||||||
|
onChange: (value) {
|
||||||
|
widget.textController!.text = value!;
|
||||||
|
if (widget.onChange != null) {
|
||||||
|
widget.onChange!(value);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
isEnable: true,
|
||||||
|
// focusNode: widget.myFocusNode,
|
||||||
|
isReadOnly: widget.isFromSavedLogin,
|
||||||
|
prefix: widget.isForEmail ? null : widget.countryCode,
|
||||||
|
isBorderAllowed: false,
|
||||||
|
isAllowLeadingIcon: true,
|
||||||
|
isCountryDropDown: widget.isEnableCountryDropdown,
|
||||||
|
leadingIcon: widget.isForEmail ? AppAssets.email : AppAssets.smart_phone,
|
||||||
|
)
|
||||||
|
: SizedBox(),
|
||||||
|
],
|
||||||
|
|
||||||
|
SizedBox(height: 24),
|
||||||
|
...widget.buttons,
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue