-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Closed
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work listf: scrollingViewports, list views, slivers, etc.Viewports, list views, slivers, etc.found in release: 3.19Found to occur in 3.19Found to occur in 3.19found in release: 3.22Found to occur in 3.22Found to occur in 3.22frameworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onr: fixedIssue is closed as already fixed in a newer versionIssue is closed as already fixed in a newer versionteam-frameworkOwned by Framework teamOwned by Framework teamtriaged-frameworkTriaged by Framework teamTriaged by Framework team
Description
Steps to reproduce
- Create a page view with a page controller
- Put a builder or subwidget inside of
pages - Display
PageController.pagefrom inside the builder/subwidget, checkingcontroller.hasClientsfirst
Expected results
The current page is displayed or a fallback if no page is available (has client is false or the page is null)
Actual results
Page value is only available after content dimensions are established. is thrown and the screen flashes red before properly displaying the page number.
Code sample
Code sample
class PageDemo extends StatefulWidget {
const PageDemo({super.key});
@override
State<PageDemo> createState() => _PageDemoState();
}
class _PageDemoState extends State<PageDemo> {
final PageController controller = PageController();
@override
Widget build(BuildContext context) {
if (controller.hasClients) {
print(controller.page);
}
return MaterialApp(
home: Scaffold(
body: PageView(
controller: controller,
children: [
// Only throws if a builder or sub widget is used here.
Builder(
builder: (context) {
final double currentPage =
controller.hasClients ? controller.page ?? -1 : -2;
return Center(child: Text(currentPage.toString()));
},
),
],
),
),
);
}
}Screenshots or Video
Screenshots / Video demonstration
[Upload media here]
Logs
Logs
[Paste your logs here]Flutter Doctor output
Doctor output
[Paste your output here]hamza-imran75
Metadata
Metadata
Assignees
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work listf: scrollingViewports, list views, slivers, etc.Viewports, list views, slivers, etc.found in release: 3.19Found to occur in 3.19Found to occur in 3.19found in release: 3.22Found to occur in 3.22Found to occur in 3.22frameworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onr: fixedIssue is closed as already fixed in a newer versionIssue is closed as already fixed in a newer versionteam-frameworkOwned by Framework teamOwned by Framework teamtriaged-frameworkTriaged by Framework teamTriaged by Framework team