mirror of
https://github.com/flutter/samples.git
synced 2025-11-08 13:58:47 +00:00
Add game_template (#1180)
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
This commit is contained in:
39
game_template/test/crashlytics_test.dart
Normal file
39
game_template/test/crashlytics_test.dart
Normal file
@@ -0,0 +1,39 @@
|
||||
// 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:game_template/src/crashlytics/crashlytics.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
void main() {
|
||||
group('filterStackTrace', () {
|
||||
test('keeps current stacktrace intact', () {
|
||||
final original = StackTrace.current;
|
||||
final filtered = filterStackTrace(original).toString().trim();
|
||||
|
||||
expect(filtered, equals(original.toString().trim()));
|
||||
});
|
||||
|
||||
test('parses an empty stacktrace', () {
|
||||
const original = StackTrace.empty;
|
||||
final filtered = filterStackTrace(original).toString().trim();
|
||||
|
||||
expect(filtered, equals(original.toString().trim()));
|
||||
});
|
||||
|
||||
test('removes the head of an example stacktrace', () {
|
||||
final original = StackTrace.fromString(
|
||||
''' at guardWithCrashlytics.<fn>.<fn>(crashlytics.dart:32)
|
||||
at _BroadcastStreamController.add(_BroadcastStreamController.java)
|
||||
at Logger._publish(logger.dart:276)
|
||||
at Logger.log(logger.dart:200)
|
||||
at Logger.severe(logger.dart:258)
|
||||
at GamesServicesController.initialize(games_services.dart:23)''');
|
||||
final filtered = filterStackTrace(original).toString().trim();
|
||||
|
||||
expect(filtered, isNot(original.toString().trim()));
|
||||
expect(filtered, isNot(contains('at guardWithCrashlytics')));
|
||||
expect(filtered, contains('at GamesServicesController'));
|
||||
});
|
||||
});
|
||||
}
|
||||
48
game_template/test/smoke_test.dart
Normal file
48
game_template/test/smoke_test.dart
Normal file
@@ -0,0 +1,48 @@
|
||||
// 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_test/flutter_test.dart';
|
||||
import 'package:game_template/main.dart';
|
||||
import 'package:game_template/src/player_progress/persistence/memory_player_progress_persistence.dart';
|
||||
import 'package:game_template/src/settings/persistence/memory_settings_persistence.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('smoke test', (tester) async {
|
||||
// Build our game and trigger a frame.
|
||||
await tester.pumpWidget(MyApp(
|
||||
settingsPersistence: MemoryOnlySettingsPersistence(),
|
||||
playerProgressPersistence: MemoryOnlyPlayerProgressPersistence(),
|
||||
adsController: null,
|
||||
gamesServicesController: null,
|
||||
inAppPurchaseController: null,
|
||||
));
|
||||
|
||||
// Verify that the 'Play' button is shown.
|
||||
expect(find.text('Play'), findsOneWidget);
|
||||
|
||||
// Verify that the 'Settings' button is shown.
|
||||
expect(find.text('Settings'), findsOneWidget);
|
||||
|
||||
// Go to 'Settings'.
|
||||
await tester.tap(find.text('Settings'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Music'), findsOneWidget);
|
||||
|
||||
// Go back to main menu.
|
||||
await tester.tap(find.text('Back'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Tap 'Play'.
|
||||
await tester.tap(find.text('Play'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Select level'), findsOneWidget);
|
||||
|
||||
// Tap level 1.
|
||||
await tester.tap(find.text('Level #1'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Find the first level's "tutorial" text.
|
||||
expect(find.text('Drag the slider to 5% or above!'), findsOneWidget);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user