Last active
November 28, 2022 11:36
-
-
Save ben-xD/43e60e23d7c315b2b78d834611f23272 to your computer and use it in GitHub Desktop.
Debug: PageView, inside ListView, inside Column
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
// Doesn't actually use the PageView, because it doesn't current work. | |
import 'package:flutter/material.dart'; | |
const Color darkBlue = Color.fromARGB(255, 18, 32, 47); | |
void main() { | |
runApp(MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
theme: ThemeData.dark().copyWith( | |
scaffoldBackgroundColor: darkBlue, | |
), | |
debugShowCheckedModeBanner: false, | |
home: Scaffold( | |
body: Center( | |
child: MyWidget(), | |
), | |
), | |
); | |
} | |
} | |
class MyWidget extends StatefulWidget { | |
Widget createPage(int page, Color color) { | |
return Container( | |
color: color, | |
child: Padding( | |
padding: EdgeInsets.symmetric(vertical: 200.0), | |
child: Text("Page: $page. Swipe right to go to next page"), | |
), | |
); | |
} | |
late final List<Widget> pages = [ | |
createPage(1, Colors.purple), | |
createPage(2, Colors.red) | |
]; | |
@override | |
createState() => _MyWidgetState(); | |
} | |
class _MyWidgetState extends State<MyWidget> { | |
late final PageController _pageController; | |
int page = 0; | |
@override | |
initState() { | |
super.initState(); | |
_pageController = PageController(); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Column( | |
children: [ | |
Expanded( | |
child: ListView( | |
children: [ | |
Container(color: Colors.green, child: const Text("Top of screen, scrollable.")), | |
// This works | |
Column( | |
children: widget.pages, | |
), | |
// PageView tries to take the full height. Without Flexible, PageView is unbounded. | |
// Flexible( | |
// child: PageView.builder( | |
// itemCount: widget.pages.length, | |
// controller: _pageController, | |
// onPageChanged: (int index) => setState(() => page = index), | |
// itemBuilder: (context, index) => widget.pages[index], | |
// ), | |
// ) | |
], | |
), | |
), | |
Container(color: Colors.green, child: const Text("Bottom of screen, always")), | |
], | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment