-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ordenação das listagens, listagem de eventos
- Loading branch information
1 parent
11cfa44
commit 34afb8d
Showing
22 changed files
with
545 additions
and
181 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import 'package:baby_guard/blocs/event/event_event.dart'; | ||
import 'package:baby_guard/blocs/event/event_state.dart'; | ||
import 'package:baby_guard/repositories/event_repository.dart'; | ||
import 'package:flutter/foundation.dart'; | ||
|
||
import 'package:flutter_bloc/flutter_bloc.dart'; | ||
|
||
class EventBloc extends Bloc<EventEvent, EventState> { | ||
EventBloc({required this.eventRepository}) : super(EventInitialState()) { | ||
on<ListEventsEvent>((event, emit) async { | ||
try { | ||
emit(ListEventsLoadingState()); | ||
|
||
final events = | ||
(await eventRepository.list(sensorId: event.sensorId)).events ?? []; | ||
|
||
emit(ListEventsDoneState(events: events)); | ||
} catch (e) { | ||
if (kDebugMode) { | ||
print(e); | ||
} | ||
|
||
emit(ListEventsErrorState(message: e.toString())); | ||
} | ||
}); | ||
} | ||
|
||
final EventRepository eventRepository; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
abstract class EventEvent {} | ||
|
||
class ListEventsEvent extends EventEvent { | ||
ListEventsEvent({ | ||
required this.sensorId, | ||
}); | ||
|
||
final int sensorId; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import 'package:baby_guard/models/event.dart'; | ||
|
||
abstract class EventState {} | ||
|
||
class EventInitialState extends EventState {} | ||
|
||
// ListEvents | ||
|
||
class ListEventsLoadingState extends EventState {} | ||
|
||
class ListEventsDoneState extends EventState { | ||
ListEventsDoneState({ | ||
required this.events, | ||
}); | ||
|
||
final List<Event> events; | ||
} | ||
|
||
class ListEventsErrorState extends EventState { | ||
ListEventsErrorState({ | ||
required this.message, | ||
}); | ||
|
||
final String message; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,5 @@ import 'package:flutter/material.dart'; | |
void main() { | ||
runApp(const App()); | ||
} | ||
|
||
// TODO: fix, app bar logo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import 'package:json_annotation/json_annotation.dart'; | ||
|
||
part 'event.g.dart'; | ||
|
||
@JsonSerializable(fieldRename: FieldRename.none, explicitToJson: true) | ||
class Event { | ||
Event({ | ||
required this.id, | ||
required this.updatedAt, | ||
required this.createdAt, | ||
required this.sensorId, | ||
}); | ||
|
||
int? id; | ||
String? updatedAt; | ||
String? createdAt; | ||
int? sensorId; | ||
|
||
factory Event.fromJson(Map<String, dynamic> json) => _$EventFromJson(json); | ||
|
||
Map<String, dynamic> toJson() => _$EventToJson(this); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import 'package:baby_guard/models/event.dart'; | ||
import 'package:json_annotation/json_annotation.dart'; | ||
|
||
part 'list_events_response.g.dart'; | ||
|
||
@JsonSerializable(fieldRename: FieldRename.none, explicitToJson: true) | ||
class ListEventsResponse { | ||
ListEventsResponse({ | ||
required this.events, | ||
}); | ||
|
||
List<Event>? events; | ||
|
||
factory ListEventsResponse.fromJson(Map<String, dynamic> json) => | ||
_$ListEventsResponseFromJson(json); | ||
|
||
Map<String, dynamic> toJson() => _$ListEventsResponseToJson(this); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import 'package:baby_guard/models/event.dart'; | ||
import 'package:baby_guard/utils/formatting.dart'; | ||
import 'package:baby_guard/utils/utils.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
class EventListTile extends StatelessWidget { | ||
const EventListTile({ | ||
super.key, | ||
required this.event, | ||
}); | ||
|
||
final Event event; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
final date = Formatting.date( | ||
Utils.dateTimeFromString(event.createdAt), | ||
mode: DateFormattingMode.slashSeparatedLong, | ||
); | ||
|
||
return ListTile( | ||
title: const Text('Detecção'), | ||
leading: const Icon(Icons.sensors), | ||
subtitle: Text('Disparado em $date'), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import 'package:baby_guard/blocs/sensor/sensor_bloc.dart'; | ||
import 'package:baby_guard/blocs/sensor/sensor_event.dart'; | ||
import 'package:baby_guard/blocs/sensor/sensor_state.dart'; | ||
import 'package:baby_guard/models/sensor.dart'; | ||
import 'package:baby_guard/utils/utils.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_bloc/flutter_bloc.dart'; | ||
|
||
class CreateSensorDialog extends StatelessWidget { | ||
CreateSensorDialog({super.key}); | ||
|
||
final _formKey = GlobalKey<FormState>(); | ||
|
||
final _identifierController = TextEditingController(); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return BlocConsumer<SensorBloc, SensorState>( | ||
listener: (context, state) async { | ||
if (state is CreateSensorDoneState) { | ||
await Utils.popNavigation(context); | ||
} | ||
}, | ||
builder: (context, state) { | ||
return AlertDialog( | ||
title: const Text('Criar sensor'), | ||
content: Form( | ||
key: _formKey, | ||
child: Column( | ||
mainAxisSize: MainAxisSize.min, | ||
crossAxisAlignment: CrossAxisAlignment.stretch, | ||
children: [ | ||
TextFormField( | ||
controller: _identifierController, | ||
decoration: const InputDecoration( | ||
labelText: 'Identificador', | ||
), | ||
validator: (value) { | ||
value ??= ''; | ||
|
||
if (value.length < 3) { | ||
return 'Identificador muito curto.'; | ||
} | ||
|
||
return null; | ||
}, | ||
), | ||
], | ||
), | ||
), | ||
actions: [ | ||
TextButton( | ||
onPressed: state is CreateSensorLoadingState | ||
? null | ||
: () { | ||
if (_formKey.currentState?.validate() != true) { | ||
return; | ||
} | ||
|
||
final sensor = Sensor( | ||
id: null, | ||
updatedAt: null, | ||
createdAt: null, | ||
userId: null, | ||
alias: null, | ||
identifier: _identifierController.text, | ||
); | ||
|
||
BlocProvider.of<SensorBloc>(context) | ||
.add(CreateSensorEvent(sensor: sensor)); | ||
}, | ||
child: const Text('OK'), | ||
), | ||
], | ||
); | ||
}, | ||
); | ||
} | ||
} |
82 changes: 82 additions & 0 deletions
82
app/lib/modules/sensors/delete_sensor_modal_bottom_sheet.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import 'package:baby_guard/blocs/sensor/sensor_bloc.dart'; | ||
import 'package:baby_guard/blocs/sensor/sensor_event.dart'; | ||
import 'package:baby_guard/blocs/sensor/sensor_state.dart'; | ||
import 'package:baby_guard/models/sensor.dart'; | ||
import 'package:baby_guard/utils/utils.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_bloc/flutter_bloc.dart'; | ||
|
||
class DeleteSensorModalBottomSheet extends StatelessWidget { | ||
const DeleteSensorModalBottomSheet({ | ||
super.key, | ||
required this.sensor, | ||
}); | ||
|
||
final Sensor sensor; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return BlocConsumer<SensorBloc, SensorState>( | ||
listener: (context, state) async { | ||
if (state is DeleteSensorDoneState) { | ||
await Utils.popNavigation(context); | ||
} | ||
}, | ||
builder: (context, state) { | ||
return Padding( | ||
padding: const EdgeInsets.all(16), | ||
child: Column( | ||
mainAxisSize: MainAxisSize.min, | ||
crossAxisAlignment: CrossAxisAlignment.stretch, | ||
children: [ | ||
Text( | ||
'Remover sensor', | ||
style: Theme.of(context).textTheme.titleLarge, | ||
), | ||
const SizedBox(height: 16), | ||
Text( | ||
'Deseja remover o sensor ${sensor.identifier ?? ''}? Esta ação não pode ser desfeita.', | ||
), | ||
const SizedBox(height: 16), | ||
IntrinsicHeight( | ||
child: Row( | ||
crossAxisAlignment: CrossAxisAlignment.stretch, | ||
children: [ | ||
Expanded( | ||
child: OutlinedButton( | ||
style: OutlinedButton.styleFrom( | ||
foregroundColor: Colors.redAccent, | ||
), | ||
onPressed: state is DeleteSensorLoadingState | ||
? null | ||
: () async { | ||
await Utils.popNavigation(context); | ||
}, | ||
child: const Icon(Icons.close), | ||
), | ||
), | ||
const SizedBox(width: 16), | ||
Expanded( | ||
child: OutlinedButton( | ||
style: OutlinedButton.styleFrom( | ||
foregroundColor: Colors.greenAccent, | ||
), | ||
onPressed: state is DeleteSensorLoadingState | ||
? null | ||
: () { | ||
BlocProvider.of<SensorBloc>(context) | ||
.add(DeleteSensorEvent(sensor: sensor)); | ||
}, | ||
child: const Icon(Icons.check), | ||
), | ||
), | ||
], | ||
), | ||
), | ||
], | ||
), | ||
); | ||
}, | ||
); | ||
} | ||
} |
Oops, something went wrong.