mirror of
https://github.com/flutter/samples.git
synced 2025-11-10 14:58:34 +00:00
Adds a template / sample for games built in Flutter, with all the bells and whistles, like ads, in-app purchases, audio, main menu, settings, and so on. Co-authored-by: Parker Lougheed Co-authored-by: Shams Zakhour
33 lines
784 B
Dart
33 lines
784 B
Dart
// Copyright 2022, the Flutter project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
import 'package:flutter/foundation.dart';
|
|
|
|
/// An extremely silly example of a game state.
|
|
///
|
|
/// Tracks only a single variable, [progress], and calls [onWin] when
|
|
/// the value of [progress] reaches [goal].
|
|
class LevelState extends ChangeNotifier {
|
|
final VoidCallback onWin;
|
|
|
|
final int goal;
|
|
|
|
LevelState({required this.onWin, this.goal = 100});
|
|
|
|
int _progress = 0;
|
|
|
|
int get progress => _progress;
|
|
|
|
void setProgress(int value) {
|
|
_progress = value;
|
|
notifyListeners();
|
|
}
|
|
|
|
void evaluate() {
|
|
if (_progress >= goal) {
|
|
onWin();
|
|
}
|
|
}
|
|
}
|