Skip to content

Commit

Permalink
habito
Browse files Browse the repository at this point in the history
  • Loading branch information
wjrcode committed Oct 11, 2022
1 parent 61a8970 commit cff98d5
Show file tree
Hide file tree
Showing 7 changed files with 136 additions and 86 deletions.
6 changes: 4 additions & 2 deletions lib/Controller/HabitoController.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<dynamic>? value) => model.dias = value!.cast<String>();
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<bool> saveHabito() async {
if (!formKey.currentState!.validate()) {
Expand Down
25 changes: 19 additions & 6 deletions lib/Model/Habito/HabitoModel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<dynamic>? 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<String, dynamic> 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<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
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;
}
Expand Down
8 changes: 6 additions & 2 deletions lib/Repository/HabitoRepository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand All @@ -27,6 +28,7 @@ class HabitoRepository {
"hora": model.data,
"dias": model.dias,
"cor": model.cor,
"dataFinal": model.dataFinal,
};

final response = await http.put(
Expand All @@ -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));

Expand Down
1 change: 0 additions & 1 deletion lib/Repository/LoginRepository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
20 changes: 15 additions & 5 deletions lib/components/dialogs/habitos/habitoCadastroDialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ Future<dynamic> 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);
Expand All @@ -39,7 +41,7 @@ Future<dynamic> 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: <Widget>[
Expand All @@ -54,12 +56,20 @@ Future<dynamic> 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 ?? ''),
Expand Down
1 change: 1 addition & 0 deletions lib/components/dialogs/habitos/habitoDialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Future<dynamic> visualizarHabito(BuildContext context,
habitoController = HabitoController(HabitoRepository(), context);

habitoController.habitoId(habito.id);
habitoController.habitoIdRotina(habito.idRotina);

return showDialog(
barrierDismissible: false,
Expand Down
161 changes: 91 additions & 70 deletions lib/components/selectData.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -21,7 +23,7 @@ class SelectData extends StatefulWidget {
class _SelectDataState extends State<SelectData> {
@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(
Expand All @@ -31,7 +33,7 @@ class _SelectDataState extends State<SelectData> {
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
widget.apenasHora == true ? 'hora' : 'data e hora',
widget.label,
style: const TextStyle(
color: Colors.black,
fontSize: 16,
Expand All @@ -44,8 +46,10 @@ class _SelectDataState extends State<SelectData> {
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),
Expand Down Expand Up @@ -73,81 +77,94 @@ class _SelectDataState extends State<SelectData> {

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,
Expand Down Expand Up @@ -227,7 +244,11 @@ class _SelectDataState extends State<SelectData> {
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(
Expand Down

0 comments on commit cff98d5

Please sign in to comment.