horario fixed
This commit is contained in:
@@ -0,0 +1,139 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
typedef TimeCallback = void Function(TimeOfDay? pickedTime);
|
||||||
|
|
||||||
|
class SchedulePicker extends StatefulWidget {
|
||||||
|
final String name;
|
||||||
|
Schedule schedule;
|
||||||
|
|
||||||
|
SchedulePicker({super.key, required this.name, required this.schedule});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<SchedulePicker> createState() => _SchedulePickerState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _SchedulePickerState extends State<SchedulePicker> {
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Column(
|
||||||
|
children: [
|
||||||
|
customSwitch(widget.name, widget.schedule.habilitado, (value) {
|
||||||
|
widget.schedule.habilitado = value;
|
||||||
|
}),
|
||||||
|
...datePickers(widget.schedule.habilitado),
|
||||||
|
const Divider(
|
||||||
|
height: 15,
|
||||||
|
color: Colors.grey,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Widget> datePickers(bool lunesValue) {
|
||||||
|
if (!lunesValue) return [];
|
||||||
|
return [
|
||||||
|
customSwitch(
|
||||||
|
'Jornada continua',
|
||||||
|
widget.schedule.jornadaContinua,
|
||||||
|
(value) {
|
||||||
|
widget.schedule.jornadaContinua = value;
|
||||||
|
},
|
||||||
|
),
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 25),
|
||||||
|
child: Row(children: [
|
||||||
|
datePicker(widget.schedule.range1Hour1,
|
||||||
|
(pickedTime) => widget.schedule.range1Hour1 = pickedTime),
|
||||||
|
const Text('-'),
|
||||||
|
...(!widget.schedule.jornadaContinua
|
||||||
|
? [
|
||||||
|
datePicker(widget.schedule.range1Hour2,
|
||||||
|
(pickedTime) => widget.schedule.range1Hour2 = pickedTime),
|
||||||
|
const Text(' '),
|
||||||
|
]
|
||||||
|
: []),
|
||||||
|
...(!widget.schedule.jornadaContinua
|
||||||
|
? [
|
||||||
|
datePicker(widget.schedule.range2Hour1,
|
||||||
|
(pickedTime) => widget.schedule.range2Hour1 = pickedTime),
|
||||||
|
const Text('-'),
|
||||||
|
]
|
||||||
|
: []),
|
||||||
|
datePicker(widget.schedule.range1Hour2,
|
||||||
|
(pickedTime) => widget.schedule.range1Hour2 = pickedTime),
|
||||||
|
]),
|
||||||
|
)
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
datePicker(TimeOfDay? time, TimeCallback callback) {
|
||||||
|
return Expanded(
|
||||||
|
child: TextFormField(
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
onTap: () async {
|
||||||
|
final TimeOfDay? pickedTime = await showTimePicker(
|
||||||
|
context: context,
|
||||||
|
initialTime: TimeOfDay.now(),
|
||||||
|
);
|
||||||
|
if (pickedTime != null) {
|
||||||
|
setState(() {
|
||||||
|
callback(pickedTime);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
readOnly: true,
|
||||||
|
decoration: const InputDecoration(
|
||||||
|
hintText: 'Hora',
|
||||||
|
),
|
||||||
|
controller: TextEditingController(
|
||||||
|
text: time == null ? '' : time.format(context),
|
||||||
|
),
|
||||||
|
style: const TextStyle(fontSize: 15),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
customSwitch(String text, bool switchValue, ValueChanged<bool> onChanged) {
|
||||||
|
return Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 30),
|
||||||
|
child: SizedBox(
|
||||||
|
height: 40,
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
Expanded(
|
||||||
|
child: Text(
|
||||||
|
text,
|
||||||
|
style: const TextStyle(
|
||||||
|
fontSize: 15,
|
||||||
|
color: Colors.black,
|
||||||
|
),
|
||||||
|
)),
|
||||||
|
Transform.scale(
|
||||||
|
scale: 1.2,
|
||||||
|
child: Switch(
|
||||||
|
value: switchValue,
|
||||||
|
onChanged: (bool newValue) {
|
||||||
|
setState(() {
|
||||||
|
onChanged(newValue);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Schedule {
|
||||||
|
bool habilitado;
|
||||||
|
bool jornadaContinua;
|
||||||
|
TimeOfDay? range1Hour1 = TimeOfDay.now();
|
||||||
|
TimeOfDay? range1Hour2 = TimeOfDay.now();
|
||||||
|
TimeOfDay? range2Hour1 = TimeOfDay.now();
|
||||||
|
TimeOfDay? range2Hour2 = TimeOfDay.now();
|
||||||
|
|
||||||
|
Schedule(this.habilitado, this.jornadaContinua, this.range1Hour1,
|
||||||
|
this.range1Hour2, this.range2Hour1, this.range2Hour2);
|
||||||
|
}
|
||||||
+20
-169
@@ -1,7 +1,8 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_animate/flutter_animate.dart';
|
|
||||||
import 'package:prosappco/src/components/pop_appbar.dart';
|
import 'package:prosappco/src/components/pop_appbar.dart';
|
||||||
|
|
||||||
|
import '../components/schedule_picker.dart';
|
||||||
|
|
||||||
class HorarioScreen extends StatefulWidget {
|
class HorarioScreen extends StatefulWidget {
|
||||||
const HorarioScreen({super.key});
|
const HorarioScreen({super.key});
|
||||||
|
|
||||||
@@ -19,22 +20,15 @@ class _HorarioScreenState extends State<HorarioScreen> {
|
|||||||
bool domingoValue = false;
|
bool domingoValue = false;
|
||||||
bool jornadaContinuaLunes = false;
|
bool jornadaContinuaLunes = false;
|
||||||
|
|
||||||
TimeOfDay? _selectedTime;
|
Map<String, Schedule> horarios = {
|
||||||
|
"Lunes": Schedule(true, false, null, null, null, null),
|
||||||
Future<void> _selectTime(BuildContext context) async {
|
"Martes": Schedule(false, false, null, null, null, null),
|
||||||
final TimeOfDay? pickedTime = await showTimePicker(
|
"Miercoles": Schedule(false, false, null, null, null, null),
|
||||||
context: context,
|
"Jueves": Schedule(false, false, null, null, null, null),
|
||||||
initialTime: TimeOfDay.now(),
|
"Viernes": Schedule(false, false, null, null, null, null),
|
||||||
// builder: (context, child) {
|
"Sabado": Schedule(false, false, null, null, null, null),
|
||||||
// return Theme(data: ThemeData.dark(), child: child!);
|
"Domingo": Schedule(false, false, null, null, null, null),
|
||||||
// },
|
};
|
||||||
);
|
|
||||||
if (pickedTime != null) {
|
|
||||||
setState(() {
|
|
||||||
_selectedTime = pickedTime;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
@@ -46,159 +40,16 @@ class _HorarioScreenState extends State<HorarioScreen> {
|
|||||||
},
|
},
|
||||||
label: 'Horario'),
|
label: 'Horario'),
|
||||||
body: SingleChildScrollView(
|
body: SingleChildScrollView(
|
||||||
child: Column(children: [
|
child: Column(
|
||||||
const Divider(color: Colors.white, height: 10),
|
children: horarios.entries.map<Widget>(
|
||||||
customSwitch(
|
(entry) {
|
||||||
'Lunes',
|
return SchedulePicker(
|
||||||
lunesValue,
|
name: entry.key,
|
||||||
(value) {
|
schedule: entry.value,
|
||||||
lunesValue = value;
|
);
|
||||||
},
|
},
|
||||||
),
|
).toList(),
|
||||||
lunesValue
|
),
|
||||||
? Column(
|
|
||||||
children: [
|
|
||||||
customSwitch(
|
|
||||||
'Jornada continua',
|
|
||||||
jornadaContinuaLunes,
|
|
||||||
(value) {
|
|
||||||
jornadaContinuaLunes = value;
|
|
||||||
},
|
|
||||||
),
|
|
||||||
Padding(
|
|
||||||
padding: const EdgeInsets.only(left: 30, bottom: 15),
|
|
||||||
child: Column(
|
|
||||||
children: [
|
|
||||||
Row(
|
|
||||||
children: [
|
|
||||||
Expanded(
|
|
||||||
child: TextFormField(
|
|
||||||
onTap: () {
|
|
||||||
_selectTime(context);
|
|
||||||
},
|
|
||||||
readOnly: true,
|
|
||||||
decoration: const InputDecoration(
|
|
||||||
hintText: 'Hora',
|
|
||||||
),
|
|
||||||
controller: TextEditingController(
|
|
||||||
text: _selectedTime == null
|
|
||||||
? ''
|
|
||||||
: ' ${_selectedTime!.format(context)}',
|
|
||||||
),
|
|
||||||
style: const TextStyle(fontSize: 15),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const Text(' - '),
|
|
||||||
SizedBox(
|
|
||||||
width: 80,
|
|
||||||
child: TextFormField(
|
|
||||||
onTap: () {
|
|
||||||
_selectTime(context);
|
|
||||||
},
|
|
||||||
readOnly: true,
|
|
||||||
decoration: const InputDecoration(
|
|
||||||
hintText: 'Hora',
|
|
||||||
),
|
|
||||||
controller: TextEditingController(
|
|
||||||
text: _selectedTime == null
|
|
||||||
? ''
|
|
||||||
: ' ${_selectedTime!.format(context)}'),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const Text(' - '),
|
|
||||||
SizedBox(
|
|
||||||
width: 80,
|
|
||||||
child: TextFormField(
|
|
||||||
onTap: () {
|
|
||||||
_selectTime(context);
|
|
||||||
},
|
|
||||||
readOnly: true,
|
|
||||||
decoration: const InputDecoration(
|
|
||||||
hintText: 'Hora',
|
|
||||||
),
|
|
||||||
controller: TextEditingController(
|
|
||||||
text: _selectedTime == null
|
|
||||||
? ''
|
|
||||||
: ' ${_selectedTime!.format(context)}'),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const Text(' - '),
|
|
||||||
SizedBox(
|
|
||||||
width: 80,
|
|
||||||
child: TextFormField(
|
|
||||||
onTap: () {
|
|
||||||
_selectTime(context);
|
|
||||||
},
|
|
||||||
readOnly: true,
|
|
||||||
decoration: const InputDecoration(
|
|
||||||
hintText: 'Hora',
|
|
||||||
),
|
|
||||||
controller: TextEditingController(
|
|
||||||
text: _selectedTime == null
|
|
||||||
? ''
|
|
||||||
: ' ${_selectedTime!.format(context)}'),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
).animate().moveY(
|
|
||||||
duration: const Duration(milliseconds: 100)),
|
|
||||||
],
|
|
||||||
)
|
|
||||||
.animate()
|
|
||||||
.moveY(duration: const Duration(milliseconds: 100)),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
)
|
|
||||||
: const SizedBox(),
|
|
||||||
const Divider(height: 10),
|
|
||||||
customSwitch(
|
|
||||||
'Martes',
|
|
||||||
martesValue,
|
|
||||||
(value) {
|
|
||||||
martesValue = value;
|
|
||||||
},
|
|
||||||
),
|
|
||||||
const Divider(height: 10),
|
|
||||||
customSwitch(
|
|
||||||
'Miercoles',
|
|
||||||
miercolesValue,
|
|
||||||
(value) {
|
|
||||||
miercolesValue = value;
|
|
||||||
},
|
|
||||||
),
|
|
||||||
const Divider(height: 10),
|
|
||||||
customSwitch(
|
|
||||||
'Jueves',
|
|
||||||
juevesValue,
|
|
||||||
(value) {
|
|
||||||
juevesValue = value;
|
|
||||||
},
|
|
||||||
),
|
|
||||||
const Divider(height: 10),
|
|
||||||
customSwitch(
|
|
||||||
'Viernes',
|
|
||||||
viernesValue,
|
|
||||||
(value) {
|
|
||||||
viernesValue = value;
|
|
||||||
},
|
|
||||||
),
|
|
||||||
const Divider(height: 10),
|
|
||||||
customSwitch(
|
|
||||||
'Sabado',
|
|
||||||
sabadoValue,
|
|
||||||
(value) {
|
|
||||||
sabadoValue = value;
|
|
||||||
},
|
|
||||||
),
|
|
||||||
const Divider(height: 10),
|
|
||||||
customSwitch(
|
|
||||||
'Domingo',
|
|
||||||
domingoValue,
|
|
||||||
(value) {
|
|
||||||
domingoValue = value;
|
|
||||||
},
|
|
||||||
),
|
|
||||||
]),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user