Houshan-Basa/lib/data/model/banner_model.dart

76 lines
1.9 KiB
Dart

import 'dart:math';
import 'package:flutter/material.dart';
import 'package:hoshan/data/model/ai/bots_model.dart';
import 'package:hoshan/ui/theme/colors.dart';
List<List<Color>> _listOfColors = [
[
AppColors.primaryColor[200].withAlpha(80),
AppColors.primaryColor[200].withAlpha(80),
AppColors.primaryColor[300],
AppColors.primaryColor[400],
AppColors.primaryColor.defaultShade,
],
[
AppColors.secondryColor[200].withAlpha(50),
AppColors.secondryColor[200].withAlpha(80),
AppColors.secondryColor[300],
AppColors.secondryColor[400],
AppColors.secondryColor.defaultShade
],
[
const Color(0xffbbf7d0).withAlpha(50),
const Color(0xff9be0b7).withAlpha(80),
const Color(0xff57b488),
const Color(0xff2d9f72),
const Color(0xff059467),
]
];
class BannerModel {
final Widget child;
final String imageUrl;
final List<Color> colors;
BannerModel(
{required this.child, required this.imageUrl, required this.colors});
}
class Banners {
String? image;
String? title;
String? description;
String? link;
List<Color>? colors;
Bots? bot;
Banners({this.image, this.title, this.description, this.colors}) {
if (colors == null) {
final randomIndex = Random().nextInt(_listOfColors.length);
colors = _listOfColors[randomIndex];
}
}
Banners.fromJson(Map<String, dynamic> json) {
image = json['image'];
title = json['title'];
link = json['link'];
description = json['description'];
final randomIndex = Random().nextInt(_listOfColors.length);
colors = _listOfColors[randomIndex];
bot = json['bot'] != null ? Bots.fromJson(json['bot']) : null;
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = <String, dynamic>{};
data['image'] = image;
data['title'] = title;
data['link'] = link;
data['description'] = description;
if (bot != null) {
data['bot'] = bot!.toJson();
}
return data;
}
}