chore: reference the app text styles from theme context (#264)

pull/274/head
jonathandaniels-vgv 3 years ago committed by GitHub
parent 650ecaf10c
commit 8fddce60a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -15,6 +15,7 @@ import 'package:pinball/game/game.dart';
import 'package:pinball/l10n/l10n.dart';
import 'package:pinball/select_character/select_character.dart';
import 'package:pinball_audio/pinball_audio.dart';
import 'package:pinball_ui/pinball_ui.dart';
class App extends StatelessWidget {
const App({
@ -37,14 +38,15 @@ class App extends StatelessWidget {
],
child: BlocProvider(
create: (context) => CharacterThemeCubit(),
child: const MaterialApp(
child: MaterialApp(
title: 'I/O Pinball',
localizationsDelegates: [
theme: PinballTheme.standard,
localizationsDelegates: const [
AppLocalizations.delegate,
GlobalMaterialLocalizations.delegate,
],
supportedLocales: AppLocalizations.supportedLocales,
home: PinballGamePage(),
home: const PinballGamePage(),
),
),
);

@ -1,7 +1,6 @@
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:pinball/l10n/l10n.dart';
import 'package:pinball/theme/theme.dart';
import 'package:pinball_ui/pinball_ui.dart';
/// {@template footer}
@ -35,7 +34,7 @@ class _GoogleIO extends StatelessWidget {
final theme = Theme.of(context);
return Text(
l10n.footerGoogleIOText,
style: theme.textTheme.bodyText1!.copyWith(color: AppColors.white),
style: theme.textTheme.bodyText1!.copyWith(color: PinballColors.white),
);
}
}
@ -51,7 +50,7 @@ class _MadeWithFlutterAndFirebase extends StatelessWidget {
textAlign: TextAlign.center,
text: TextSpan(
text: l10n.footerMadeWithText,
style: theme.textTheme.bodyText1!.copyWith(color: AppColors.white),
style: theme.textTheme.bodyText1!.copyWith(color: PinballColors.white),
children: <TextSpan>[
TextSpan(
text: l10n.footerFlutterLinkText,

@ -2,7 +2,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:pinball/game/game.dart';
import 'package:pinball/gen/gen.dart';
import 'package:pinball/theme/app_colors.dart';
import 'package:pinball_ui/pinball_ui.dart';
/// {@template game_hud}
/// Overlay on the [PinballGame].
@ -72,7 +72,7 @@ class _ScoreViewDecoration extends StatelessWidget {
decoration: BoxDecoration(
borderRadius: radius,
border: Border.all(
color: AppColors.white,
color: PinballColors.white,
width: borderWidth,
),
image: DecorationImage(

@ -2,7 +2,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:pinball/game/game.dart';
import 'package:pinball/l10n/l10n.dart';
import 'package:pinball/theme/theme.dart';
import 'package:pinball_ui/pinball_ui.dart';
/// {@template round_count_display}
/// Colored square indicating if a round is available.
@ -20,9 +20,7 @@ class RoundCountDisplay extends StatelessWidget {
children: [
Text(
l10n.rounds,
style: AppTextStyle.subtitle1.copyWith(
color: AppColors.yellow,
),
style: Theme.of(context).textTheme.subtitle1,
),
const SizedBox(width: 8),
Row(
@ -53,9 +51,9 @@ class RoundIndicator extends StatelessWidget {
@override
Widget build(BuildContext context) {
final color = isActive ? AppColors.yellow : AppColors.yellow.withAlpha(128);
final color =
isActive ? PinballColors.yellow : PinballColors.yellow.withAlpha(128);
const size = 8.0;
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 8),
child: Container(

@ -2,7 +2,6 @@ import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:pinball/game/game.dart';
import 'package:pinball/l10n/l10n.dart';
import 'package:pinball/theme/theme.dart';
import 'package:pinball_components/pinball_components.dart';
/// {@template score_view}
@ -38,9 +37,7 @@ class _GameOver extends StatelessWidget {
return Text(
l10n.gameOver,
style: AppTextStyle.headline1.copyWith(
color: AppColors.white,
),
style: Theme.of(context).textTheme.headline1,
);
}
}
@ -58,9 +55,7 @@ class _ScoreDisplay extends StatelessWidget {
children: [
Text(
l10n.score.toLowerCase(),
style: AppTextStyle.subtitle1.copyWith(
color: AppColors.yellow,
),
style: Theme.of(context).textTheme.subtitle1,
),
const _ScoreText(),
const RoundCountDisplay(),
@ -78,9 +73,7 @@ class _ScoreText extends StatelessWidget {
return Text(
score.formatScore(),
style: AppTextStyle.headline1.copyWith(
color: AppColors.white,
),
style: Theme.of(context).textTheme.headline1,
);
}
}

@ -5,7 +5,6 @@ import 'dart:async';
import 'package:flutter/material.dart';
import 'package:pinball/gen/gen.dart';
import 'package:pinball/l10n/l10n.dart';
import 'package:pinball/theme/theme.dart';
import 'package:pinball_ui/pinball_ui.dart';
import 'package:platform_helper/platform_helper.dart';
@ -122,7 +121,7 @@ class _MobileLaunchControls extends StatelessWidget {
@override
Widget build(BuildContext context) {
final l10n = context.l10n;
const textStyle = AppTextStyle.subtitle3;
final textStyle = Theme.of(context).textTheme.headline3;
return Column(
children: [
Text(
@ -138,9 +137,7 @@ class _MobileLaunchControls extends StatelessWidget {
),
TextSpan(
text: l10n.launch,
style: textStyle.copyWith(
color: AppColors.blue,
),
style: textStyle?.copyWith(color: PinballColors.blue),
),
],
),
@ -156,7 +153,7 @@ class _MobileFlipperControls extends StatelessWidget {
@override
Widget build(BuildContext context) {
final l10n = context.l10n;
const textStyle = AppTextStyle.subtitle3;
final textStyle = Theme.of(context).textTheme.headline3;
return Column(
children: [
Text(
@ -172,9 +169,7 @@ class _MobileFlipperControls extends StatelessWidget {
),
TextSpan(
text: l10n.flip,
style: textStyle.copyWith(
color: AppColors.orange,
),
style: textStyle?.copyWith(color: PinballColors.orange),
),
],
),
@ -207,21 +202,22 @@ class _HowToPlayHeader extends StatelessWidget {
@override
Widget build(BuildContext context) {
final l10n = context.l10n;
const headerTextStyle = AppTextStyle.title;
final textStyle = Theme.of(context).textTheme.headline3?.copyWith(
color: PinballColors.darkBlue,
);
return FittedBox(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
l10n.howToPlay,
style: headerTextStyle.copyWith(
style: textStyle?.copyWith(
fontWeight: FontWeight.bold,
),
),
Text(
l10n.tipsForFlips,
style: headerTextStyle,
style: textStyle,
),
],
),
@ -241,7 +237,7 @@ class _DesktopLaunchControls extends StatelessWidget {
children: [
Text(
l10n.launchControls,
style: AppTextStyle.headline4,
style: Theme.of(context).textTheme.headline4,
),
const SizedBox(height: 10),
Wrap(
@ -270,7 +266,7 @@ class _DesktopFlipperControls extends StatelessWidget {
children: [
Text(
l10n.flipperControls,
style: AppTextStyle.subtitle2,
style: Theme.of(context).textTheme.subtitle2,
),
const SizedBox(height: 10),
Column(
@ -311,8 +307,9 @@ class KeyButton extends StatelessWidget {
@override
Widget build(BuildContext context) {
final textTheme = Theme.of(context).textTheme;
final textStyle =
_control.isArrow ? AppTextStyle.headline1 : AppTextStyle.headline3;
_control.isArrow ? textTheme.headline1 : textTheme.headline3;
const height = 60.0;
final width = _control.isSpace ? height * 2.83 : height;
return DecoratedBox(
@ -334,7 +331,7 @@ class KeyButton extends StatelessWidget {
quarterTurns: _control.isDown ? 1 : 0,
child: Text(
_control.getCharacter(context),
style: textStyle.copyWith(color: AppColors.white),
style: textStyle?.copyWith(color: PinballColors.white),
),
),
),

@ -1,2 +0,0 @@
export 'app_colors.dart';
export 'app_text_style.dart';

@ -0,0 +1,16 @@
/// GENERATED CODE - DO NOT MODIFY BY HAND
/// *****************************************************
/// FlutterGen
/// *****************************************************
// ignore_for_file: directives_ordering,unnecessary_import
class FontFamily {
FontFamily._();
/// Font family: PixeloidMono
static const String pixeloidMono = 'PixeloidMono';
/// Font family: PixeloidSans
static const String pixeloidSans = 'PixeloidSans';
}

@ -5,3 +5,4 @@ export 'package:url_launcher_platform_interface/url_launcher_platform_interface.
export 'src/dialog/dialog.dart';
export 'src/external_links/external_links.dart';
export 'src/theme/theme.dart';

@ -1,17 +1,11 @@
// ignore_for_file: public_member_api_docs
import 'package:flutter/material.dart';
abstract class AppColors {
abstract class PinballColors {
static const Color white = Color(0xFFFFFFFF);
static const Color darkBlue = Color(0xFF0C32A4);
static const Color yellow = Color(0xFFFFEE02);
static const Color orange = Color(0xFFE5AB05);
static const Color blue = Color(0xFF4B94F6);
static const Color transparent = Color(0x00000000);
}

@ -1,17 +1,18 @@
// ignore_for_file: public_member_api_docs
import 'package:flutter/widgets.dart';
import 'package:pinball/theme/theme.dart';
import 'package:pinball_components/pinball_components.dart';
import 'package:pinball_ui/gen/fonts.gen.dart';
import 'package:pinball_ui/pinball_ui.dart';
const _fontPackage = 'pinball_components';
const _primaryFontFamily = FontFamily.pixeloidSans;
abstract class AppTextStyle {
abstract class PinballTextStyle {
static const headline1 = TextStyle(
fontSize: 28,
package: _fontPackage,
fontFamily: _primaryFontFamily,
color: PinballColors.white,
);
static const headline2 = TextStyle(
@ -21,36 +22,22 @@ abstract class AppTextStyle {
);
static const headline3 = TextStyle(
color: AppColors.white,
color: PinballColors.white,
fontSize: 20,
package: _fontPackage,
fontFamily: _primaryFontFamily,
fontWeight: FontWeight.bold,
);
static const headline4 = TextStyle(
color: AppColors.white,
color: PinballColors.white,
fontSize: 16,
package: _fontPackage,
fontFamily: _primaryFontFamily,
);
static const title = TextStyle(
color: AppColors.darkBlue,
fontSize: 20,
package: _fontPackage,
fontFamily: _primaryFontFamily,
);
static const subtitle3 = TextStyle(
color: AppColors.white,
fontSize: 20,
fontWeight: FontWeight.bold,
package: _fontPackage,
fontFamily: _primaryFontFamily,
);
static const subtitle2 = TextStyle(
color: AppColors.white,
color: PinballColors.white,
fontSize: 16,
package: _fontPackage,
fontFamily: _primaryFontFamily,
@ -60,5 +47,6 @@ abstract class AppTextStyle {
fontSize: 10,
fontFamily: _primaryFontFamily,
package: _fontPackage,
color: PinballColors.yellow,
);
}

@ -0,0 +1,23 @@
import 'package:flutter/material.dart';
import 'package:pinball_ui/pinball_ui.dart';
/// Pinball theme
class PinballTheme {
/// Standard [ThemeData] for Pinball UI
static ThemeData get standard {
return ThemeData(
textTheme: _textTheme,
);
}
static TextTheme get _textTheme {
return const TextTheme(
headline1: PinballTextStyle.headline1,
headline2: PinballTextStyle.headline2,
headline3: PinballTextStyle.headline3,
headline4: PinballTextStyle.headline4,
subtitle1: PinballTextStyle.subtitle1,
subtitle2: PinballTextStyle.subtitle2,
);
}
}

@ -0,0 +1,3 @@
export 'pinball_colors.dart';
export 'pinball_text_style.dart';
export 'pinball_theme.dart';

@ -23,6 +23,15 @@ flutter:
generate: true
assets:
- assets/images/dialog/
fonts:
- family: PixeloidSans
fonts:
- asset: fonts/PixeloidSans-nR3g1.ttf
- asset: fonts/PixeloidSansBold-RpeJo.ttf
weight: 700
- family: PixeloidMono
fonts:
- asset: fonts/PixeloidMono-1G8ae.ttf
flutter_gen:
line_length: 80

@ -0,0 +1,31 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pinball_ui/pinball_ui.dart';
void main() {
group('PinballColors', () {
test('white is 0xFFFFFFFF', () {
expect(PinballColors.white, const Color(0xFFFFFFFF));
});
test('darkBlue is 0xFF0C32A4', () {
expect(PinballColors.darkBlue, const Color(0xFF0C32A4));
});
test('yellow is 0xFFFFEE02', () {
expect(PinballColors.yellow, const Color(0xFFFFEE02));
});
test('orange is 0xFFE5AB05', () {
expect(PinballColors.orange, const Color(0xFFE5AB05));
});
test('blue is 0xFF4B94F6', () {
expect(PinballColors.blue, const Color(0xFF4B94F6));
});
test('transparent is 0x00000000', () {
expect(PinballColors.transparent, const Color(0x00000000));
});
});
}

@ -0,0 +1,41 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:pinball_ui/pinball_ui.dart';
void main() {
group('PinballTextStyle', () {
test('headline1 has fontSize 28 and white color', () {
const style = PinballTextStyle.headline1;
expect(style.fontSize, 28);
expect(style.color, PinballColors.white);
});
test('headline2 has fontSize 24', () {
const style = PinballTextStyle.headline2;
expect(style.fontSize, 24);
});
test('headline3 has fontSize 20 and white color', () {
const style = PinballTextStyle.headline3;
expect(style.fontSize, 20);
expect(style.color, PinballColors.white);
});
test('headline4 has fontSize 16 and white color', () {
const style = PinballTextStyle.headline4;
expect(style.fontSize, 16);
expect(style.color, PinballColors.white);
});
test('subtitle1 has fontSize 10 and yellow color', () {
const style = PinballTextStyle.subtitle1;
expect(style.fontSize, 10);
expect(style.color, PinballColors.yellow);
});
test('subtitle2 has fontSize 16 and white color', () {
const style = PinballTextStyle.subtitle2;
expect(style.fontSize, 16);
expect(style.color, PinballColors.white);
});
});
}

@ -0,0 +1,98 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:pinball_ui/pinball_ui.dart';
void main() {
group('PinballTheme', () {
group('standard', () {
test('headline1 matches PinballTextStyle#headline1', () {
expect(
PinballTheme.standard.textTheme.headline1!.fontSize,
PinballTextStyle.headline1.fontSize,
);
expect(
PinballTheme.standard.textTheme.headline1!.color,
PinballTextStyle.headline1.color,
);
expect(
PinballTheme.standard.textTheme.headline1!.fontFamily,
PinballTextStyle.headline1.fontFamily,
);
});
test('headline2 matches PinballTextStyle#headline2', () {
expect(
PinballTheme.standard.textTheme.headline2!.fontSize,
PinballTextStyle.headline2.fontSize,
);
expect(
PinballTheme.standard.textTheme.headline2!.fontFamily,
PinballTextStyle.headline2.fontFamily,
);
expect(
PinballTheme.standard.textTheme.headline2!.fontWeight,
PinballTextStyle.headline2.fontWeight,
);
});
test('headline3 matches PinballTextStyle#headline3', () {
expect(
PinballTheme.standard.textTheme.headline3!.fontSize,
PinballTextStyle.headline3.fontSize,
);
expect(
PinballTheme.standard.textTheme.headline3!.color,
PinballTextStyle.headline3.color,
);
expect(
PinballTheme.standard.textTheme.headline3!.fontFamily,
PinballTextStyle.headline3.fontFamily,
);
});
test('headline4 matches PinballTextStyle#headline4', () {
expect(
PinballTheme.standard.textTheme.headline4!.fontSize,
PinballTextStyle.headline4.fontSize,
);
expect(
PinballTheme.standard.textTheme.headline4!.color,
PinballTextStyle.headline4.color,
);
expect(
PinballTheme.standard.textTheme.headline4!.fontFamily,
PinballTextStyle.headline4.fontFamily,
);
});
test('subtitle1 matches PinballTextStyle#subtitle1', () {
expect(
PinballTheme.standard.textTheme.subtitle1!.fontSize,
PinballTextStyle.subtitle1.fontSize,
);
expect(
PinballTheme.standard.textTheme.subtitle1!.color,
PinballTextStyle.subtitle1.color,
);
expect(
PinballTheme.standard.textTheme.subtitle1!.fontFamily,
PinballTextStyle.subtitle1.fontFamily,
);
});
test('subtitle2 matches PinballTextStyle#subtitle2', () {
expect(
PinballTheme.standard.textTheme.subtitle2!.fontSize,
PinballTextStyle.subtitle2.fontSize,
);
expect(
PinballTheme.standard.textTheme.subtitle2!.color,
PinballTextStyle.subtitle2.color,
);
expect(
PinballTheme.standard.textTheme.subtitle2!.fontFamily,
PinballTextStyle.subtitle2.fontFamily,
);
});
});
});
}

@ -15,6 +15,7 @@ import 'package:mocktail/mocktail.dart';
import 'package:pinball/game/game.dart';
import 'package:pinball/l10n/l10n.dart';
import 'package:pinball_components/pinball_components.dart' hide Assets;
import 'package:pinball_ui/pinball_ui.dart';
import '../../../helpers/helpers.dart';
@ -56,6 +57,7 @@ void main() {
Future<void> _pumpAppWithWidget(WidgetTester tester) async {
await tester.pumpWidget(
MaterialApp(
theme: PinballTheme.standard,
localizationsDelegates: const [
AppLocalizations.delegate,
GlobalMaterialLocalizations.delegate,

@ -2,7 +2,7 @@ import 'package:bloc_test/bloc_test.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pinball/game/game.dart';
import 'package:pinball/theme/app_colors.dart';
import 'package:pinball_ui/pinball_ui.dart';
import '../../../helpers/helpers.dart';
@ -108,7 +108,7 @@ void main() {
expect(
find.byWidgetPredicate(
(widget) => widget is Container && widget.color == AppColors.yellow,
(widget) => widget is Container && widget.color == PinballColors.yellow,
),
findsOneWidget,
);
@ -125,7 +125,7 @@ void main() {
find.byWidgetPredicate(
(widget) =>
widget is Container &&
widget.color == AppColors.yellow.withAlpha(128),
widget.color == PinballColors.yellow.withAlpha(128),
),
findsOneWidget,
);

@ -17,6 +17,7 @@ import 'package:pinball/l10n/l10n.dart';
import 'package:pinball/select_character/select_character.dart';
import 'package:pinball/start_game/start_game.dart';
import 'package:pinball_audio/pinball_audio.dart';
import 'package:pinball_ui/pinball_ui.dart';
import 'helpers.dart';
@ -85,6 +86,7 @@ extension PumpApp on WidgetTester {
),
],
child: MaterialApp(
theme: PinballTheme.standard,
localizationsDelegates: const [
AppLocalizations.delegate,
GlobalMaterialLocalizations.delegate,

Loading…
Cancel
Save