Unverified Commit 5b6d748c authored by Kate Lovett's avatar Kate Lovett Committed by GitHub

Fix sample code crash, add test (#133812)

Fixes https://github.com/flutter/flutter/issues/133402

On web `1 << 32` crashes, 31 is the maximum.
parent 7ade1638
...@@ -405,7 +405,6 @@ final Set<String> _knownMissingTests = <String>{ ...@@ -405,7 +405,6 @@ final Set<String> _knownMissingTests = <String>{
'examples/api/test/widgets/animated_switcher/animated_switcher.0_test.dart', 'examples/api/test/widgets/animated_switcher/animated_switcher.0_test.dart',
'examples/api/test/widgets/transitions/relative_positioned_transition.0_test.dart', 'examples/api/test/widgets/transitions/relative_positioned_transition.0_test.dart',
'examples/api/test/widgets/transitions/positioned_transition.0_test.dart', 'examples/api/test/widgets/transitions/positioned_transition.0_test.dart',
'examples/api/test/widgets/transitions/listenable_builder.3_test.dart',
'examples/api/test/widgets/transitions/sliver_fade_transition.0_test.dart', 'examples/api/test/widgets/transitions/sliver_fade_transition.0_test.dart',
'examples/api/test/widgets/transitions/align_transition.0_test.dart', 'examples/api/test/widgets/transitions/align_transition.0_test.dart',
'examples/api/test/widgets/transitions/fade_transition.0_test.dart', 'examples/api/test/widgets/transitions/fade_transition.0_test.dart',
......
...@@ -39,7 +39,7 @@ class _ListenableBuilderExampleState extends State<ListenableBuilderExample> { ...@@ -39,7 +39,7 @@ class _ListenableBuilderExampleState extends State<ListenableBuilderExample> {
appBar: AppBar(title: const Text('ListenableBuilder Example')), appBar: AppBar(title: const Text('ListenableBuilder Example')),
body: ListBody(listNotifier: _listNotifier), body: ListBody(listNotifier: _listNotifier),
floatingActionButton: FloatingActionButton( floatingActionButton: FloatingActionButton(
onPressed: () => _listNotifier.add(_random.nextInt(1 << 32)), // 1 << 32 is the maximum supported value onPressed: () => _listNotifier.add(_random.nextInt(1 << 31)), // 1 << 31 is the maximum supported value
child: const Icon(Icons.add), child: const Icon(Icons.add),
), ),
), ),
......
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:flutter_api_samples/widgets/transitions/listenable_builder.3.dart' as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Tapping FAB adds to values', (WidgetTester tester) async {
await tester.pumpWidget(const example.ListenableBuilderExample());
final Finder listContent = find.byWidgetPredicate((Widget widget) => widget is example.ListBody);
expect(find.text('Current values:'), findsOneWidget);
expect(find.byIcon(Icons.add), findsOneWidget);
expect(
(tester.widget(listContent) as example.ListBody).listNotifier.values.isEmpty,
isTrue,
);
await tester.tap(find.byType(FloatingActionButton).first);
await tester.pumpAndSettle();
expect(
(tester.widget(listContent) as example.ListBody).listNotifier.values.isEmpty,
isFalse,
);
expect(
(tester.widget(listContent) as example.ListBody).listNotifier.values,
<int>[1464685455],
);
expect(find.text('1464685455'), findsOneWidget);
});
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment