Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class InsertRepairPage extends StatefulWidget {
- const InsertRepairPage({Key? key}) : super(key: key);
- @override
- State<InsertRepairPage> createState() => _InsertRepairPageState();
- }
- class _InsertRepairPageState extends State<InsertRepairPage> {
- final textControllerCode = TextEditingController();
- final textControllerCustomer = TextEditingController();
- final textControllerDataAcc = TextEditingController();
- final textControllerDataCons = TextEditingController();
- final textControllerUser = TextEditingController();
- final textControllerTechnician = TextEditingController();
- final textControllerObjects = TextEditingController();
- final textControllerToDoWorks = TextEditingController();
- final textControllerPcosto = TextEditingController();
- final textControllerRicambio1 = TextEditingController();
- final textControllerRicambio2 = TextEditingController();
- final textControllerRicambio3 = TextEditingController();
- final textControllerNote = TextEditingController();
- final textControllerPPubblico = TextEditingController();
- final DateTime _date = DateTime.now();
- final _formKeyScreen = GlobalKey<FormState>();
- XFile? picture;
- final bool _inWarranty = false;
- bool _formValid = false;
- @override
- void initState() {
- _codeRetrieve(context);
- BlocProvider.of<CustomerBloc>(context).add(CustomerEventInit());
- BlocProvider.of<UserCubit>(context).getAlluser();
- BlocProvider.of<TechnicianCubit>(context).getAlltechnician();
- picture = context.read();
- textControllerDataAcc.text = DateFormat('dd-MM-yyyy').format(_date);
- super.initState();
- }
- @override
- void dispose() {
- textControllerCode.dispose();
- textControllerCustomer.dispose();
- textControllerDataAcc.dispose();
- textControllerDataCons.dispose();
- textControllerUser.dispose();
- textControllerTechnician.dispose();
- textControllerObjects.dispose();
- textControllerToDoWorks.dispose();
- textControllerPcosto.dispose();
- textControllerRicambio1.dispose();
- textControllerRicambio2.dispose();
- textControllerRicambio3.dispose();
- textControllerNote.dispose();
- textControllerPPubblico.dispose();
- BlocProvider.of<CustomerBloc>(context).add(CustomerEventInit());
- super.dispose();
- }
- @override
- Widget build(BuildContext context) {
- double h = MediaQuery.of(context).size.height;
- double w = MediaQuery.of(context).size.width;
- return Scaffold(
- body: Form(
- key: _formKeyScreen,
- onChanged: (() {
- final isValid = _formKeyScreen.currentState?.validate() ?? false;
- setState(() {
- _formValid = isValid;
- });
- }),
- child: Padding(
- padding: const EdgeInsets.all(8.0),
- child: Column(
- children: [
- SizedBox(height: h * 0.01),
- Text(
- 'INSERIMENTO RIPARAZIONE',
- style: Theme.of(context).textTheme.headline2,
- ),
- SizedBox(height: h * 0.01),
- Padding(
- padding: const EdgeInsets.all(8.0),
- child: Row(children: [
- Expanded(
- flex: 2,
- child: Column(
- children: [
- Card(
- color: Theme.of(context).colorScheme.secondary,
- child: Padding(
- padding: const EdgeInsets.all(8.0),
- child: Column(
- children: [
- SizedBox(
- height: h * 0.03,
- ),
- Row(
- mainAxisAlignment: MainAxisAlignment.center,
- crossAxisAlignment:
- CrossAxisAlignment.center,
- children: [
- SizedBox(
- height: h * 0.1,
- width: w * 0.08,
- child: CustomTextFormField(
- txtLable: 'Codice Riparazione',
- enable: false,
- controller: textControllerCode,
- ),
- ),
- SizedBox(
- width: w * 0.03,
- ),
- SizedBox(
- height: h * 0.1,
- width: w * 0.12,
- child: customTextFieldAutocCustomer(
- context),
- ),
- ],
- ),
- SizedBox(
- height: h * 0.03,
- ),
- Container(
- padding: const EdgeInsets.all(10.0),
- decoration: BoxDecoration(
- borderRadius: const BorderRadius.all(
- Radius.circular(5)),
- border: Border.all(
- color: Colors.pink.shade50),
- ),
- child: Row(
- crossAxisAlignment:
- CrossAxisAlignment.center,
- mainAxisAlignment:
- MainAxisAlignment.center,
- children: [
- Column(
- crossAxisAlignment:
- CrossAxisAlignment.center,
- children: [
- SizedBox(
- height: h * 0.001,
- ),
- SizedBox(
- height: h * 0.01,
- ),
- SizedBox(
- height: h * 0.08,
- width: w * 0.11,
- child: DateWidget(
- controller:
- textControllerDataAcc,
- label: 'Accettazione'),
- ),
- SizedBox(
- height: h * 0.03,
- ),
- SizedBox(
- height: h * 0.06,
- width: w * 0.11,
- child: DateWidget(
- controller:
- textControllerDataCons,
- label: 'Consegna',
- )),
- SizedBox(
- height: h * 0.03,
- ),
- SizedBox(
- height: h * 0.09,
- width: w * 0.11,
- child: customTextFieldAutocUser(
- context)),
- SizedBox(
- height: h * 0.09,
- width: w * 0.11,
- child:
- customButtonDropDownTechnician(
- context, h),
- ),
- SizedBox(
- height: h * 0.03,
- //width: w * 0.11,
- child: Text(
- 'Garanzia',
- style: Theme.of(context)
- .textTheme
- .headline5,
- ),
- ),
- WarantyOrNot(
- w: w,
- h: h,
- warranty: _inWarranty),
- ],
- ),
- Padding(
- padding: const EdgeInsets.fromLTRB(
- 15, 20, 0, 0),
- child: Column(
- mainAxisAlignment:
- MainAxisAlignment.center,
- crossAxisAlignment:
- CrossAxisAlignment.center,
- children: [
- SizedBox(
- height: h * 0.35,
- width: w * 0.20,
- child: Card(
- semanticContainer: true,
- clipBehavior: Clip
- .antiAliasWithSaveLayer,
- shape:
- RoundedRectangleBorder(
- borderRadius:
- BorderRadius.circular(
- 10.0),
- ),
- elevation: 5,
- margin:
- const EdgeInsets.all(
- 10),
- child: picture != null
- ? Image.file(
- File(picture!.path))
- : const SizedBox
- .shrink(),
- ),
- ),
- SizedBox(
- height: h * 0.03,
- ),
- //Image.file(File(picture.path), fit: BoxFit.cover, width: 250),
- SizedBox(
- height: h * 0.08,
- width: w * 0.09,
- child:
- _takePhotoButton(context),
- )
- ]),
- ),
- ],
- ),
- ),
- SizedBox(
- height: h * 0.05,
- ),
- ],
- ),
- )),
- ],
- ),
- ),
- Expanded(
- flex: 2,
- child: CentralColumn(
- h: h,
- w: w,
- textControllerObjects: textControllerObjects,
- textControllerToDoWorks: textControllerToDoWorks,
- )),
- Expanded(
- flex: 1,
- child: RightColumn(
- h: h,
- w: w,
- textControllerPcosto: textControllerPcosto,
- textControllerRicambio1: textControllerRicambio1,
- textControllerRicambio2: textControllerRicambio2,
- textControllerRicambio3: textControllerRicambio3,
- textControllerNote: textControllerNote,
- textControllerPPubblico: textControllerPPubblico,
- ))
- ]),
- ),
- Card(
- color: Theme.of(context).colorScheme.secondary,
- child: Padding(
- padding: const EdgeInsets.all(8.0),
- child: Row(
- mainAxisAlignment: MainAxisAlignment.center,
- children: [
- SizedBox(
- height: h * 0.08,
- width: w * 0.09,
- child: _exitButton(context),
- ),
- SizedBox(
- width: w * 0.03,
- ),
- SizedBox(
- height: h * 0.08,
- width: w * 0.09,
- child: _saveButton(context),
- )
- ],
- )))
- ],
- ),
- ),
- ),
- );
- }
- _codeRetrieve(BuildContext context) async {
- final id_repair = await context.read<RepairRepository>().getIdRepair();
- final int addOne = int.parse(id_repair.id_repair.toString()) + 1;
- textControllerCode.text = addOne.toString();
- }
- Widget _takePhotoButton(
- BuildContext context, {
- bool loading = false,
- }) {
- return SizedBox(
- child: ElevatedButton(
- style: ElevatedButton.styleFrom(
- shape: RoundedRectangleBorder(
- borderRadius: BorderRadius.circular(12))),
- onPressed: () => _navigationCamera(context),
- child: const Text(
- 'Foto',
- style: TextStyle(
- fontSize: 19, fontFamily: 'PT Serif', color: Colors.white),
- )),
- );
- }
- Widget _saveButton(
- BuildContext context, {
- bool loading = false,
- }) {
- double h = MediaQuery.of(context).size.height;
- double w = MediaQuery.of(context).size.width;
- return SizedBox(
- height: h * 0.10,
- width: w * 0.15,
- child: ElevatedButton(
- style: ElevatedButton.styleFrom(
- shape: RoundedRectangleBorder(
- borderRadius: BorderRadius.circular(12))),
- onPressed: _formValid
- ? () {
- //_saveUpdateData(context);
- //_cleanTextField();
- // _formKeyScreen.currentState?.reset();
- }
- : null,
- child: !loading
- ? const Text(
- 'Salva',
- style: TextStyle(
- fontSize: 30, fontFamily: 'PT Serif', color: Colors.white),
- )
- : SizedBox(
- height: h * 0.15,
- width: w * 10,
- child: const CircularProgressIndicator(color: Colors.white),
- ),
- ),
- );
- }
- _exitButton(
- BuildContext context, {
- bool loading = false,
- }) {
- double h = MediaQuery.of(context).size.height;
- double w = MediaQuery.of(context).size.width;
- return SizedBox(
- height: h * 0.10,
- width: w * 0.15,
- child: ElevatedButton(
- style: ElevatedButton.styleFrom(
- shape: RoundedRectangleBorder(
- borderRadius: BorderRadius.circular(12))),
- onPressed: (() {
- Get.back();
- //BlocProvider.of<CustomerBloc>(context).add(CustomerEventInit());
- }),
- child: !loading
- ? const Text(
- 'Esci',
- style: TextStyle(
- fontSize: 30, fontFamily: 'PT Serif', color: Colors.white),
- )
- : SizedBox(
- height: h * 0.15,
- width: w * 10,
- child: const CircularProgressIndicator(color: Colors.white),
- ),
- ),
- );
- }
- customTextFieldAutocCustomer(BuildContext context) {
- return BlocBuilder<CustomerBloc, CustomerState>(
- builder: (context, state) {
- if (state is CustomerLoadingState) {
- return const Center(
- child: CircularProgressIndicator(),
- );
- }
- if (state is CustomerGetAllLoadedState) {
- return EasyAutocomplete(
- controller: textControllerCustomer,
- //initialValue: '',
- decoration: InputDecoration(
- //errorText: _errorText(),
- label: const Text('Cliente'),
- contentPadding:
- const EdgeInsets.symmetric(vertical: 0, horizontal: 10),
- focusedBorder: OutlineInputBorder(
- borderRadius: BorderRadius.circular(5),
- borderSide:
- BorderSide(color: Theme.of(context).primaryColor)),
- enabledBorder: OutlineInputBorder(
- borderRadius: BorderRadius.circular(5),
- borderSide: BorderSide(
- color: Theme.of(context).primaryColor,
- style: BorderStyle.solid))),
- suggestionBuilder: (data) {
- return Container(
- margin: const EdgeInsets.all(1),
- padding: const EdgeInsets.all(5),
- decoration: BoxDecoration(
- color: Theme.of(context).primaryColor,
- borderRadius: BorderRadius.circular(5)),
- child: Text(data,
- style: Theme.of(context).textTheme.headline3));
- },
- suggestions:
- state.customers.map((e) => e.name.toString()).toList(),
- //focusNode: _focusNodeId,
- onChanged: (value) {
- // if (value.length < 3 || _clientController.text.l) {}
- if (value.length > 3 ||
- state.customers.map((e) => e.name).contains(value)) {
- print('il valore e presente nella lista');
- }
- if (value.length > 3 &&
- !state.customers.map((e) => e.name).contains(value)) {
- print('il valore non e presente nella lista devi inserirlo');
- showDialog(
- context: context,
- builder: (BuildContext context) => AlertDialog(
- title: const Text(
- 'Cliente non trovato vuoi registrarlo?'),
- actions: [
- TextButton(
- onPressed: () {
- Navigator.of(context).pop();
- //_ceck = true;
- },
- child: const Text('NO')),
- TextButton(
- onPressed: (() {
- _navigateToClient(context);
- }),
- child: const Text('SI'))
- ],
- ));
- }
- //repair.copyWith(nameClient: value);
- });
- } else {
- return const SizedBox();
- }
- },
- );
- }
- customTextFieldAutocUser(BuildContext context) {
- return BlocBuilder<UserCubit, UserState>(
- builder: (context, state) {
- if (state is UserLoading) {
- return const Center(
- child: CircularProgressIndicator(),
- );
- }
- if (state is UsersLoaded) {
- return EasyAutocomplete(
- controller: textControllerUser,
- //initialValue: '',
- decoration: InputDecoration(
- //errorText: _errorText(),
- label: const Text('Utente'),
- contentPadding:
- const EdgeInsets.symmetric(vertical: 0, horizontal: 10),
- focusedBorder: OutlineInputBorder(
- borderRadius: BorderRadius.circular(5),
- borderSide:
- BorderSide(color: Theme.of(context).primaryColor)),
- enabledBorder: OutlineInputBorder(
- borderRadius: BorderRadius.circular(5),
- borderSide: BorderSide(
- color: Theme.of(context).primaryColor,
- style: BorderStyle.solid))),
- suggestionBuilder: (data) {
- return Container(
- margin: const EdgeInsets.all(1),
- padding: const EdgeInsets.all(5),
- decoration: BoxDecoration(
- color: Theme.of(context).primaryColor,
- borderRadius: BorderRadius.circular(5)),
- child: Text(data,
- style: Theme.of(context).textTheme.headline3));
- },
- suggestions:
- state.users.map((e) => e.username.toString()).toList(),
- //focusNode: _focusNodeId,
- onChanged: (value) {
- // if (value.length < 3 || _clientController.text.l) {}
- if (value.length > 3 ||
- state.users.map((e) => e.username).contains(value)) {
- print('il valore e presente nella lista');
- }
- //repair.copyWith(nameClient: value);
- });
- } else {
- return const SizedBox();
- }
- },
- );
- }
- customButtonDropDownTechnician(BuildContext context, double h) {
- //final double h;
- return BlocBuilder<TechnicianCubit, TechnicianState>(
- builder: (context, state) {
- if (state is TechnicianLoading) {
- return const Center(
- child: CircularProgressIndicator(),
- );
- }
- if (state is TechnicianLoaded) {
- return DropdownButtonFormField2(
- buttonDecoration: BoxDecoration(
- borderRadius: BorderRadius.circular(8),
- border: Border.all(
- color: Color.fromARGB(66, 59, 106, 181),
- ),
- color: Color.fromARGB(255, 240, 249, 251),
- ),
- decoration: InputDecoration(
- //Add isDense true and zero Padding.
- //Add Horizontal padding using buttonPadding and Vertical padding by increasing buttonHeight instead of add Padding here so that The whole TextField Button become clickable, and also the dropdown menu open under The whole TextField Button.
- fillColor: Colors.amber,
- isDense: true,
- contentPadding: EdgeInsets.zero,
- border: OutlineInputBorder(
- borderRadius: BorderRadius.circular(8),
- )),
- dropdownDecoration: BoxDecoration(
- borderRadius: BorderRadius.circular(8),
- color: Color.fromARGB(255, 175, 212, 231)),
- isExpanded: true,
- hint: const Text(
- 'Tecnico',
- style: TextStyle(fontSize: 12),
- ),
- icon: const Icon(
- Icons.arrow_drop_down,
- color: Colors.black45,
- ),
- iconSize: 30,
- buttonHeight: h * 0.066,
- buttonPadding: const EdgeInsets.only(left: 30, right: 10),
- items: state.technicians
- .map((item) => DropdownMenuItem<String>(
- value: item.name,
- child: Text(
- item.name,
- style: const TextStyle(
- fontSize: 14,
- ),
- ),
- ))
- .toList(),
- onChanged: (value) {
- //Do something when changing the item if you want.
- });
- /* EasyAutocomplete(
- controller: textControllerTechnician,
- //initialValue: '',
- decoration: InputDecoration(
- //errorText: _errorText(),
- label: const Text('Tecnico'),
- contentPadding:
- const EdgeInsets.symmetric(vertical: 0, horizontal: 10),
- focusedBorder: OutlineInputBorder(
- borderRadius: BorderRadius.circular(5),
- borderSide:
- BorderSide(color: Theme.of(context).primaryColor)),
- enabledBorder: OutlineInputBorder(
- borderRadius: BorderRadius.circular(5),
- borderSide: BorderSide(
- color: Theme.of(context).primaryColor,
- style: BorderStyle.solid))),
- suggestionBuilder: (data) {
- return Container(
- margin: const EdgeInsets.all(1),
- padding: const EdgeInsets.all(5),
- decoration: BoxDecoration(
- color: Theme.of(context).primaryColor,
- borderRadius: BorderRadius.circular(5)),
- child: Text(data,
- style: Theme.of(context).textTheme.headline3));
- },
- suggestions:
- state.technicians.map((e) => e.name.toString()).toList(),
- //focusNode: _focusNodeId,
- onChanged: (value) {
- // if (value.length < 3 || _clientController.text.l) {}
- if (value.length > 3 ||
- state.technicians.map((e) => e.name).contains(value)) {
- print('il valore e presente nella lista');
- }
- //repair.copyWith(nameClient: value);
- });
- */
- } else {
- return const SizedBox(
- child: Text('Errore nel caricamento dati'),
- );
- }
- },
- );
- }
- // method to call camera that return photo from cameraPage
- Future<void> _navigationCamera(BuildContext context) async {
- final result = await availableCameras().then((value) => Navigator.push(
- context,
- MaterialPageRoute(builder: (context) => CameraPage(cameras: value))));
- if (!mounted) return null;
- setState(() {
- picture = result;
- });
- }
- Future<void> _navigateToClient(BuildContext context) async {
- Navigator.pop(context);
- final result = await Navigator.push(context,
- MaterialPageRoute(builder: ((context) => const CustomerPage())));
- if (result == 'Saved') {
- textControllerCustomer.clear();
- setState(() {
- BlocProvider.of<CustomerBloc>(context).add(CustomerEventInit());
- });
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement