Created
June 13, 2021 04:03
-
-
Save keithshep/92320bae18a4f12ed99abe38cf643dea to your computer and use it in GitHub Desktop.
scrollproblem.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/cupertino.dart'; | |
import 'package:flutter/material.dart'; | |
void main() { | |
runApp(MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return CupertinoApp( | |
theme: const CupertinoThemeData(brightness: Brightness.light), | |
home: MyHomePage(), | |
); | |
} | |
} | |
class MyHomePage extends StatelessWidget { | |
MyHomePage({Key? key}) : super(key: key); | |
@override | |
Widget build(BuildContext context) { | |
return CupertinoTabScaffold( | |
tabBar: CupertinoTabBar( | |
items: const <BottomNavigationBarItem>[ | |
BottomNavigationBarItem( | |
icon: Icon(CupertinoIcons.check_mark), | |
label: 'TODO List', | |
), | |
BottomNavigationBarItem( | |
icon: Icon(CupertinoIcons.gear), | |
label: 'Settings', | |
), | |
], | |
), | |
tabBuilder: (context, index) { | |
late final CupertinoTabView returnValue; | |
switch (index) { | |
case 0: | |
returnValue = CupertinoTabView(builder: (context) { | |
return CupertinoPageScaffold( | |
navigationBar: CupertinoNavigationBar(middle: Text('TODOs')), | |
// // Using ListView scrolling works as expected | |
// child: ListView( | |
// children: | |
// List.generate( | |
// 30, | |
// (index) => Container( | |
// height: 50, | |
// color: Colors.amber[100 * (index % 6 + 1)], | |
// child: Center(child: Text('Entry ${index + 1}')), | |
// ), | |
// ) | |
// ), | |
// Using CustomScrollView we can't scroll to entries 1 or 30 | |
child: CustomScrollView( | |
slivers: <Widget>[ | |
SliverList( | |
delegate: SliverChildListDelegate( | |
List.generate( | |
30, | |
(index) => Container( | |
height: 50, | |
color: Colors.amber[100 * (index % 6 + 1)], | |
child: Center(child: Text('Entry ${index + 1}')), | |
), | |
) | |
), | |
), | |
] | |
), | |
); | |
}); | |
break; | |
case 1: | |
returnValue = CupertinoTabView(builder: (context) { | |
return CupertinoPageScaffold( | |
navigationBar: CupertinoNavigationBar( | |
middle: Text('Settings'), | |
), | |
child: CustomScrollView(), | |
); | |
}); | |
break; | |
} | |
return returnValue; | |
}, | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment