Flutter - iOS. Tapping statusbar scrolls all listviews within a bottom navigation bar to the top.

644 views
Skip to first unread message

Samuel Akabo

unread,
Apr 23, 2020, 1:15:17 PM4/23/20
to Flutter Development (flutter-dev)
This is a sample code to demonstrate the unexpected behaviour.


import
'package:flutter/material.dart';

void main() {
runApp(MyApp());
}

class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: HomePage(),
);
}
}

class HomePage extends StatefulWidget {
@override
_HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
final _bodies = [
Feeds(),
Search(),
];

int _currentIndex = 0;

@override
Widget build(BuildContext context) {
return Scaffold(
body: IndexedStack(
index: _currentIndex,
children: _bodies,
),
bottomNavigationBar: BottomNavigationBar(
items: <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: Icon(Icons.home),
title: Text('Feeds'),
),
BottomNavigationBarItem(
icon: Icon(Icons.search),
title: Text('Search'),
),
],
onTap: (index) => setState(
() => _currentIndex = index,
),
),
);
}
}

class Feeds extends StatelessWidget {
@override
Widget build(BuildContext context) {
return PrimaryScrollController(
controller: ScrollController(),
child: Scaffold(
body: NestedScrollView(
controller: PrimaryScrollController.of(context),
headerSliverBuilder: (_, __) {
return [
SliverAppBar(
pinned: true,
title: Text('Feeds'),
),
];
},
body: ListView.builder(
itemBuilder: (_, int index) {
return Container(
height: 100,
margin: EdgeInsets.only(
left: 16,
right: 16,
bottom: 16,
),
decoration: BoxDecoration(
color: Colors.blueGrey.withOpacity(0.3),
borderRadius: BorderRadius.circular(15),
),
);
},
),
),
),
);
}
}

class Search extends StatelessWidget {
@override
Widget build(BuildContext context) {
return PrimaryScrollController(
controller: ScrollController(),
child: Scaffold(
body: NestedScrollView(
controller: PrimaryScrollController.of(context),
headerSliverBuilder: (_, __) {
return [
SliverAppBar(
pinned: true,
title: Text('Search'),
),
];
},
body: ListView.builder(
itemBuilder: (_, int index) {
return Container(
height: 100,
margin: EdgeInsets.only(
left: 16,
right: 16,
bottom: 16,
),
decoration: BoxDecoration(
color: Colors.lightGreen.withOpacity(0.5),
borderRadius: BorderRadius.circular(15),
),
);
},
),
),
),
);
}
}


Ralph Bergmann

unread,
Apr 23, 2020, 2:09:26 PM4/23/20
to Samuel Akabo, Flutter Development (flutter-dev)
Do you have a question about it?
--
You received this message because you are subscribed to the Google Groups "Flutter Development (flutter-dev)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/flutter-dev/90e8ef90-9995-46d9-bda9-64bbf0ef4e21%40googlegroups.com.

Samuel Akabo

unread,
Apr 23, 2020, 2:15:25 PM4/23/20
to Flutter Development (flutter-dev)
Well...I was expecting the other listview not to scroll to the top. I would really appreciate any pointers if this is not a bug.
Reply all
Reply to author
Forward
0 new messages