Avance practica 6 Listado de categorias

parent 532fbac5
// lib/src/models/category_model.dart
class CategoryModel {
int id;
int? version;
String? key;
String? name;
int? createdDate;
CategoryModel? parentCategory;
List<CategoryModel>? subCategories;
bool? active;
CategoryModel({
required this.id,
this.version,
this.key,
this.name,
this.createdDate,
this.parentCategory,
this.subCategories,
this.active,
});
// Método para crear una instancia de CategoryModel desde un JSON
factory CategoryModel.fromJson(Map<String, dynamic> json) {
return CategoryModel(
id: json['id'],
version: json['version'],
key: json['clave'],
name: json['nombre'],
createdDate: json['fechaCreado'],
parentCategory: json['categoria'] != null
? CategoryModel.fromJson(json['categoria'])
: null,
subCategories: json['categorias'] != null
? CategoryModel.fromJsonArray(json['categorias'])
: [],
active: json['activo'],
);
}
// Este metodo sirve para para convertir una instancia de CategoryModel a JSON
Map<String, dynamic> toJson() {
return {
"id": id,
"version": version,
"clave": key,
"nombre": name,
"fechaCreado": createdDate,
"categoria": parentCategory?.toJson(),
"categorias": subCategories != null
? CategoryModel.toJsonArray(subCategories!)
: [],
"activo": active,
};
}
// Método para crear una lista de CategoryModel desde un JSON
static List<CategoryModel> fromJsonArray(json) {
if (json == null) return [];
var list = json as List;
List<CategoryModel> listResult =
list.map((data) => CategoryModel.fromJson(data)).toList();
return listResult;
}
static toJsonArray(List<CategoryModel> list) {
List<Map<String, dynamic>> listMap = [];
for (CategoryModel item in list) {
listMap.add(item.toJson());
}
return listMap;
}
}
import 'dart:async';
import 'dart:convert';
import 'package:flutter/cupertino.dart';
class Categorias extends StatelessWidget{
@override
Widget build(BuildContext context) {
// TODO: implement build
throw UnimplementedError();
}
}
\ No newline at end of file
......@@ -66,15 +66,31 @@ packages:
dependency: "direct dev"
description:
name: flutter_lints
sha256: "9e8c3858111da373efc5aa341de011d9bd23e2c5c5e0c62bccf32438e192d7b1"
sha256: "3f41d009ba7172d5ff9be5f6e6e6abb4300e263aab8866d2a0842ed2a70f8f0c"
url: "https://pub.dev"
source: hosted
version: "3.0.2"
version: "4.0.0"
flutter_test:
dependency: "direct dev"
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:
......@@ -103,10 +119,10 @@ packages:
dependency: transitive
description:
name: lints
sha256: cbf8d4b858bb0134ef3ef87841abdf8d63bfc255c266b7bf6b39daa1085c4290
sha256: "976c774dd944a42e83e2467f4cc670daef7eed6295b10b36ae8c85bcbf828235"
url: "https://pub.dev"
source: hosted
version: "3.0.0"
version: "4.0.0"
matcher:
dependency: transitive
description:
......@@ -192,6 +208,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 +232,14 @@ 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"
sdks:
dart: ">=3.4.4 <4.0.0"
flutter: ">=3.18.0-18.0.pre.54"
......@@ -22,34 +22,18 @@ version: 1.0.0+1
environment:
sdk: '>=3.4.4 <4.0.0'
# Dependencies specify other packages that your package needs in order to work.
# To automatically upgrade your package dependencies to the latest versions
# consider running `flutter pub upgrade --major-versions`. Alternatively,
# dependencies can be manually updated by changing the version numbers below to
# the latest version available on pub.dev. To see which dependencies have newer
# versions available, run `flutter pub outdated`.
dependencies:
flutter:
sdk: flutter
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
http: ^1.2.2
cupertino_icons: ^1.0.6
dev_dependencies:
flutter_test:
sdk: flutter
# The "flutter_lints" package below contains a set of recommended lints to
# encourage good coding practices. The lint set provided by the package is
# activated in the `analysis_options.yaml` file located at the root of your
# package. See that file for information about deactivating specific lint
# rules and activating additional ones.
flutter_lints: ^3.0.0
flutter_lints: ^4.0.0
# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec
# The following section is specific to Flutter packages.
flutter:
# The following line ensures that the Material Icons font is
......
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