fix: apply code review

pull/236/head
arturplaczek 3 years ago
parent 3a6a1fbb11
commit 21adfddd02

@ -1,5 +1,9 @@
name: pinball_ui name: pinball_ui
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
on: on:
push: push:
paths: paths:

@ -66,14 +66,14 @@ class _ScoreViewDecoration extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
const radius = BorderRadius.all(Radius.circular(12)); const radius = BorderRadius.all(Radius.circular(12));
const boardWidth = 5.0; const borderWidth = 5.0;
return DecoratedBox( return DecoratedBox(
decoration: BoxDecoration( decoration: BoxDecoration(
borderRadius: radius, borderRadius: radius,
border: Border.all( border: Border.all(
color: AppColors.white, color: AppColors.white,
width: boardWidth, width: borderWidth,
), ),
image: DecorationImage( image: DecorationImage(
fit: BoxFit.cover, fit: BoxFit.cover,
@ -83,7 +83,7 @@ class _ScoreViewDecoration extends StatelessWidget {
), ),
), ),
child: Padding( child: Padding(
padding: const EdgeInsets.all(boardWidth - 1), padding: const EdgeInsets.all(borderWidth - 1),
child: ClipRRect( child: ClipRRect(
borderRadius: radius, borderRadius: radius,
child: child, child: child,

@ -28,7 +28,16 @@ class PlayButtonOverlay extends StatelessWidget {
context: context, context: context,
barrierDismissible: false, barrierDismissible: false,
builder: (_) { builder: (_) {
return const CharacterSelectionDialog(); // TODO(arturplaczek): remove after merge StarBlocListener
final height = MediaQuery.of(context).size.height * 0.5;
return Center(
child: SizedBox(
height: height,
width: height * 1.4,
child: const CharacterSelectionDialog(),
),
);
}, },
); );
}, },

@ -33,7 +33,7 @@ class CharacterSelectionView extends StatelessWidget {
Widget build(BuildContext context) { Widget build(BuildContext context) {
final l10n = context.l10n; final l10n = context.l10n;
return PinballDialogLayout( return PixelatedDecoration(
header: Text( header: Text(
l10n.characterSelectionTitle, l10n.characterSelectionTitle,
style: Theme.of(context).textTheme.headline3, style: Theme.of(context).textTheme.headline3,
@ -47,9 +47,18 @@ class CharacterSelectionView extends StatelessWidget {
TextButton( TextButton(
onPressed: () { onPressed: () {
Navigator.of(context).pop(); Navigator.of(context).pop();
// TODO(arturplaczek): remove after merge StarBlocListener
final height = MediaQuery.of(context).size.height * 0.5;
showDialog<void>( showDialog<void>(
context: context, context: context,
builder: (_) => const HowToPlayDialog(), builder: (_) => Center(
child: SizedBox(
height: height,
width: height * 1.4,
child: const HowToPlayDialog(),
),
),
); );
}, },
child: Text(l10n.start), child: Text(l10n.start),

@ -12,7 +12,7 @@ class HowToPlayDialog extends StatelessWidget {
final l10n = context.l10n; final l10n = context.l10n;
const spacing = SizedBox(height: 16); const spacing = SizedBox(height: 16);
return PinballDialogLayout( return PixelatedDecoration(
header: Text(l10n.howToPlay), header: Text(l10n.howToPlay),
body: ListView( body: ListView(
children: const [ children: const [

@ -3,7 +3,7 @@
[![style: very good analysis][very_good_analysis_badge]][very_good_analysis_link] [![style: very good analysis][very_good_analysis_badge]][very_good_analysis_link]
[![License: MIT][license_badge]][license_link] [![License: MIT][license_badge]][license_link]
Package with the UI components for the Pinball Game UI Toolkit for the Pinball Flutter Application
[license_badge]: https://img.shields.io/badge/license-MIT-blue.svg [license_badge]: https://img.shields.io/badge/license-MIT-blue.svg
[license_link]: https://opensource.org/licenses/MIT [license_link]: https://opensource.org/licenses/MIT

@ -1 +1 @@
export 'pinball_dialog_layout.dart'; export 'pixelated_decoration.dart';

@ -1,98 +0,0 @@
import 'package:flutter/material.dart';
import 'package:pinball_ui/gen/gen.dart';
/// {@template pinball_dialog_layout}
/// Decoration for dialogs that display pixelated background and takes
/// two parameters:
/// - header [Widget]
/// - body [Widget]
///
/// Creates square, centered decoration the size of a game.
///
/// The header takes 20% of the area and the body remaining space.
/// {@endtemplate}
class PinballDialogLayout extends StatelessWidget {
/// {@macro pinball_dialog_layout}
const PinballDialogLayout({
Key? key,
required Widget header,
required Widget body,
}) : _header = header,
_body = body,
super(key: key);
final Widget _header;
final Widget _body;
@override
Widget build(BuildContext context) {
return LayoutBuilder(
builder: (context, constraints) {
final gameWidgetWidth = constraints.maxHeight * 9 / 16;
return Center(
child: SizedBox(
height: gameWidgetWidth,
width: gameWidgetWidth,
child: _DialogDecoration(
header: _header,
body: _body,
),
),
);
},
);
}
}
class _DialogDecoration extends StatelessWidget {
const _DialogDecoration({
Key? key,
required Widget header,
required Widget body,
}) : _header = header,
_body = body,
super(key: key);
final Widget _header;
final Widget _body;
@override
Widget build(BuildContext context) {
const radius = BorderRadius.all(Radius.circular(12));
const boardWidth = 5.0;
return DecoratedBox(
decoration: BoxDecoration(
borderRadius: radius,
border: Border.all(
color: Colors.white,
width: boardWidth,
),
image: DecorationImage(
fit: BoxFit.cover,
image: AssetImage(
Assets.images.dialog.background.keyName,
),
),
),
child: Padding(
padding: const EdgeInsets.all(boardWidth - 1),
child: ClipRRect(
borderRadius: radius,
child: Column(
children: [
Expanded(
child: Center(child: _header),
),
Expanded(
flex: 4,
child: _body,
),
],
),
),
),
);
}
}

@ -0,0 +1,58 @@
import 'package:flutter/material.dart';
import 'package:pinball_ui/gen/gen.dart';
/// {@template pixelated_decoration}
/// Pixelated decoration.
/// {@endtemplate}
class PixelatedDecoration extends StatelessWidget {
/// {@macro pixelated_decoration}
const PixelatedDecoration({
Key? key,
required Widget header,
required Widget body,
}) : _header = header,
_body = body,
super(key: key);
final Widget _header;
final Widget _body;
@override
Widget build(BuildContext context) {
const radius = BorderRadius.all(Radius.circular(12));
const borderWidth = 5.0;
return DecoratedBox(
decoration: BoxDecoration(
image: DecorationImage(
fit: BoxFit.fill,
image: AssetImage(Assets.images.dialog.background.keyName),
),
borderRadius: radius,
border: Border.all(
color: Colors.white,
width: borderWidth,
),
),
child: Padding(
padding: const EdgeInsets.all(borderWidth),
child: ClipRRect(
borderRadius: radius,
child: Column(
children: [
Expanded(
child: Center(
child: _header,
),
),
Expanded(
flex: 4,
child: _body,
),
],
),
),
),
);
}
}

@ -1,5 +1,5 @@
name: pinball_ui name: pinball_ui
description: App UI Component Library description: UI Toolkit for the Pinball Flutter Application
version: 1.0.0+1 version: 1.0.0+1
publish_to: none publish_to: none
@ -13,7 +13,6 @@ dependencies:
dev_dependencies: dev_dependencies:
flutter_test: flutter_test:
sdk: flutter sdk: flutter
mocktail: ^0.2.0
test: ^1.19.2 test: ^1.19.2
very_good_analysis: ^2.4.0 very_good_analysis: ^2.4.0

@ -5,14 +5,14 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:pinball_ui/pinball_ui.dart'; import 'package:pinball_ui/pinball_ui.dart';
void main() { void main() {
group('PinballDialogLayout', () { group('PixelatedDecoration', () {
testWidgets('renders header and body', (tester) async { testWidgets('renders header and body', (tester) async {
const headerText = 'header'; const headerText = 'header';
const bodyText = 'body'; const bodyText = 'body';
await tester.pumpWidget( await tester.pumpWidget(
MaterialApp( MaterialApp(
home: PinballDialogLayout( home: PixelatedDecoration(
header: Text(headerText), header: Text(headerText),
body: Text(bodyText), body: Text(bodyText),
), ),
Loading…
Cancel
Save