mirror of https://github.com/flutter/pinball.git
parent
7f2a29ffe4
commit
6efcce4694
@ -0,0 +1,45 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:pinball/gen/gen.dart';
|
||||
|
||||
/// {@template pinball_button}
|
||||
/// Pinball button with onPressed [VoidCallback] and child [Widget].
|
||||
/// {@endtemplate}
|
||||
class PinballButton extends StatelessWidget {
|
||||
/// {@macro pinball_button}
|
||||
const PinballButton({
|
||||
Key? key,
|
||||
required this.child,
|
||||
this.onPressed,
|
||||
}) : super(key: key);
|
||||
|
||||
/// Child displayed on button.
|
||||
final Widget child;
|
||||
|
||||
/// On pressed callback used for user integration.
|
||||
final VoidCallback? onPressed;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return InkWell(
|
||||
onTap: onPressed,
|
||||
child: DecoratedBox(
|
||||
decoration: BoxDecoration(
|
||||
image: DecorationImage(
|
||||
image: AssetImage(
|
||||
Assets.images.selectCharacter.pinballButton.keyName,
|
||||
),
|
||||
),
|
||||
),
|
||||
child: Center(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 32,
|
||||
vertical: 16,
|
||||
),
|
||||
child: child,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pinball/game/game.dart';
|
||||
|
||||
import '../../../helpers/helpers.dart';
|
||||
|
||||
void main() {
|
||||
const buttonText = 'this is the button text';
|
||||
|
||||
testWidgets('displays button', (tester) async {
|
||||
await tester.pumpApp(
|
||||
const Material(
|
||||
child: PinballButton(
|
||||
child: Text(buttonText),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.text(buttonText), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('on tap calls onPressed callback', (tester) async {
|
||||
var isTapped = false;
|
||||
|
||||
await tester.pumpApp(
|
||||
Material(
|
||||
child: PinballButton(
|
||||
child: const Text(buttonText),
|
||||
onPressed: () {
|
||||
isTapped = true;
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.tap(find.text(buttonText));
|
||||
|
||||
expect(isTapped, isTrue);
|
||||
});
|
||||
}
|
Loading…
Reference in new issue