Skip to content

Instantly share code, notes, and snippets.

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 HansMuller/5d0e670737501b4b25e1b694325c4f4f to your computer and use it in GitHub Desktop.
Save HansMuller/5d0e670737501b4b25e1b694325c4f4f to your computer and use it in GitHub Desktop.
// See https://github.com/flutter/flutter/issues/10531
/*
In release mode the app is often asked to layout before the engine
has initialized to the point where the size of the screen is known.
In that case the app is built and laid out with 0x0 constraints and
then later with the screen's actual size.
The phantom tabbar scrolling seen here upon app startup is due to the
scrollable tabbar's scroll offset being "corrected" once the tab bar's
size is constrained to a non-zero value. The correction happens
in ScrollPosition.applyNewDimensions() which calls the IdleScrollActivity
with the same name, which ballistic-scrolls the scroll offset back to 0.
The phantom scroll can be worked around but not building anything
until the app's size is non-zero.
*/
import 'package:flutter/material.dart';
class AppBarBug extends StatefulWidget {
@override
_AppBarBugState createState() => new _AppBarBugState();
}
class _AppBarBugState extends State<AppBarBug> with SingleTickerProviderStateMixin {
final List<Widget> tabs = <Widget>[
new Tab(text: 'NEW MEXICO'),
new Tab(text: 'GABBA'),
new Tab(text: 'HEY'),
];
TabController _tabController;
@override
void initState() {
super.initState();
_tabController = new TabController(vsync: this, length: tabs.length);
}
@override
void dispose() {
_tabController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return new LayoutBuilder(
builder: (_, BoxConstraints constraints) {
// In release mode, layout may begin before the engine has initialized
// to the point where the size of the screen is known. We'll be built
// again, when the incoming constraints are non-zero.
if (constraints.biggest == Size.zero)
return new Container();
return new Scaffold(
appBar: new AppBar(
title: new Text('AppBarBug'),
bottom: new PreferredSize(
preferredSize: const Size.fromHeight(30.0),
child: new Padding(
padding: const EdgeInsets.symmetric(horizontal: 15.0),
child: new Align(
alignment: FractionalOffset.center,
child: new LayoutBuilder(
builder: (BuildContext _, BoxConstraints constraints) {
return new TabBar(
controller: _tabController,
isScrollable: true,
tabs: tabs,
);
},
),
),
),
),
),
body: new Center(
child: new Text('Hello World'),
),
);
},
);
}
}
void main() {
runApp(new MaterialApp(home: new AppBarBug()));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment