Skip to content

Instantly share code, notes, and snippets.

@remonh87
Last active October 10, 2020 13:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save remonh87/bd6d8583e70955b23f2fdccfb390a9b3 to your computer and use it in GitHub Desktop.
Save remonh87/bd6d8583e70955b23f2fdccfb390a9b3 to your computer and use it in GitHub Desktop.
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:sliver_tools/sliver_tools.dart';
void main() {
testWidgets('This succeeds', (tester) async {
var result = 0;
final sut = MaterialApp(
home: Scaffold(
body: Center(
child: CustomScrollView(
slivers: [
SliverStack(
children: [
SliverToBoxAdapter(
child: SizedBox(
height: 400,
width: 400,
),
),
SliverToBoxAdapter(
child: TextButton(
child: Text('test'),
onPressed: () {
result++;
},
),
)
],
)
],
),
),
),
);
await tester.pumpWidget(sut);
await tester.pumpAndSettle();
await tester.tap(find.text('test'));
await tester.pumpAndSettle();
expect(result, 1);
});
testWidgets('this fail', (tester) async {
var result = 0;
final sut = MaterialApp(
home: Scaffold(
body: Center(
child: CustomScrollView(
slivers: [
SliverStack(
children: [
SliverToBoxAdapter(
child: SizedBox(
height: 100,
width: 400,
),
),
SliverPositioned(
left: 40,
right: 40,
top: 225,
child: TextButton(
child: Text('test'),
onPressed: () {
result++;
},
),
),
],
)
],
),
),
),
);
await tester.pumpWidget(sut);
await tester.pumpAndSettle();
await tester.tap(find.text('test'));
await tester.pumpAndSettle();
expect(result, 1);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment