2023-04-11 06:08:10 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter/src/widgets/container.dart';
|
|
|
|
import 'package:flutter/src/widgets/framework.dart';
|
2023-04-13 08:45:19 +00:00
|
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
2023-04-11 06:08:10 +00:00
|
|
|
import 'package:flutter_form_builder/flutter_form_builder.dart';
|
|
|
|
import 'package:flutter_svg/svg.dart';
|
|
|
|
import 'package:fluttericon/font_awesome5_icons.dart';
|
|
|
|
import 'package:fluttericon/typicons_icons.dart';
|
|
|
|
import 'package:form_builder_validators/form_builder_validators.dart';
|
2023-04-13 08:45:19 +00:00
|
|
|
import 'package:intl/intl.dart';
|
|
|
|
import 'package:unit2/bloc/sos/sos_bloc.dart';
|
2023-04-11 06:08:10 +00:00
|
|
|
import 'package:unit2/screens/sos/components/mobile.dart';
|
|
|
|
import 'package:unit2/theme-data.dart/colors.dart';
|
|
|
|
import 'package:unit2/utils/text_container.dart';
|
|
|
|
|
2023-04-13 08:45:19 +00:00
|
|
|
import '../../../sevices/sos/sos_service.dart';
|
2023-04-11 06:08:10 +00:00
|
|
|
import '../../../theme-data.dart/btn-style.dart';
|
|
|
|
import '../../../theme-data.dart/form-style.dart';
|
|
|
|
import '../../../utils/global.dart';
|
2023-04-13 08:45:19 +00:00
|
|
|
import 'edit_mobile.dart';
|
2023-04-11 06:08:10 +00:00
|
|
|
|
|
|
|
class RequestSOS extends StatefulWidget {
|
|
|
|
const RequestSOS({super.key});
|
|
|
|
|
|
|
|
@override
|
|
|
|
State<RequestSOS> createState() => _RequestSOSState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _RequestSOSState extends State<RequestSOS> {
|
2023-04-13 08:45:19 +00:00
|
|
|
final formKey = GlobalKey<FormBuilderState>();
|
|
|
|
DateFormat dteFormat = DateFormat("y-M-d H:m:s");
|
|
|
|
|
|
|
|
String? mobileNumber1;
|
|
|
|
String? mobileNumber2;
|
2023-04-11 06:08:10 +00:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2023-04-13 08:45:19 +00:00
|
|
|
return BlocBuilder<SosBloc, SosState>(
|
|
|
|
builder: (context, state) {
|
|
|
|
if(state is RequestSosState){
|
|
|
|
return SingleChildScrollView(
|
|
|
|
child: Container(
|
|
|
|
height: screenHeight * .82,
|
2023-06-21 00:22:43 +00:00
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 42, vertical: 10),
|
2023-04-13 08:45:19 +00:00
|
|
|
child: FormBuilder(
|
|
|
|
key: formKey,
|
|
|
|
child: Column(
|
|
|
|
children: [
|
|
|
|
SizedBox(
|
|
|
|
height: blockSizeVertical * 2,
|
|
|
|
),
|
|
|
|
SvgPicture.asset(
|
|
|
|
'assets/svgs/request_sos.svg',
|
|
|
|
height: blockSizeVertical * 22,
|
|
|
|
allowDrawingOutsideViewBox: true,
|
|
|
|
),
|
|
|
|
Mobile(
|
|
|
|
title: state.mobile1,
|
|
|
|
subtitle: mobile1,
|
|
|
|
//// edit modal
|
|
|
|
onPressed: () {
|
|
|
|
showBottomSheet(
|
|
|
|
context: context,
|
|
|
|
builder: (context) {
|
|
|
|
return EditMobile(
|
|
|
|
title: "Edit Mobile 1",
|
|
|
|
label: "Mobile number 1",
|
|
|
|
initialValue: state.mobile1,
|
|
|
|
onchanged: (value) {
|
|
|
|
mobileNumber1 = value;
|
|
|
|
},
|
|
|
|
onpressed: () {
|
|
|
|
Navigator.of(context,
|
|
|
|
rootNavigator: true)
|
|
|
|
.pop();
|
|
|
|
BlocProvider.of<SosBloc>(context)
|
|
|
|
.add(SubmitMobile(
|
|
|
|
mobile1: mobileNumber1!,
|
|
|
|
mobile2: state.mobile2));
|
|
|
|
},
|
|
|
|
);
|
|
|
|
});
|
|
|
|
},),
|
|
|
|
const Divider(),
|
|
|
|
////edit mobile 2
|
|
|
|
Mobile(
|
|
|
|
title: state.mobile2??"N/A",
|
|
|
|
subtitle: mobile2,
|
|
|
|
onPressed: () {
|
|
|
|
showBottomSheet(
|
|
|
|
context: context,
|
|
|
|
builder: (context) {
|
|
|
|
return EditMobile(
|
|
|
|
title: "Edit Mobile 2",
|
|
|
|
label: "Mobile number 2",
|
|
|
|
initialValue: state.mobile2??'',
|
|
|
|
onchanged: (value) {
|
|
|
|
mobileNumber2 = value;
|
|
|
|
},
|
|
|
|
onpressed: () {
|
|
|
|
Navigator.of(context,
|
|
|
|
rootNavigator: true)
|
|
|
|
.pop();
|
|
|
|
BlocProvider.of<SosBloc>(context)
|
|
|
|
.add(SubmitMobile(
|
|
|
|
mobile1: state.mobile1,
|
|
|
|
mobile2: mobileNumber2));
|
|
|
|
},
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}),
|
|
|
|
const Divider(),
|
|
|
|
ListTile(
|
|
|
|
leading: const Icon(
|
|
|
|
Typicons.location,
|
|
|
|
color: second,
|
|
|
|
),
|
|
|
|
title: Text("${state.locationData.latitude}/${state.locationData.longitude}"),
|
|
|
|
subtitle: Text(
|
|
|
|
currentLocation,
|
|
|
|
style: Theme.of(context).textTheme.bodySmall,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
FormBuilderTextField(
|
|
|
|
name: "message",
|
|
|
|
validator: FormBuilderValidators.compose([
|
|
|
|
FormBuilderValidators.required(errorText: messageRequired)
|
|
|
|
]),
|
|
|
|
autovalidateMode: AutovalidateMode.onUserInteraction,
|
|
|
|
maxLines: 5,
|
|
|
|
decoration: normalTextFieldStyle("", sosMessage),
|
|
|
|
),
|
|
|
|
const Expanded(
|
|
|
|
child: SizedBox(),
|
|
|
|
),
|
|
|
|
SizedBox(
|
|
|
|
width: double.infinity,
|
|
|
|
height: screenHeight * .06,
|
|
|
|
child: ElevatedButton(
|
|
|
|
style: secondaryBtnStyle(
|
|
|
|
primary, Colors.transparent, Colors.white54),
|
|
|
|
child: const Text(
|
|
|
|
submit,
|
|
|
|
style: TextStyle(color: Colors.white),
|
|
|
|
),
|
|
|
|
//// on pressed
|
|
|
|
onPressed: () async{
|
|
|
|
if( formKey.currentState!.saveAndValidate()){
|
|
|
|
String message = formKey.currentState!.value['message'];
|
|
|
|
DateTime today = DateTime.now();
|
|
|
|
String requestedDate =
|
|
|
|
dteFormat.format(today);
|
|
|
|
BlocProvider.of<SosBloc>(context).add(SendSOS(msg: message, requestDate: requestedDate));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
),
|
2023-04-11 06:08:10 +00:00
|
|
|
),
|
2023-04-13 08:45:19 +00:00
|
|
|
],
|
2023-04-11 06:08:10 +00:00
|
|
|
),
|
2023-04-13 08:45:19 +00:00
|
|
|
)),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return Container();
|
|
|
|
},
|
2023-04-11 06:08:10 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|