create supplier engineer functionality added.
parent
b508e839c5
commit
8273537b00
@ -0,0 +1,30 @@
|
||||
class SupplierEngineer {
|
||||
int id;
|
||||
int supplierId;
|
||||
String personName;
|
||||
int personRoleId;
|
||||
String contact;
|
||||
String email;
|
||||
|
||||
SupplierEngineer({this.id, this.supplierId, this.personName, this.personRoleId, this.contact, this.email});
|
||||
|
||||
SupplierEngineer.fromJson(Map<String, dynamic> json) {
|
||||
id = json['id'];
|
||||
supplierId = json['supplierId'];
|
||||
personName = json['personName'];
|
||||
personRoleId = json['personRoleId'];
|
||||
contact = json['contact'];
|
||||
email = json['email'];
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final Map<String, dynamic> data = new Map<String, dynamic>();
|
||||
data['id'] = this.id;
|
||||
data['supplierId'] = this.supplierId;
|
||||
data['personName'] = this.personName;
|
||||
data['personRoleId'] = this.personRoleId;
|
||||
data['contact'] = this.contact;
|
||||
data['email'] = this.email;
|
||||
return data;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,35 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:http/http.dart';
|
||||
import 'package:test_sa/controllers/api_routes/api_manager.dart';
|
||||
import 'package:test_sa/controllers/api_routes/urls.dart';
|
||||
import 'package:test_sa/models/lookup.dart';
|
||||
import 'package:test_sa/providers/loading_list_notifier.dart';
|
||||
|
||||
class SupplierEngineerProvider extends LoadingListNotifier<Lookup> {
|
||||
@override
|
||||
Future getDate() async {
|
||||
if (loading == true) return -2;
|
||||
loading = true;
|
||||
notifyListeners();
|
||||
loading = true;
|
||||
notifyListeners();
|
||||
try {
|
||||
Response response = await ApiManager.instance.get(URLs.getPersonRoles);
|
||||
stateCode = response.statusCode;
|
||||
if (response.statusCode >= 200 && response.statusCode < 300) {
|
||||
// client's request was successfully received
|
||||
List categoriesListJson = json.decode(response.body)["data"];
|
||||
items = categoriesListJson.map((item) => Lookup.fromJson(item)).toList();
|
||||
}
|
||||
loading = false;
|
||||
notifyListeners();
|
||||
return response.statusCode;
|
||||
} catch (error) {
|
||||
loading = false;
|
||||
stateCode = -1;
|
||||
notifyListeners();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,151 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:fluttertoast/fluttertoast.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:test_sa/controllers/providers/api/user_provider.dart';
|
||||
import 'package:test_sa/extensions/context_extension.dart';
|
||||
import 'package:test_sa/extensions/int_extensions.dart';
|
||||
import 'package:test_sa/extensions/string_extensions.dart';
|
||||
import 'package:test_sa/extensions/text_extensions.dart';
|
||||
import 'package:test_sa/extensions/widget_extensions.dart';
|
||||
import 'package:test_sa/models/service_request/supp_engineer_work_orders.dart';
|
||||
import 'package:test_sa/models/service_request/supplier_engineer_model.dart';
|
||||
import 'package:test_sa/providers/work_order/supplier_engineer_provider.dart';
|
||||
|
||||
import '../../../../controllers/providers/api/service_requests_provider.dart';
|
||||
import '../../../../models/lookup.dart';
|
||||
import '../../../../new_views/app_style/app_color.dart';
|
||||
import '../../../../new_views/common_widgets/app_filled_button.dart';
|
||||
import '../../../../new_views/common_widgets/app_text_form_field.dart';
|
||||
import '../../../../new_views/common_widgets/single_item_drop_down_menu.dart';
|
||||
|
||||
class AddSupplierEngineerBottomSheet extends StatefulWidget {
|
||||
final int supplierId;
|
||||
|
||||
const AddSupplierEngineerBottomSheet(this.supplierId, {Key key}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<AddSupplierEngineerBottomSheet> createState() => _AddSupplierEngineerBottomSheetState();
|
||||
}
|
||||
|
||||
class _AddSupplierEngineerBottomSheetState extends State<AddSupplierEngineerBottomSheet> {
|
||||
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
|
||||
|
||||
Lookup suppEngRole;
|
||||
|
||||
SupplierEngineer engineer = SupplierEngineer();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
engineer.id = 0;
|
||||
engineer.supplierId = widget.supplierId;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final userProvider = Provider.of<UserProvider>(context, listen: false);
|
||||
return Wrap(
|
||||
children: [
|
||||
Container(
|
||||
clipBehavior: Clip.antiAlias,
|
||||
margin: EdgeInsets.only(bottom: MediaQuery.of(context).viewInsets.bottom),
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(context).scaffoldBackgroundColor,
|
||||
borderRadius: const BorderRadius.only(topRight: Radius.circular(20), topLeft: Radius.circular(20)),
|
||||
),
|
||||
padding: EdgeInsets.symmetric(horizontal: 16.toScreenWidth, vertical: 8.toScreenHeight),
|
||||
child: Form(
|
||||
key: _formKey,
|
||||
child: SingleChildScrollView(
|
||||
child: Column(
|
||||
children: [
|
||||
Container(
|
||||
width: 40.toScreenWidth,
|
||||
height: 5.toScreenHeight,
|
||||
decoration: BoxDecoration(color: AppColor.neutral40, borderRadius: BorderRadius.circular(30)),
|
||||
),
|
||||
Align(
|
||||
alignment: AlignmentDirectional.centerStart,
|
||||
child: "Add Engineer For Supplier".heading5(context).custom(fontWeight: FontWeight.w600).paddingOnly(top: 16, bottom: 16),
|
||||
),
|
||||
8.height,
|
||||
AppTextFormField(
|
||||
labelText: "Engineer Supplier Name".addTranslation,
|
||||
textInputType: TextInputType.name,
|
||||
onChange: (text) {
|
||||
engineer.personName = text.isEmpty ? null : text;
|
||||
},
|
||||
onSaved: (text) {
|
||||
engineer.personName = text.isEmpty ? null : text;
|
||||
},
|
||||
),
|
||||
8.height,
|
||||
SingleItemDropDownMenu<Lookup, SupplierEngineerProvider>(
|
||||
context: context,
|
||||
title: "Role",
|
||||
initialValue: suppEngRole,
|
||||
onSelect: (value) {
|
||||
if (value != null) {
|
||||
suppEngRole = value;
|
||||
}
|
||||
},
|
||||
),
|
||||
8.height,
|
||||
AppTextFormField(
|
||||
labelText: "Contact".addTranslation,
|
||||
textInputType: TextInputType.name,
|
||||
onChange: (text) {
|
||||
engineer.contact = text.isEmpty ? null : text;
|
||||
},
|
||||
onSaved: (text) {
|
||||
engineer.contact = text.isEmpty ? null : text;
|
||||
},
|
||||
),
|
||||
8.height,
|
||||
AppTextFormField(
|
||||
labelText: "Email".addTranslation,
|
||||
textInputType: TextInputType.name,
|
||||
onChange: (text) {
|
||||
engineer.email = text.isEmpty ? null : text;
|
||||
},
|
||||
onSaved: (text) {
|
||||
engineer.email = text.isEmpty ? null : text;
|
||||
},
|
||||
),
|
||||
8.height,
|
||||
16.height,
|
||||
Consumer<ServiceRequestsProvider>(
|
||||
builder: (context, snapshot, _) => AppFilledButton(
|
||||
label: context.translation.save,
|
||||
loading: snapshot.isLoading ?? false,
|
||||
onPressed: () async {
|
||||
_formKey.currentState.save();
|
||||
|
||||
if (engineer.personName.isEmpty) {
|
||||
"Engineer supplier name is empty".showToast;
|
||||
return;
|
||||
}
|
||||
|
||||
engineer.personRoleId = suppEngRole?.id;
|
||||
// print(engineer.toJson());
|
||||
// return;
|
||||
SuppEngineerWorkOrders suppEngineer = await snapshot.addSupplierEngineer(engineer);
|
||||
if (suppEngineer == null) {
|
||||
Fluttertoast.showToast(msg: "${context.translation.failedToCompleteRequest}");
|
||||
return;
|
||||
}
|
||||
Fluttertoast.showToast(msg: context.translation.successfulRequestMessage);
|
||||
Navigator.pop(context, suppEngineer);
|
||||
},
|
||||
),
|
||||
),
|
||||
16.height,
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue