我正在学习“颤抖” \“飞镖”,在我的课程中,讲师创建了如下模型和数据。我注意到类别类别中的列表费用。它是指费用类别吗?我们什么时候引用外部课程?这类似于SQL中的联接吗?
费用模型
class Expense {
final String name;
final double cost;
Expense({this.name, this.cost});
}
类别模型
class Category {
final String name;
final double maxAmount;
final List<Expense> expenses;
Category({this.name, this.maxAmount, this.expenses});
}
数据
import 'dart:math';
import 'package:flutter_budget_ui/models/category_model.dart';
import 'package:flutter_budget_ui/models/expense_model.dart';
final rand = Random();
final List<double> weeklySpending = [
rand.nextDouble() * 100,
rand.nextDouble() * 100,
rand.nextDouble() * 100,
rand.nextDouble() * 100,
rand.nextDouble() * 100,
rand.nextDouble() * 100,
rand.nextDouble() * 100,
];
_generateExpenses() {
List<Expense> expenses = [
Expense(name: 'Item 0', cost: rand.nextDouble() * 90),
Expense(name: 'Item 1', cost: rand.nextDouble() * 90),
Expense(name: 'Item 2', cost: rand.nextDouble() * 90),
Expense(name: 'Item 3', cost: rand.nextDouble() * 90),
Expense(name: 'Item 4', cost: rand.nextDouble() * 90),
Expense(name: 'Item 5', cost: rand.nextDouble() * 90),
];
return expenses;
}
List<Category> categories = [
Category(name: 'Food', maxAmount: 450, expenses: _generateExpenses()),
Category(name: 'Clothing', maxAmount: 500, expenses: _generateExpenses()),
Category(name: 'Utilities', maxAmount: 600, expenses: _generateExpenses()),
Category(
name: 'Entertainment', maxAmount: 330, expenses: _generateExpenses()),
Category(
name: 'Transportation', maxAmount: 500, expenses: _generateExpenses()),
Category(name: 'Housing', maxAmount: 1000, expenses: _generateExpenses()),
];