35 lines
595 B
Dart
35 lines
595 B
Dart
import 'package:flutter/foundation.dart';
|
|
|
|
class Person {
|
|
String name;
|
|
int age;
|
|
|
|
Person(this.name, this.age);
|
|
}
|
|
|
|
class MyProvider with ChangeNotifier {
|
|
final List<Person> _people = [
|
|
Person('John', 30),
|
|
Person('Jane', 25),
|
|
Person('Jack', 20),
|
|
Person('Chea', 40),
|
|
];
|
|
|
|
List<Person> get people => _people;
|
|
|
|
void addPerson(Person person) {
|
|
_people.add(person);
|
|
notifyListeners();
|
|
}
|
|
|
|
void removePerson(Person person) {
|
|
_people.remove(person);
|
|
notifyListeners();
|
|
}
|
|
|
|
void removeLastPerson() {
|
|
_people.removeLast();
|
|
notifyListeners();
|
|
}
|
|
}
|