diff --git a/lib/Controller/HabitoController.dart b/lib/Controller/HabitoController.dart index 44e74e4..a369811 100644 --- a/lib/Controller/HabitoController.dart +++ b/lib/Controller/HabitoController.dart @@ -17,17 +17,19 @@ class HabitoController extends Base { //var loginConfiguracoes = LoginConfiguracoes(); habitoId(int? value) => model.id = value; + habitoIdRotina(int? value) => model.idRotina = value; habitoNome(String? value) => model.nome = value.toString(); - habitoDataehora(String? value) => - {print('dfasfa ' + (value ?? '')), model.data = value.toString()}; + habitoDataehora(String? value) => model.data = value.toString(); habitoDias(List? value) => model.dias = value!.cast(); habitoCor(String? value) => model.cor = value.toString(); + habitoDataFinal(String? value) => model.dataFinal = value.toString(); var controllerNome = TextEditingController(); var controllerDias = TextEditingController(); var controllerPrioridade = TextEditingController(); var controllerCor = TextEditingController(); var controllerDataehora = TextEditingController(); + var controllerDataFinal = TextEditingController(); Future saveHabito() async { if (!formKey.currentState!.validate()) { diff --git a/lib/Model/Habito/HabitoModel.dart b/lib/Model/Habito/HabitoModel.dart index bf120a5..fcc5836 100644 --- a/lib/Model/Habito/HabitoModel.dart +++ b/lib/Model/Habito/HabitoModel.dart @@ -3,29 +3,42 @@ import 'package:organizei/Model/Generica.dart'; class HabitoModel extends GenericaModel { int? id; + int? idRotina; String? nome; String? data; + String? dataFinal; List? dias; String? cor; ResponseAPIModel? responseAPIModel; - HabitoModel({this.id, this.nome, this.data, this.dias, this.cor}); + HabitoModel( + {this.id, + this.nome, + this.data, + this.dias, + this.cor, + this.idRotina, + this.dataFinal}); HabitoModel.fromJson(Map json) { id = int.parse(json['id']); + idRotina = int.parse(json['idRotina']); nome = json['nome']; data = json['hora']; dias = json['dias']; cor = json['cor']; + dataFinal = json['dataFinal']; } Map toJson() { final Map data = new Map(); - data['id'] = this.id; - data['nome'] = this.nome; - data['hora'] = this.data; - data['dias'] = this.dias; - data['cor'] = this.cor; + data['idRotina'] = idRotina; + data['id'] = id; + data['nome'] = nome; + data['hora'] = data; + data['dias'] = dias; + data['cor'] = cor; + data['dataFinal'] = dataFinal; return data; } diff --git a/lib/Repository/HabitoRepository.dart b/lib/Repository/HabitoRepository.dart index 474f6f0..800a5ed 100644 --- a/lib/Repository/HabitoRepository.dart +++ b/lib/Repository/HabitoRepository.dart @@ -13,6 +13,7 @@ class HabitoRepository { "hora": model.data, "dias": model.dias, "cor": model.cor, + "dataFinal": model.dataFinal, }; final response = await http.post(Uri.parse(ApiModel.ApiUrl + '/habitos'), @@ -27,6 +28,7 @@ class HabitoRepository { "hora": model.data, "dias": model.dias, "cor": model.cor, + "dataFinal": model.dataFinal, }; final response = await http.put( @@ -44,8 +46,10 @@ class HabitoRepository { }; final response = await http.put( - Uri.parse( - ApiModel.ApiUrl + '/habitos/' + model.id.toString() + '/concluir'), + Uri.parse(ApiModel.ApiUrl + + '/habitos/' + + model.idRotina.toString() + + '/concluir'), headers: ApiModel.headers, body: jsonEncode(json)); diff --git a/lib/Repository/LoginRepository.dart b/lib/Repository/LoginRepository.dart index 147db6b..f7ce278 100644 --- a/lib/Repository/LoginRepository.dart +++ b/lib/Repository/LoginRepository.dart @@ -26,7 +26,6 @@ class LoginRepository { final dadosLogin = ResponseAPIModel.fromJson(jsonDecode(response.body)); prefs.setString('UsuarioApelido', dadosLogin.msg.toString()); - print(dadosLogin.msg.toString()); return true; } diff --git a/lib/components/dialogs/habitos/habitoCadastroDialog.dart b/lib/components/dialogs/habitos/habitoCadastroDialog.dart index 0b07fd4..e8327c8 100644 --- a/lib/components/dialogs/habitos/habitoCadastroDialog.dart +++ b/lib/components/dialogs/habitos/habitoCadastroDialog.dart @@ -18,6 +18,8 @@ Future criarHabito(BuildContext context, if (habito != null) { habitoController.controllerNome.text = habito.nome ?? ''; habitoController.controllerDataehora.text = habito.data ?? ''; + habitoController.controllerDataFinal.text = + habito.dataFinal!.substring(0, 10); habitoController.controllerDias.text = habito.dias.toString(); habitoController.habitoCor(habito.cor); habitoController.habitoId(habito.id); @@ -39,7 +41,7 @@ Future criarHabito(BuildContext context, key: habitoController.formKey, child: Container( margin: const EdgeInsets.only(top: 24), - height: MediaQuery.of(context).size.height, + //height: MediaQuery.of(context).size.height, child: DialogPersonalizado( nome: 'Hábito', child: [ @@ -54,12 +56,20 @@ Future criarHabito(BuildContext context, SelectData( controller: habitoController.controllerDataehora, onSaved: habitoController.habitoDataehora, - apenasHora: true, + tipo: 'hora', + label: 'hora', ), SelectDia( - dia: habitoController.habitoDias, - diaAtual: habito?.dias ?? - ['0', '0', '0', '0', '0', '0', '0']), + dia: habitoController.habitoDias, + diaAtual: habito?.dias ?? + ['0', '0', '0', '0', '0', '0', '0'], + ), + SelectData( + controller: habitoController.controllerDataFinal, + onSaved: habitoController.habitoDataFinal, + tipo: 'data', + label: 'repetir até quanto?', + ), SelectCor( cor: habitoController.habitoCor, corAtual: habito?.cor ?? ''), diff --git a/lib/components/dialogs/habitos/habitoDialog.dart b/lib/components/dialogs/habitos/habitoDialog.dart index 100a1e2..abc9db3 100644 --- a/lib/components/dialogs/habitos/habitoDialog.dart +++ b/lib/components/dialogs/habitos/habitoDialog.dart @@ -12,6 +12,7 @@ Future visualizarHabito(BuildContext context, habitoController = HabitoController(HabitoRepository(), context); habitoController.habitoId(habito.id); + habitoController.habitoIdRotina(habito.idRotina); return showDialog( barrierDismissible: false, diff --git a/lib/components/selectData.dart b/lib/components/selectData.dart index 446845c..42ebae3 100644 --- a/lib/components/selectData.dart +++ b/lib/components/selectData.dart @@ -6,12 +6,14 @@ import 'package:intl/intl.dart' as intl; class SelectData extends StatefulWidget { final dynamic onSaved; final TextEditingController? controller; - final bool? apenasHora; + final String? tipo; + final String label; const SelectData( {Key? key, required this.onSaved, this.controller, - this.apenasHora = false}) + this.tipo = 'dataHora', + this.label = 'data e hora'}) : super(key: key); @override @@ -21,7 +23,7 @@ class SelectData extends StatefulWidget { class _SelectDataState extends State { @override Widget build(BuildContext context) { - if (widget.controller!.text.length > 6 && widget.apenasHora!) { + if (widget.controller!.text.length > 6 && widget.tipo! == 'hora') { widget.controller!.text = widget.controller!.text.substring(11); } return Padding( @@ -31,7 +33,7 @@ class _SelectDataState extends State { crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( - widget.apenasHora == true ? 'hora' : 'data e hora', + widget.label, style: const TextStyle( color: Colors.black, fontSize: 16, @@ -44,8 +46,10 @@ class _SelectDataState extends State { onTap: () async { DateTime date = new DateTime.now(); - if (widget.apenasHora == false) { - DateTime? newDate = await showDatePicker( + DateTime? newDate; + + if (widget.tipo != 'hora') { + newDate = await showDatePicker( context: context, initialDate: date, firstDate: DateTime(2020), @@ -73,81 +77,94 @@ class _SelectDataState extends State { if (newDate == null) return; - final time = await showTimePicker( - context: context, - initialTime: - TimeOfDay(hour: date.hour, minute: date.minute), - builder: (BuildContext context, child) { - return Theme( - data: ThemeData.light().copyWith( - timePickerTheme: TimePickerThemeData( - shape: RoundedRectangleBorder( - side: const BorderSide( - width: 3, color: Colors.black), - borderRadius: BorderRadius.circular(16.0), - ), - backgroundColor: const Color(0xFFE9E9E9), - hourMinuteColor: - MaterialStateColor.resolveWith((states) => - states.contains( - MaterialState.selected) - ? const Color(0xFFE9E9E9) - : const Color(0xFFE9E9E9)), - dialHandColor: Color(0xFFE9E9E9), - dialTextColor: MaterialStateColor.resolveWith( - (states) => states - .contains(MaterialState.selected) - ? Colors.black - : Colors.black), - hourMinuteTextColor: - MaterialStateColor.resolveWith((states) => - states.contains( - MaterialState.selected) - ? const Color(0xFF6385C3) - : Colors.black), - dialBackgroundColor: const Color(0xFF6385C3), - ), - textButtonTheme: TextButtonThemeData( - style: ButtonStyle( - foregroundColor: + setState(() { + date = newDate!; + }); + + widget.controller!.text = + intl.DateFormat('dd/MM/yyyy').format(newDate); + + widget.onSaved(newDate.toString()); + + if (widget.tipo != 'data') { + final time = await showTimePicker( + context: context, + initialTime: + TimeOfDay(hour: date.hour, minute: date.minute), + builder: (BuildContext context, child) { + return Theme( + data: ThemeData.light().copyWith( + timePickerTheme: TimePickerThemeData( + shape: RoundedRectangleBorder( + side: const BorderSide( + width: 3, color: Colors.black), + borderRadius: BorderRadius.circular(16.0), + ), + backgroundColor: const Color(0xFFE9E9E9), + hourMinuteColor: MaterialStateColor.resolveWith( - (states) => - const Color(0xFF6385C3)), - overlayColor: + (states) => states.contains( + MaterialState.selected) + ? const Color(0xFFE9E9E9) + : const Color(0xFFE9E9E9)), + dialHandColor: Color(0xFFE9E9E9), + dialTextColor: MaterialStateColor.resolveWith( - (states) => const Color(0xFF6385C3), + (states) => states.contains( + MaterialState.selected) + ? Colors.black + : Colors.black), + hourMinuteTextColor: + MaterialStateColor.resolveWith( + (states) => states.contains( + MaterialState.selected) + ? const Color(0xFF6385C3) + : Colors.black), + dialBackgroundColor: + const Color(0xFF6385C3), + ), + textButtonTheme: TextButtonThemeData( + style: ButtonStyle( + foregroundColor: + MaterialStateColor.resolveWith( + (states) => + const Color(0xFF6385C3)), + overlayColor: + MaterialStateColor.resolveWith( + (states) => const Color(0xFF6385C3), + ), ), ), ), - ), - child: child!, - ); - }); + child: child!, + ); + }); - if (time == null) return; + if (time == null) return; - final newDateTime = DateTime( - newDate.year, - newDate.month, - newDate.day, - time.hour, - time.minute, - ); + final newDateTime = DateTime( + newDate.year, + newDate.month, + newDate.day, + time.hour, + time.minute, + ); - setState(() { - date = newDate; - }); + setState(() { + date = newDate!; + }); - widget.onSaved(newDateTime.toString()); + widget.onSaved(newDateTime.toString()); - intl.Intl.defaultLocale = 'pt_BR'; - initializeDateFormatting('pt_BR'); + intl.Intl.defaultLocale = 'pt_BR'; + initializeDateFormatting('pt_BR'); - intl.DateFormat('dd/MM/yyyy HH:mm').format(newDateTime); + intl.DateFormat('dd/MM/yyyy HH:mm').format(newDateTime); - widget.controller!.text = - intl.DateFormat('dd/MM/yyyy HH:mm') - .format(newDateTime); + widget.controller!.text = + intl.DateFormat('dd/MM/yyyy HH:mm') + .format(newDateTime); + } } else { final time = await showTimePicker( context: context, @@ -227,7 +244,11 @@ class _SelectDataState extends State { onSaved: widget.onSaved, controller: widget.controller, decoration: InputDecoration( - hintText: 'Selecione a data e hora', + hintText: widget.tipo == 'hora' + ? 'seleciona a hora' + : widget.tipo == 'data' + ? 'selecione a data' + : 'selecione a data e hora', fillColor: Colors.white, filled: true, enabledBorder: OutlineInputBorder(