section.dart 803 B

12345678910111213141516171819202122232425262728293031323334
  1. import 'unit.dart';
  2. class LayoutSection {
  3. String _key = '';
  4. List<LayoutUnit>? _layouts;
  5. String get key => _key;
  6. List<LayoutUnit> get layouts => _layouts ?? const [];
  7. LayoutSection();
  8. factory LayoutSection.fromJson(Map<String, dynamic> map) {
  9. final instance = LayoutSection();
  10. instance._key = map['n'] ?? '';
  11. instance._loadLayoutUnits(map['Layouts']);
  12. return instance;
  13. }
  14. void _loadLayoutUnits(dynamic data) {
  15. final List<LayoutUnit> arr = [];
  16. if (data != null && data is List) {
  17. final List<dynamic> jArr = data;
  18. for (final item in jArr) {
  19. arr.add(LayoutUnit.fromJson(item));
  20. }
  21. }
  22. if (arr.isEmpty) {
  23. throw ArgumentError(
  24. "Layout configuration error: Layout element not found.");
  25. }
  26. _layouts = arr;
  27. }
  28. }