Again
unknown
dart
2 years ago
17 kB
14
Indexable
import 'dart:async';
import 'dart:developer';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:mmmarvellous/generated/l10n.dart';
import 'package:mmmarvellous/src/core/utils/date_format.dart';
import 'package:mmmarvellous/src/core/utils/launch_url.dart';
import 'package:mmmarvellous/src/feature/domain/models/regulars/assign_regular_entity.dart';
import 'package:mmmarvellous/src/core/constans/widgets.dart';
import 'package:mmmarvellous/src/feature/presentation/bloc/counter/counter_bloc.dart';
import 'package:mmmarvellous/src/feature/presentation/bloc/counter/counter_event.dart';
import 'package:mmmarvellous/src/feature/presentation/bloc/regular/regular_bloc.dart';
import 'package:mmmarvellous/src/feature/presentation/bloc/regular_request/regular_request_bloc.dart';
class RegularDetailsPage extends StatefulWidget {
final AssignRegularEntity loaded;
final String regularType;
const RegularDetailsPage(
{super.key, required this.loaded, required this.regularType});
@override
State<RegularDetailsPage> createState() => _RegularDetailsPageState();
}
class _RegularDetailsPageState extends State<RegularDetailsPage> {
bool isActive = true;
Future<void> _apply(BuildContext context, SnackBar snackBar) async {
ScaffoldMessenger.of(context).clearSnackBars();
setState(() {
isActive = false;
});
try {
final completer = Completer<dynamic>();
ScaffoldMessenger.of(context).showSnackBar(snackBar);
context.read<AssignRegularBloc>().add(SendApplyAssignRegularJobEvent(
id: widget.loaded.id, completer: completer));
await completer.future;
if (context.mounted) {
context.read<AssignRegularBloc>().add(FetchAssignRegularDataEvent());
context.read<CounterBloc>().add(const FetchCounterJobEvent());
}
} catch (e) {
log(e.toString());
}
}
Future<void> _requestDelete(BuildContext context, SnackBar snackBar) async {
ScaffoldMessenger.of(context).clearSnackBars();
setState(() {
isActive = false;
});
try {
final completer = Completer<dynamic>();
ScaffoldMessenger.of(context).showSnackBar(snackBar);
context.read<RegularRequestBloc>().add(SendRegularRequestDeleteEvent(
id: widget.loaded.id, completer: completer));
await completer.future;
if (context.mounted) {
context.read<RegularRequestBloc>().add(FetchRegularRequestEvent());
context.read<CounterBloc>().add(const FetchCounterJobEvent());
}
} catch (e) {
log(e.toString());
}
}
@override
Widget build(BuildContext context) {
final snackBar = SnackBar(
duration: const Duration(seconds: 4),
content: Text(
widget.regularType == 'regular'
? S.of(context).request_sent
: S.of(context).request_deleted,
style: const TextStyle(fontWeight: FontWeight.w600),
),
action: SnackBarAction(
label: S.of(context).snack_bar_action,
onPressed: () {},
),
);
return Scaffold(
appBar: AppBar(
title: Text(
S.of(context).regular_details,
style: const TextStyle(fontWeight: FontWeight.w600),
),
centerTitle: true,
),
body: SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.fromLTRB(12, 0, 12, 0),
child: Column(
children: [
const SizedBox(height: 20.0),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Container(
width: MediaQuery.of(context).size.width / 2.2,
height: MediaQuery.of(context).size.height / 5,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(15.0),
color: Theme.of(context).primaryColor,
),
child: Padding(
padding: const EdgeInsets.all(12.0),
child: ListView(
scrollDirection: Axis.vertical,
children: [
Text(S.of(context).need_from),
Text(
widget.loaded.from!.toMMMMdEEE,
style: const TextStyle(fontWeight: FontWeight.w600),
),
const SizedBox(height: 4),
Text(S.of(context).post_code),
Text(
'${widget.loaded.job!.client!.city}',
style: const TextStyle(fontWeight: FontWeight.w600),
),
Text(
'${widget.loaded.job!.client!.post}',
style: const TextStyle(fontWeight: FontWeight.w600),
),
],
),
),
),
const SizedBox(width: 12.0),
Flexible(
child: Container(
width: MediaQuery.of(context).size.width / 2.2,
height: MediaQuery.of(context).size.height / 5,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(15.0),
color: Theme.of(context).primaryColor,
),
child: Padding(
padding: const EdgeInsets.all(12.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(S.of(context).tasks),
const SizedBox(height: 2),
Expanded(child: TasksWidget(loaded: widget.loaded)),
],
),
),
),
),
],
),
const SizedBox(height: 12.0),
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(15.0),
color: Theme.of(context).primaryColor,
),
child: Padding(
padding: const EdgeInsets.all(12.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
widget.regularType == 'myRegular'
? Wrap(
direction: Axis.vertical,
children: [
Text(S.of(context).client),
Text(
widget.loaded.job!.client!.name!,
style: const TextStyle(
fontWeight: FontWeight.w600),
),
const SizedBox(height: 12.0),
Text(S.of(context).address),
Text(
widget.loaded.job!.client!.address!,
style: const TextStyle(
fontWeight: FontWeight.w600,
),
),
const SizedBox(height: 12.0),
],
)
: const SizedBox(),
Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
SizedBox(
width: MediaQuery.of(context).size.width / 4,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(S.of(context).hours),
JobDetailsHoursWidget(
loaded: widget.loaded.job!.jobDetails),
],
),
),
SizedBox(
width: MediaQuery.of(context).size.width / 4,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(S.of(context).freq),
JobDetailsFreqWidget(
loaded: widget.loaded.job!.jobDetails),
],
),
),
],
),
const SizedBox(height: 12.0),
Text(S.of(context).details),
Text(
'${widget.loaded.hkDetails}' != ''
? '${widget.loaded.hkDetails}'
: S.of(context).empty,
style: const TextStyle(fontWeight: FontWeight.w600),
),
],
),
),
),
const SizedBox(height: 12.0),
widget.regularType == "myRegular"
? Container(
width: MediaQuery.of(context).size.width,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(15.0),
color: Theme.of(context).primaryColor,
),
child: Padding(
padding: const EdgeInsets.all(12.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(S.of(context).job_description),
Text(
'${widget.loaded.job!.description}' != ''
? '${widget.loaded.job!.description}'
: S.of(context).empty,
style:
const TextStyle(fontWeight: FontWeight.w600),
),
],
),
),
)
: const SizedBox(),
widget.regularType == "myRegular"
? const SizedBox(height: 12.0)
: const SizedBox(),
IssuesListFormatWidget(loaded: widget.loaded.job!.client!.issues),
const SizedBox(height: 12.0),
],
),
),
),
bottomNavigationBar: widget.regularType == 'regular'
? Container(
decoration: BoxDecoration(
color: Theme.of(context).secondaryHeaderColor,
),
child: Padding(
padding: const EdgeInsets.all(30.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
SizedBox(
height: MediaQuery.of(context).size.height * 0.065,
width: MediaQuery.of(context).size.width * 0.6,
child: CustomElevationButton(
onPressed:
isActive ? () => _apply(context, snackBar) : null,
color: Theme.of(context).indicatorColor,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Icon(CupertinoIcons.check_mark_circled),
const SizedBox(width: 4),
Text(S.of(context).apply_job),
],
),
),
),
SizedBox(
height: MediaQuery.of(context).size.height * 0.065,
width: MediaQuery.of(context).size.width * 0.2,
child: CustomElevationButton(
onPressed: () {
final Uri uri = Uri(
scheme: 'tel',
path: '07590361600',
);
launchUrlFunc(uri);
},
color: Theme.of(context).indicatorColor,
child: const Icon(CupertinoIcons.phone),
),
),
],
),
),
)
: widget.regularType == 'request'
? Container(
decoration: BoxDecoration(
color: Theme.of(context).secondaryHeaderColor,
),
child: Padding(
padding: const EdgeInsets.all(30.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
SizedBox(
height: MediaQuery.of(context).size.height * 0.065,
width: MediaQuery.of(context).size.width * 0.6,
child: CustomElevationButton(
onPressed: isActive
? () => _requestDelete(context, snackBar)
: null,
color: Theme.of(context).indicatorColor,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Icon(CupertinoIcons.delete),
const SizedBox(width: 4),
Text(S.of(context).delete_request),
],
),
),
),
SizedBox(
height: MediaQuery.of(context).size.height * 0.065,
width: MediaQuery.of(context).size.width * 0.2,
child: CustomElevationButton(
onPressed: () {
final Uri uri = Uri(
scheme: 'tel',
path: '07590361600',
);
launchUrlFunc(uri);
},
color: Theme.of(context).indicatorColor,
child: const Icon(CupertinoIcons.phone),
),
),
],
),
),
)
: widget.regularType == 'myRegular'
? Container(
decoration: BoxDecoration(
color: Theme.of(context).secondaryHeaderColor,
),
child: Padding(
padding: const EdgeInsets.all(30.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
SizedBox(
height:
MediaQuery.of(context).size.height * 0.065,
width: MediaQuery.of(context).size.width * 0.6,
child: CustomElevationButton(
onPressed: () {
final Uri uri = Uri(
scheme: 'tel',
path: widget.loaded.job!.client!.mobile,
);
launchUrlFunc(uri);
},
color: Theme.of(context).indicatorColor,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Icon(CupertinoIcons.phone),
const SizedBox(width: 4),
Text(
S.of(context).call_client,
),
],
),
),
),
],
),
),
)
: null,
);
}
}
Editor is loading...