From 66a26e6ab99c38207a2e459963a81f8717bbdc1c Mon Sep 17 00:00:00 2001 From: yenisleydi <126813935+yenisleydi@users.noreply.github.com> Date: Wed, 31 Jul 2024 17:12:16 -0600 Subject: [PATCH] Avances tarea 7 --- lib/environments/urls.dart | 1 + lib/src/http_api/category_service.dart | 23 +++++++++++++++++++++++ lib/src/models/categoryModel.dart | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ macos/Flutter/GeneratedPluginRegistrant.swift | 2 ++ pubspec.lock | 109 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ pubspec.yaml | 2 ++ windows/flutter/generated_plugin_registrant.cc | 3 +++ windows/flutter/generated_plugins.cmake | 1 + 8 files changed, 194 insertions(+) create mode 100644 lib/environments/urls.dart create mode 100644 lib/src/http_api/category_service.dart create mode 100644 lib/src/models/categoryModel.dart diff --git a/lib/environments/urls.dart b/lib/environments/urls.dart new file mode 100644 index 0000000..1a692be --- /dev/null +++ b/lib/environments/urls.dart @@ -0,0 +1 @@ +const apiApp = 'https://basic2.visorus.com.mx'; \ No newline at end of file diff --git a/lib/src/http_api/category_service.dart b/lib/src/http_api/category_service.dart new file mode 100644 index 0000000..fd7db71 --- /dev/null +++ b/lib/src/http_api/category_service.dart @@ -0,0 +1,23 @@ +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> 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'}; + } + } +} diff --git a/lib/src/models/categoryModel.dart b/lib/src/models/categoryModel.dart new file mode 100644 index 0000000..dc611b4 --- /dev/null +++ b/lib/src/models/categoryModel.dart @@ -0,0 +1,53 @@ +// 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 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 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 fromJsonArray(List json) { + return json.map((data) => CategoryModel.fromJson(data)).toList(); + } + + // Método para convertir una lista de CategoryModel a una lista de JSONs + static List> toJsonArray(List list) { + return list.map((item) => item.toJson()).toList(); + } +} diff --git a/macos/Flutter/GeneratedPluginRegistrant.swift b/macos/Flutter/GeneratedPluginRegistrant.swift index cccf817..ad535f5 100644 --- a/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/macos/Flutter/GeneratedPluginRegistrant.swift @@ -5,6 +5,8 @@ import FlutterMacOS import Foundation +import connectivity_plus func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { + ConnectivityPlusPlugin.register(with: registry.registrar(forPlugin: "ConnectivityPlusPlugin")) } diff --git a/pubspec.lock b/pubspec.lock index 6cb5f72..58e5797 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1,6 +1,14 @@ # 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" diff --git a/pubspec.yaml b/pubspec.yaml index 9e1616e..8ac05b9 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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. diff --git a/windows/flutter/generated_plugin_registrant.cc b/windows/flutter/generated_plugin_registrant.cc index 8b6d468..8777c93 100644 --- a/windows/flutter/generated_plugin_registrant.cc +++ b/windows/flutter/generated_plugin_registrant.cc @@ -6,6 +6,9 @@ #include "generated_plugin_registrant.h" +#include void RegisterPlugins(flutter::PluginRegistry* registry) { + ConnectivityPlusWindowsPluginRegisterWithRegistrar( + registry->GetRegistrarForPlugin("ConnectivityPlusWindowsPlugin")); } diff --git a/windows/flutter/generated_plugins.cmake b/windows/flutter/generated_plugins.cmake index b93c4c3..cc1361d 100644 --- a/windows/flutter/generated_plugins.cmake +++ b/windows/flutter/generated_plugins.cmake @@ -3,6 +3,7 @@ # list(APPEND FLUTTER_PLUGIN_LIST + connectivity_plus ) list(APPEND FLUTTER_FFI_PLUGIN_LIST -- libgit2 0.27.1