25 lines
677 B
Dart
25 lines
677 B
Dart
import 'dart:async';
|
|
import '../models/game_model.dart';
|
|
|
|
class GameController {
|
|
final List<Game> _games = [];
|
|
final _gameStreamController = StreamController<List<Game>>.broadcast();
|
|
|
|
Stream<List<Game>> get gamesStream => _gameStreamController.stream;
|
|
|
|
void addGame(String myTeam, String opponent, String season) {
|
|
final newGame = Game(
|
|
id: DateTime.now().toString(),
|
|
myTeam: myTeam,
|
|
opponentTeam: opponent,
|
|
season: season,
|
|
date: DateTime.now(),
|
|
);
|
|
_games.insert(0, newGame); // Adiciona ao topo da lista
|
|
_gameStreamController.add(List.unmodifiable(_games));
|
|
}
|
|
|
|
void dispose() {
|
|
_gameStreamController.close();
|
|
}
|
|
} |