PrankSoundboard/lib/models/prank_category.dart

41 lines
1.1 KiB
Dart

import 'package:flutter/material.dart';
import 'prank_sound.dart';
class PrankCategory {
final String categoryId;
final String categoryName;
final String categoryUrl;
final List<PrankSound> list;
final Color themeColor;
PrankCategory({
required this.categoryId,
required this.categoryName,
required this.categoryUrl,
required this.list,
this.themeColor = const Color(0xFF6C63FF),
});
factory PrankCategory.fromJson(Map<String, dynamic> json, int index) {
final List<Color> colors = [
const Color(0xFF6C63FF), // Purple
const Color(0xFFFF6584), // Pink
const Color(0xFF32D74B), // Green
const Color(0xFFFF9F0A), // Orange
const Color(0xFF30B0C7), // Teal
const Color(0xFFFF453A), // Red
];
var listData = json['list'] as List<dynamic>? ?? [];
List<PrankSound> soundList = listData.map((i) => PrankSound.fromJson(i)).toList();
return PrankCategory(
categoryId: json['categoryId'] ?? '',
categoryName: json['categoryName'] ?? 'Category',
categoryUrl: json['categoryUrl'] ?? '',
list: soundList,
themeColor: colors[index % colors.length],
);
}
}