TabNavigator animates selected TabView
The TabBar's selection is now represented by a TabBarSelection object which encapsulates both the previous and currently selected indices and the Performance used to animate the selection indicator. Added a TabBarView class which displays a tab's contents. It uses a shared TabBarSelection to stay in sync with a TabBar. The TabBarView scrolls in sync with the TabBar when the selection changes. Eventually it will allow one to fling the selection forward or backwards. Added a tabBar property to ToolBar. Typically the corresponding TabBarView will be the body of the toolbar's Scaffold. Removed TabNavigatorView and TabNavigator. Added a widget gallery tabs demo page. Removed the old tabs demo.
This commit is contained in:
@@ -7,16 +7,13 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
int selectedIndex = 2;
|
||||
TabBarSelection selection;
|
||||
|
||||
Widget buildFrame({ List<String> tabs, bool isScrollable: false }) {
|
||||
return new TabBar(
|
||||
labels: tabs.map((String tab) => new TabLabel(text: tab)).toList(),
|
||||
selectedIndex: selectedIndex,
|
||||
isScrollable: isScrollable,
|
||||
onChanged: (int tabIndex) {
|
||||
selectedIndex = tabIndex;
|
||||
}
|
||||
selection: selection,
|
||||
isScrollable: isScrollable
|
||||
);
|
||||
}
|
||||
|
||||
@@ -24,56 +21,56 @@ void main() {
|
||||
test('TabBar tap selects tab', () {
|
||||
testWidgets((WidgetTester tester) {
|
||||
List<String> tabs = <String>['A', 'B', 'C'];
|
||||
selectedIndex = 2;
|
||||
selection = new TabBarSelection(index: 2);
|
||||
|
||||
tester.pumpWidget(buildFrame(tabs: tabs, isScrollable: false));
|
||||
expect(tester.findText('A'), isNotNull);
|
||||
expect(tester.findText('B'), isNotNull);
|
||||
expect(tester.findText('C'), isNotNull);
|
||||
expect(selectedIndex, equals(2));
|
||||
expect(selection.index, equals(2));
|
||||
|
||||
tester.pumpWidget(buildFrame(tabs: tabs, isScrollable: false));
|
||||
tester.tap(tester.findText('B'));
|
||||
tester.pump();
|
||||
expect(selectedIndex, equals(1));
|
||||
expect(selection.index, equals(1));
|
||||
|
||||
tester.pumpWidget(buildFrame(tabs: tabs, isScrollable: false));
|
||||
tester.tap(tester.findText('C'));
|
||||
tester.pump();
|
||||
expect(selectedIndex, equals(2));
|
||||
expect(selection.index, equals(2));
|
||||
|
||||
tester.pumpWidget(buildFrame(tabs: tabs, isScrollable: false));
|
||||
tester.tap(tester.findText('A'));
|
||||
tester.pump();
|
||||
expect(selectedIndex, equals(0));
|
||||
expect(selection.index, equals(0));
|
||||
});
|
||||
});
|
||||
|
||||
test('Scrollable TabBar tap selects tab', () {
|
||||
testWidgets((WidgetTester tester) {
|
||||
List<String> tabs = <String>['A', 'B', 'C'];
|
||||
selectedIndex = 2;
|
||||
selection = new TabBarSelection(index: 2);
|
||||
|
||||
tester.pumpWidget(buildFrame(tabs: tabs, isScrollable: true));
|
||||
expect(tester.findText('A'), isNotNull);
|
||||
expect(tester.findText('B'), isNotNull);
|
||||
expect(tester.findText('C'), isNotNull);
|
||||
expect(selectedIndex, equals(2));
|
||||
expect(selection.index, equals(2));
|
||||
|
||||
tester.pumpWidget(buildFrame(tabs: tabs, isScrollable: true));
|
||||
tester.tap(tester.findText('B'));
|
||||
tester.pump();
|
||||
expect(selectedIndex, equals(1));
|
||||
expect(selection.index, equals(1));
|
||||
|
||||
tester.pumpWidget(buildFrame(tabs: tabs, isScrollable: true));
|
||||
tester.tap(tester.findText('C'));
|
||||
tester.pump();
|
||||
expect(selectedIndex, equals(2));
|
||||
expect(selection.index, equals(2));
|
||||
|
||||
tester.pumpWidget(buildFrame(tabs: tabs, isScrollable: true));
|
||||
tester.tap(tester.findText('A'));
|
||||
tester.pump();
|
||||
expect(selectedIndex, equals(0));
|
||||
expect(selection.index, equals(0));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user