feat: include game files (#2)

* feat: included flame and flame_forge2d dependency

* feat: included initial LandingPage with PinballGame

* feat: included test

* feat: included navigation test

* fix: landing page test

* feat: used l10n string for "Play"

Co-authored-by: Erick Zanardo <erickzanardoo@gmail.com>
pull/5/head
Alejandro Santiago 2 years ago committed by GitHub
parent 5ab34687a0
commit ab77ebec67
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -8,6 +8,7 @@
import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:pinball/l10n/l10n.dart';
import 'package:pinball/landing/landing.dart';
class App extends StatelessWidget {
const App({Key? key}) : super(key: key);
@ -15,6 +16,7 @@ class App extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'I/O Pinball',
theme: ThemeData(
appBarTheme: const AppBarTheme(color: Color(0xFF13B9FF)),
colorScheme: ColorScheme.fromSwatch(
@ -26,7 +28,7 @@ class App extends StatelessWidget {
GlobalMaterialLocalizations.delegate,
],
supportedLocales: AppLocalizations.supportedLocales,
home: Container(),
home: const LandingPage(),
);
}
}

@ -0,0 +1,2 @@
export 'pinball_game.dart';
export 'view/pinball_game_page.dart';

@ -0,0 +1,3 @@
import 'package:flame_forge2d/forge2d_game.dart';
class PinballGame extends Forge2DGame {}

@ -0,0 +1,16 @@
import 'package:flame/game.dart';
import 'package:flutter/material.dart';
import 'package:pinball/game/game.dart';
class PinballGamePage extends StatelessWidget {
const PinballGamePage({Key? key}) : super(key: key);
static Route route() {
return MaterialPageRoute<void>(builder: (_) => const PinballGamePage());
}
@override
Widget build(BuildContext context) {
return GameWidget(game: PinballGame());
}
}

@ -1,7 +1,4 @@
{
"@@locale": "en",
"counterAppBarTitle": "Counter",
"@counterAppBarTitle": {
"description": "Text shown in the AppBar of the Counter Page"
}
"play": "Play"
}

@ -1,7 +1,4 @@
{
"@@locale": "es",
"counterAppBarTitle": "Contador",
"@counterAppBarTitle": {
"description": "Texto mostrado en la AppBar de la página del contador"
}
"play": "Jugar"
}

@ -0,0 +1 @@
export 'view/landing_page.dart';

@ -0,0 +1,21 @@
import 'package:flutter/material.dart';
import 'package:pinball/game/game.dart';
import 'package:pinball/l10n/l10n.dart';
class LandingPage extends StatelessWidget {
const LandingPage({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
final l10n = context.l10n;
return Scaffold(
body: Center(
child: TextButton(
onPressed: () =>
Navigator.of(context).push<void>(PinballGamePage.route()),
child: Text(l10n.play),
),
),
);
}
}

@ -127,6 +127,20 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "6.1.2"
flame:
dependency: "direct main"
description:
name: flame
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.0"
flame_forge2d:
dependency: "direct main"
description:
name: flame_forge2d
url: "https://pub.dartlang.org"
source: hosted
version: "0.8.3"
flutter:
dependency: "direct main"
description: flutter
@ -149,6 +163,13 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
forge2d:
dependency: transitive
description:
name: forge2d
url: "https://pub.dartlang.org"
source: hosted
version: "0.8.1"
frontend_server_client:
dependency: transitive
description:
@ -233,6 +254,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.1"
mockingjay:
dependency: "direct dev"
description:
name: mockingjay
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.0"
mocktail:
dependency: "direct dev"
description:
@ -254,6 +282,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.1"
ordered_set:
dependency: transitive
description:
name: ordered_set
url: "https://pub.dartlang.org"
source: hosted
version: "5.0.0"
package_config:
dependency: transitive
description:
@ -450,4 +485,4 @@ packages:
version: "3.1.0"
sdks:
dart: ">=2.16.0 <3.0.0"
flutter: ">=1.16.0"
flutter: ">=2.5.0"

@ -8,6 +8,8 @@ environment:
dependencies:
bloc: ^8.0.2
flame: ^1.0.0
flame_forge2d: ^0.8.3
flutter:
sdk: flutter
flutter_bloc: ^8.0.1
@ -19,6 +21,7 @@ dev_dependencies:
bloc_test: ^9.0.2
flutter_test:
sdk: flutter
mockingjay: ^0.2.0
mocktail: ^0.2.0
very_good_analysis: ^2.4.0

@ -5,15 +5,15 @@
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pinball/app/app.dart';
import 'package:pinball/landing/landing.dart';
void main() {
group('App', () {
testWidgets('renders CounterPage', (tester) async {
testWidgets('renders LandingPage', (tester) async {
await tester.pumpWidget(const App());
expect(find.byType(Container), findsOneWidget);
expect(find.byType(LandingPage), findsOneWidget);
});
});
}

@ -0,0 +1,14 @@
import 'package:flame/game.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pinball/game/game.dart';
import '../../helpers/helpers.dart';
void main() {
group('PinballGamePage', () {
testWidgets('renders single GameWidget with PinballGame', (tester) async {
await tester.pumpApp(const PinballGamePage());
expect(find.byType(GameWidget<PinballGame>), findsOneWidget);
});
});
}

@ -8,10 +8,14 @@
import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mockingjay/mockingjay.dart';
import 'package:pinball/l10n/l10n.dart';
extension PumpApp on WidgetTester {
Future<void> pumpApp(Widget widget) {
Future<void> pumpApp(
Widget widget, {
MockNavigator? navigator,
}) {
return pumpWidget(
MaterialApp(
localizationsDelegates: const [
@ -19,7 +23,9 @@ extension PumpApp on WidgetTester {
GlobalMaterialLocalizations.delegate,
],
supportedLocales: AppLocalizations.supportedLocales,
home: widget,
home: navigator != null
? MockNavigatorProvider(navigator: navigator, child: widget)
: widget,
),
);
}

@ -0,0 +1,33 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mockingjay/mockingjay.dart';
import 'package:pinball/landing/landing.dart';
import '../../helpers/helpers.dart';
void main() {
group('LandingPage', () {
testWidgets('renders TextButton', (tester) async {
await tester.pumpApp(const LandingPage());
expect(find.byType(TextButton), findsOneWidget);
});
testWidgets('tapping on TextButton navigates to PinballGamePage',
(tester) async {
final navigator = MockNavigator();
when(() => navigator.push<void>(any())).thenAnswer((_) async {});
await tester.pumpApp(
const LandingPage(),
navigator: navigator,
);
await tester.tap(
find.byType(
TextButton,
),
);
verify(() => navigator.push<void>(any())).called(1);
});
});
}
Loading…
Cancel
Save