Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save HansMuller/880b28b02b92e00b97c0ec858d4c9cb6 to your computer and use it in GitHub Desktop.

Select an option

Save HansMuller/880b28b02b92e00b97c0ec858d4c9cb6 to your computer and use it in GitHub Desktop.
// TabController with a single element fails assertion on horizontal tab scroll after number of tabs was decreased from 2 to 1
// https://github.com/flutter/flutter/issues/18481
import 'package:flutter/material.dart';
class TabControllerBug extends StatefulWidget {
@override
_TabControllerBugState createState() => new _TabControllerBugState();
}
class _TabControllerBugState extends State<TabControllerBug> with TickerProviderStateMixin {
const List<Icon> icons1 = <Icon>[
const Icon(Icons.android, semanticLabel: 'Android'),
];
const List<Icon> icons2 = <Icon>[
const Icon(Icons.event, semanticLabel: 'Event'),
const Icon(Icons.home, semanticLabel: 'Home'),
];
List<Icon> _icons;
TabController _tabController;
@override
void initState() {
_tabController = new TabController(length: 2, vsync: this);
_icons = icons2;
super.initState();
}
@override
Widget build(BuildContext context) {
return new Scaffold(
body: new Center(
child: new Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
new RaisedButton(
child: const Text('reset _tabController, _icons'),
onPressed: () {
setState(() {
_tabController = new TabController(length: 1, vsync: this);
_icons = icons1;
});
},
),
const SizedBox(height: 48.0),
new SizedBox(
height: 100.0,
child: new TabBarView(
controller: _tabController,
children: _icons.map((Icon icon) {
return new Container(
padding: const EdgeInsets.all(12.0),
child: new Card(
child: new Center(
child: icon,
),
),
);
}).toList()
),
),
new TabPageSelector(controller: _tabController),
],
),
),
);
}
}
class TabControllerBugApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
home: new TabControllerBug(),
);
}
}
void main() {
runApp(new TabControllerBugApp());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment