Initial commit
This commit is contained in:
35
lib/providers/servicio_provider.dart
Normal file
35
lib/providers/servicio_provider.dart
Normal file
@@ -0,0 +1,35 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import '../database/database_helper.dart';
|
||||
import '../models/servicio.dart';
|
||||
|
||||
class ServicioProvider extends ChangeNotifier {
|
||||
final DatabaseHelper _db = DatabaseHelper.instance;
|
||||
List<Servicio> _servicios = [];
|
||||
bool _cargando = false;
|
||||
|
||||
List<Servicio> get servicios => _servicios;
|
||||
bool get cargando => _cargando;
|
||||
|
||||
Future<void> cargarServicios() async {
|
||||
_cargando = true;
|
||||
notifyListeners();
|
||||
_servicios = await _db.getServicios();
|
||||
_cargando = false;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<void> agregarServicio(Servicio servicio) async {
|
||||
await _db.insertServicio(servicio);
|
||||
await cargarServicios();
|
||||
}
|
||||
|
||||
Future<void> actualizarServicio(Servicio servicio) async {
|
||||
await _db.updateServicio(servicio);
|
||||
await cargarServicios();
|
||||
}
|
||||
|
||||
Future<void> eliminarServicio(int id) async {
|
||||
await _db.deleteServicio(id);
|
||||
await cargarServicios();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user