Commit 66a26e6a by yenisleydi

Avances tarea 7

parent ef0fb08b
const apiApp = 'https://basic2.visorus.com.mx';
\ No newline at end of file
import 'package:flutter/foundation.dart'; // Para usar kDebugMode
import 'package:http/http.dart' as http;
import 'package:primer_practica/environments/urls.dart' as api;
class CategoryService {
static const String apiBaseUrl = 'categoria'; // Cambia esto a la URL base de tu API
// Método para obtener las categorías
Future<Map<String, dynamic>> getCategories({int offset = 0, int max = 100}) async {
String url = '${{api.apiApp}}/$apiBaseUrl?offset=$offset&max=$max';
if (kDebugMode) {
print('Url -> $url');
}
try {
final resp = await http.get(Uri.parse(url));
return {"statusCode": resp.statusCode, "body": resp.body};
} catch (e) {
return {"statusCode": 501, "body": '$e'};
}
}
}
// lib/src/models/category_model.dart
class CategoryModel {
int id;
int? version;
String clave;
String nombre;
int? fechaCreado;
String categoria;
bool? activo;
CategoryModel({
required this.id,
this.version,
required this.clave,
required this.nombre,
this.fechaCreado,
required this.categoria,
this.activo,
});
// Método para crear una instancia de CategoryModel desde un JSON
factory CategoryModel.fromJson(Map<String, dynamic> json) => CategoryModel(
id: json['id'],
version: json['version'] ?? 0,
clave: json['clave'] ?? '',
nombre: json['nombre'] ?? '',
fechaCreado: json['fechaCreado'],
categoria: json['categoria'] ?? '',
activo: json['activo'],
);
// Método para convertir una instancia de CategoryModel a JSON
Map<String, dynamic> toJson() => {
'id': id,
'version': version,
'clave': clave,
'nombre': nombre,
'fechaCreado': fechaCreado,
'categoria': categoria,
'activo': activo,
};
// Método para crear una lista de CategoryModel desde una lista de JSONs
static List<CategoryModel> fromJsonArray(List<dynamic> json) {
return json.map((data) => CategoryModel.fromJson(data)).toList();
}
// Método para convertir una lista de CategoryModel a una lista de JSONs
static List<Map<String, dynamic>> toJsonArray(List<CategoryModel> list) {
return list.map((item) => item.toJson()).toList();
}
}
......@@ -5,6 +5,8 @@
import FlutterMacOS
import Foundation
import connectivity_plus
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
ConnectivityPlusPlugin.register(with: registry.registrar(forPlugin: "ConnectivityPlusPlugin"))
}
# Generated by pub
# See https://dart.dev/tools/pub/glossary#lockfile
packages:
args:
dependency: transitive
description:
name: args
sha256: "7cf60b9f0cc88203c5a190b4cd62a99feea42759a7fa695010eb5de1c0b2252a"
url: "https://pub.dev"
source: hosted
version: "2.5.0"
async:
dependency: transitive
description:
......@@ -41,6 +49,22 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.18.0"
connectivity_plus:
dependency: "direct main"
description:
name: connectivity_plus
sha256: "3e7d1d9dbae40ae82cbe6c23c518f0c4ffe32764ee9749b9a99d32cbac8734f6"
url: "https://pub.dev"
source: hosted
version: "6.0.4"
connectivity_plus_platform_interface:
dependency: transitive
description:
name: connectivity_plus_platform_interface
sha256: "42657c1715d48b167930d5f34d00222ac100475f73d10162ddf43e714932f204"
url: "https://pub.dev"
source: hosted
version: "2.0.1"
cupertino_icons:
dependency: "direct main"
description:
......@@ -49,6 +73,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.0.8"
dbus:
dependency: transitive
description:
name: dbus
sha256: "365c771ac3b0e58845f39ec6deebc76e3276aa9922b0cc60840712094d9047ac"
url: "https://pub.dev"
source: hosted
version: "0.7.10"
fake_async:
dependency: transitive
description:
......@@ -57,6 +89,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.3.1"
ffi:
dependency: transitive
description:
name: ffi
sha256: "493f37e7df1804778ff3a53bd691d8692ddf69702cf4c1c1096a2e41b4779e21"
url: "https://pub.dev"
source: hosted
version: "2.1.2"
flutter:
dependency: "direct main"
description: flutter
......@@ -75,6 +115,27 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
flutter_web_plugins:
dependency: transitive
description: flutter
source: sdk
version: "0.0.0"
http:
dependency: "direct main"
description:
name: http
sha256: b9c29a161230ee03d3ccf545097fccd9b87a5264228c5d348202e0f0c28f9010
url: "https://pub.dev"
source: hosted
version: "1.2.2"
http_parser:
dependency: transitive
description:
name: http_parser
sha256: "2aa08ce0341cc9b354a498388e30986515406668dbcc4f7c950c3e715496693b"
url: "https://pub.dev"
source: hosted
version: "4.0.2"
leak_tracker:
dependency: transitive
description:
......@@ -131,6 +192,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.12.0"
nm:
dependency: transitive
description:
name: nm
sha256: "2c9aae4127bdc8993206464fcc063611e0e36e72018696cd9631023a31b24254"
url: "https://pub.dev"
source: hosted
version: "0.5.0"
path:
dependency: transitive
description:
......@@ -139,6 +208,22 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.9.0"
petitparser:
dependency: transitive
description:
name: petitparser
sha256: c15605cd28af66339f8eb6fbe0e541bfe2d1b72d5825efc6598f3e0a31b9ad27
url: "https://pub.dev"
source: hosted
version: "6.0.2"
plugin_platform_interface:
dependency: transitive
description:
name: plugin_platform_interface
sha256: "4820fbfdb9478b1ebae27888254d445073732dae3d6ea81f0b7e06d5dedc3f02"
url: "https://pub.dev"
source: hosted
version: "2.1.8"
sky_engine:
dependency: transitive
description: flutter
......@@ -192,6 +277,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "0.7.0"
typed_data:
dependency: transitive
description:
name: typed_data
sha256: facc8d6582f16042dd49f2463ff1bd6e2c9ef9f3d5da3d9b087e244a7b564b3c
url: "https://pub.dev"
source: hosted
version: "1.3.2"
vector_math:
dependency: transitive
description:
......@@ -208,6 +301,22 @@ packages:
url: "https://pub.dev"
source: hosted
version: "14.2.1"
web:
dependency: transitive
description:
name: web
sha256: d43c1d6b787bf0afad444700ae7f4db8827f701bc61c255ac8d328c6f4d52062
url: "https://pub.dev"
source: hosted
version: "1.0.0"
xml:
dependency: transitive
description:
name: xml
sha256: b015a8ad1c488f66851d762d3090a21c600e479dc75e68328c52774040cf9226
url: "https://pub.dev"
source: hosted
version: "6.5.0"
sdks:
dart: ">=3.4.4 <4.0.0"
flutter: ">=3.18.0-18.0.pre.54"
......@@ -30,6 +30,8 @@ environment:
dependencies:
flutter:
sdk: flutter
http: ^1.2.2
connectivity_plus: ^6.0.4
# The following adds the Cupertino Icons font to your application.
......
......@@ -6,6 +6,9 @@
#include "generated_plugin_registrant.h"
#include <connectivity_plus/connectivity_plus_windows_plugin.h>
void RegisterPlugins(flutter::PluginRegistry* registry) {
ConnectivityPlusWindowsPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("ConnectivityPlusWindowsPlugin"));
}
......@@ -3,6 +3,7 @@
#
list(APPEND FLUTTER_PLUGIN_LIST
connectivity_plus
)
list(APPEND FLUTTER_FFI_PLUGIN_LIST
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment