这是indexloc提供的服务,不要输入任何密码
Skip to content

Fix TabBar crash with SliverAppBar #154485

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/flutter/lib/src/material/reorderable_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ class ReorderableListView extends StatefulWidget {
///
///
/// ** See code in examples/api/lib/material/reorderable_list/reorderable_list_view.build_default_drag_handles.0.dart **
///{@end-tool}
/// {@end-tool}
final bool buildDefaultDragHandles;

/// {@macro flutter.widgets.reorderable_list.padding}
Expand Down
8 changes: 5 additions & 3 deletions packages/flutter/lib/src/material/tabs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1742,9 +1742,11 @@ class _TabBarState extends State<TabBar> {
wrappedTabs[previousIndex] = _buildStyledTab(wrappedTabs[previousIndex], false, animation, _defaults);
} else {
// The user is dragging the TabBarView's PageView left or right.
final int tabIndex = _currentIndex!;
final Animation<double> centerAnimation = _DragAnimation(_controller!, tabIndex);
wrappedTabs[tabIndex] = _buildStyledTab(wrappedTabs[tabIndex], true, centerAnimation, _defaults);
if (_currentIndex! < widget.tabs.length) {
final int tabIndex = _currentIndex!;
final Animation<double> centerAnimation = _DragAnimation(_controller!, tabIndex);
wrappedTabs[tabIndex] = _buildStyledTab(wrappedTabs[tabIndex], true, centerAnimation, _defaults);
}
if (_currentIndex! > 0) {
final int tabIndex = _currentIndex! - 1;
final Animation<double> previousAnimation = ReverseAnimation(_DragAnimation(_controller!, tabIndex));
Expand Down
4 changes: 2 additions & 2 deletions packages/flutter/lib/src/widgets/editable_text.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1618,10 +1618,10 @@ class EditableText extends StatefulWidget {
/// {@endtemplate}
final bool cursorOpacityAnimates;

///{@macro flutter.rendering.RenderEditable.cursorOffset}
/// {@macro flutter.rendering.RenderEditable.cursorOffset}
final Offset? cursorOffset;

///{@macro flutter.rendering.RenderEditable.paintCursorAboveText}
/// {@macro flutter.rendering.RenderEditable.paintCursorAboveText}
final bool paintCursorAboveText;

/// Controls how tall the selection highlight boxes are computed to be.
Expand Down
49 changes: 49 additions & 0 deletions packages/flutter/test/material/tabs_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5947,6 +5947,55 @@ void main() {
gesture.removePointer();
});

testWidgets('No crash if TabBar build called before didUpdateWidget with SliverAppBar', (WidgetTester tester) async {
// Regression test for https://github.com/flutter/flutter/issues/154484.
final List<String> tabs = <String>[];

await tester.pumpWidget(
MaterialApp(
home: StatefulBuilder(
builder: (BuildContext context, StateSetter setState) {
return DefaultTabController(
length: tabs.length,
child: Scaffold(
body: CustomScrollView(
slivers: <Widget>[
SliverAppBar(
actions: <Widget>[
TextButton(
child: const Text('Add Tab'),
onPressed: () {
setState(() {
tabs.add('Tab ${tabs.length + 1}');
});
},
),
],
bottom: TabBar(
tabs: tabs.map((String tab) => Tab(text: tab)).toList(),
),
),
],
),
),
);
},
),
),
);

// Initializes with zero tabs.
expect(find.text('Tab 1'), findsNothing);
expect(find.text('Tab 2'), findsNothing);

// No crash after tabs added.
await tester.tap(find.text('Add Tab'));
await tester.pumpAndSettle();
expect(find.text('Tab 1'), findsOneWidget);
expect(find.text('Tab 2'), findsNothing);
expect(tester.takeException(), isNull);
});

testWidgets('Do not crash if the controller and TabBarView are updated at different phases(build and layout) of the same frame', (WidgetTester tester) async {
// Regression test for https://github.com/flutter/flutter/issues/104994.
List<String> tabTextContent = <String>[];
Expand Down