Initial commit: Flutter Weight Tracker Web
This commit is contained in:
81
lib/models/home_model.dart
Normal file
81
lib/models/home_model.dart
Normal file
@@ -0,0 +1,81 @@
|
||||
class WeightModel {
|
||||
final String name;
|
||||
final double weight;
|
||||
final DateTime date;
|
||||
final String id;
|
||||
final double weightChange;
|
||||
|
||||
WeightModel({
|
||||
required this.weight,
|
||||
required this.date,
|
||||
required this.id,
|
||||
required this.weightChange, required this.name,
|
||||
});
|
||||
|
||||
static WeightModel fromJson(Map<String, dynamic> json) {
|
||||
return WeightModel(
|
||||
weight: json['weight'],
|
||||
date: DateTime.parse(json['date']),
|
||||
id: json['id'],
|
||||
weightChange: json['weightChange'], name: json['name'],
|
||||
);
|
||||
}
|
||||
|
||||
static Map<String, dynamic> toJson(WeightModel weightModel) {
|
||||
return {
|
||||
'weight': weightModel.weight,
|
||||
'date': weightModel.date.toIso8601String(),
|
||||
'id': weightModel.id,
|
||||
'weightChange': weightModel.weightChange,
|
||||
'name': weightModel.name,
|
||||
};
|
||||
}
|
||||
|
||||
// An empty instance for initialization or default values
|
||||
static final empty = WeightModel(
|
||||
weight: 0.0,
|
||||
date: DateTime.now(),
|
||||
id: '00',
|
||||
weightChange: 0.0, name: 'Joe',
|
||||
);
|
||||
|
||||
// Sample data for testing and demonstration purposes
|
||||
static List<WeightModel> sampleData = [
|
||||
WeightModel(
|
||||
weight: 70.0,
|
||||
date: DateTime(2024, 1, 1),
|
||||
id: '01',
|
||||
weightChange: 0.0, name: 'Joe',
|
||||
),
|
||||
WeightModel(
|
||||
weight: 69.5,
|
||||
date: DateTime(2024, 1, 15),
|
||||
id: '02',
|
||||
weightChange: -0.5, name: 'Joe',
|
||||
),
|
||||
WeightModel(
|
||||
weight: 68.0,
|
||||
date: DateTime(2024, 2, 1),
|
||||
id: '03',
|
||||
weightChange: -1.5, name: 'Joe',
|
||||
),
|
||||
WeightModel(
|
||||
weight: 100.0,
|
||||
date: DateTime(2024, 1, 1),
|
||||
id: '04',
|
||||
weightChange: 0.0, name: 'Karl',
|
||||
),
|
||||
WeightModel(
|
||||
weight: 95.5,
|
||||
date: DateTime(2024, 1, 15),
|
||||
id: '05',
|
||||
weightChange: -4.5, name: 'Karl',
|
||||
),
|
||||
WeightModel(
|
||||
weight: 90.0,
|
||||
date: DateTime(2024, 2, 1),
|
||||
id: '06',
|
||||
weightChange: -5.5, name: 'Karl',
|
||||
),
|
||||
];
|
||||
}
|
||||
Reference in New Issue
Block a user