fix: calculate game hud size

pull/289/head
arturplaczek 3 years ago
parent 2e2fb2a5fc
commit e8a235913f

@ -27,36 +27,44 @@ class _GameHudState extends State<GameHud> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final isGameOver = context.select((GameBloc bloc) => bloc.state.isGameOver); final isGameOver = context.select((GameBloc bloc) => bloc.state.isGameOver);
final gameWidgetWidth = MediaQuery.of(context).size.height * 9 / 16;
final _width = gameWidgetWidth / 1.6; final height = _calculateHeight(context);
return _ScoreViewDecoration( return _ScoreViewDecoration(
child: SizedBox( child: SizedBox(
height: _width / _ratio, height: height,
width: _width, width: height * _ratio,
child: BlocListener<GameBloc, GameState>( child: BlocListener<GameBloc, GameState>(
listenWhen: (previous, current) => listenWhen: (previous, current) =>
previous.bonusHistory.length != current.bonusHistory.length, previous.bonusHistory.length != current.bonusHistory.length,
listener: (_, __) => setState(() => showAnimation = true), listener: (_, __) => setState(() => showAnimation = true),
child: FittedBox( child: AnimatedSwitcher(
alignment: Alignment.centerLeft, duration: kThemeAnimationDuration,
child: AnimatedSwitcher( child: showAnimation && !isGameOver
duration: kThemeAnimationDuration, ? _AnimationView(
child: showAnimation && !isGameOver onComplete: () {
? _AnimationView( if (mounted) {
onComplete: () { setState(() => showAnimation = false);
if (mounted) { }
setState(() => showAnimation = false); },
} )
}, : const ScoreView(),
)
: const ScoreView(),
),
), ),
), ),
), ),
); );
} }
double _calculateHeight(BuildContext context) {
final height = MediaQuery.of(context).size.height * 0.09;
if (height > 90) {
return 90;
} else if (height < 60) {
return 60;
} else {
return height;
}
}
} }
class _ScoreViewDecoration extends StatelessWidget { class _ScoreViewDecoration extends StatelessWidget {

@ -18,7 +18,7 @@ class ScoreView extends StatelessWidget {
return Padding( return Padding(
padding: const EdgeInsets.symmetric( padding: const EdgeInsets.symmetric(
horizontal: 16, horizontal: 16,
vertical: 8, vertical: 2,
), ),
child: AnimatedSwitcher( child: AnimatedSwitcher(
duration: kThemeAnimationDuration, duration: kThemeAnimationDuration,
@ -71,9 +71,11 @@ class _ScoreText extends StatelessWidget {
Widget build(BuildContext context) { Widget build(BuildContext context) {
final score = context.select((GameBloc bloc) => bloc.state.score); final score = context.select((GameBloc bloc) => bloc.state.score);
return Text( return FittedBox(
score.formatScore(), child: Text(
style: Theme.of(context).textTheme.headline1, score.formatScore(),
style: Theme.of(context).textTheme.headline2,
),
); );
} }
} }

Loading…
Cancel
Save