There have been similar issues recently, but they have been resolved and closed on GitHub.
As I'm a newbie, I could be missing something here.
After an orientation change, the page index reverts to zero, but the selected BottomNavigationBarItem is as it was.
Here page "ONE" is being displayed, but tab "FOUR" was selected prior to rotating the device
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Pageview Orientation Bug',
home: HomePage(),
);
}
}
class HomePage extends StatefulWidget {
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
int _page = 0;
PageController _controller = PageController();
@override
Widget build(BuildContext context) {
return Scaffold(
body: OrientationBuilder(
builder: (context,orientation) {
return orientation == Orientation.portrait
? Column(
children: [
Expanded(child: Container(color: Colors.grey)),
Expanded(
child: PageView(
controller: _controller,
children: [Text("ONE"), Text("TWO"),Text("THREE"), Text("FOUR"),],
),
),
],
)
: Row(
children: [
Expanded(child: Container(color: Colors.grey)),
Expanded(
child: PageView(
controller: _controller,
children: [Text("ONE"), Text("TWO"),Text("THREE"), Text("FOUR"),],
),
),
],
);
}
),
bottomNavigationBar: BottomNavigationBar(
type: BottomNavigationBarType.fixed,
currentIndex: _page,
onTap: (page) {
setState(() {
_page = page;
});
_controller.jumpToPage(page);
},
items: [
BottomNavigationBarItem(
icon: Icon(Icons.directions_bike),
label: "ONE",
),
BottomNavigationBarItem(
icon: Icon(Icons.directions_boat_outlined),
label: "TWO",
),
BottomNavigationBarItem(
icon: Icon(Icons.directions_car),
label: "THREE",
),
BottomNavigationBarItem(
icon: Icon(Icons.directions_run),
label: "FOUR",
),
],
),
);
}
}