Skip to content

Commit

Permalink
Refactor control_panel.dart
Browse files Browse the repository at this point in the history
  • Loading branch information
roman-ovsepian-ew committed Feb 10, 2023
1 parent d757d1a commit a38d4e1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
20 changes: 10 additions & 10 deletions lib/widgets/777_slots_screen/control_panel.dart
Expand Up @@ -3,6 +3,7 @@ import 'dart:math';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:triple_seven_slots_game/assets.dart';
import 'package:triple_seven_slots_game/bloc/slot_machine_bloc/slot_machine_bloc.dart';
import 'package:triple_seven_slots_game/bloc/user_balance_cubit/user_balance_cubit.dart';
import 'package:triple_seven_slots_game/widgets/777_slots_screen/bet_cell.dart';
Expand All @@ -24,7 +25,7 @@ class ControlPanel extends StatelessWidget {
ChangeBetButton(
key: decreaseBetKey,
angle: pi / -2,
title: '-', //arrowLeftIc,
asset: arrowLeftIc, //arrowLeftIc,
onPressed: state.isSpinning
? null
: () => context.read<SlotMachineBloc>().add(const DecreaseBet()),
Expand All @@ -35,7 +36,7 @@ class ControlPanel extends StatelessWidget {
ChangeBetButton(
key: increaseBetKey,
angle: pi / 2,
title: '+',
asset: arrowLeftIc,
onPressed: state.isSpinning
? null
: () => context.read<SlotMachineBloc>().add(const IncreaseBet()),
Expand Down Expand Up @@ -81,13 +82,13 @@ class ControlPanel extends StatelessWidget {
class ChangeBetButton extends StatelessWidget {
final double angle;
final Function()? onPressed;
final String title;
final String asset;

const ChangeBetButton({
Key? key,
required this.angle,
required this.onPressed,
required this.title,
required this.asset,
}) : super(key: key);

@override
Expand All @@ -96,12 +97,11 @@ class ChangeBetButton extends StatelessWidget {
angle: angle,
child: ZoomTapAnimation(
onTap: onPressed,
child: Text(title),
// child: SvgPicture.asset(
// asset,
// width: 60,
// key: key,
// ),
child: SvgPicture.asset(
asset,
width: 60,
height: 60,
),
),
);
}
Expand Down
13 changes: 6 additions & 7 deletions test/widget_test.dart
Expand Up @@ -36,14 +36,13 @@ void slotMachineTests() {
await tester.pumpAndSettle();
expect(find.text('5000'), findsOneWidget);

final increaseButton = find.text('+');
await tester.ensureVisible(increaseButton);
final increaseButton = find.byKey(increaseBetKey);
await tester.tap(increaseButton);
await tester.pump(const Duration(seconds: 2));
await tester.pumpAndSettle();
expect(find.text('6000'), findsOneWidget);

final decreaseButton = find.text('-');
final decreaseButton = find.byKey(decreaseBetKey);
await tester.ensureVisible(decreaseButton);
await tester.tap(decreaseButton);
await tester.pump(const Duration(seconds: 2));
Expand All @@ -61,7 +60,7 @@ void slotMachineTests() {
int currentBet = defaultBet;
expect(find.text(defaultBet.toString()), findsOneWidget);

final increaseButton = find.text('+');
final increaseButton = find.byKey(increaseBetKey);
while (currentBet < maxBet) {
currentBet += differenceBet;
await tester.tap(increaseButton);
Expand All @@ -86,7 +85,7 @@ void slotMachineTests() {
int currentBet = defaultBet;
expect(find.text(defaultBet.toString()), findsOneWidget);

final decreaseButton = find.text('-');
final decreaseButton = find.byKey(decreaseBetKey);
while (currentBet > minBet) {
currentBet -= differenceBet;
await tester.tap(decreaseButton);
Expand Down Expand Up @@ -128,10 +127,10 @@ void slotMachineTests() {
await tester.pump();
expect(find.text(defaultBet.toString()), findsOneWidget);

await tester.tap(find.text('+'));
await tester.tap(find.byKey(increaseBetKey));
expect(find.text(defaultBet.toString()), findsOneWidget);

await tester.tap(find.text('-'));
await tester.tap(find.byKey(decreaseBetKey));
expect(find.text(defaultBet.toString()), findsOneWidget);
});

Expand Down

0 comments on commit a38d4e1

Please sign in to comment.