Created
November 24, 2025 08:24
-
-
Save chooyan-eng/af3c5ba512ebeb8530777c791b7bdceb to your computer and use it in GitHub Desktop.
Demonstration for changing nested Navigator size depending on current page.
This file contains hidden or 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/material.dart'; | |
| void main() { | |
| runApp(const MainApp()); | |
| } | |
| class MainApp extends StatelessWidget { | |
| const MainApp({super.key}); | |
| @override | |
| Widget build(BuildContext context) { | |
| return const MaterialApp( | |
| home: Scaffold( | |
| body: SingleChildScrollView( | |
| child: Column( | |
| children: [ | |
| _SizedContent(height: 300, color: Colors.red), | |
| _SizedContent(height: 200, color: Colors.blue), | |
| _SizedContent(height: 500, color: Colors.green), | |
| _SizedContent(height: 300, color: Colors.yellow), | |
| _SizedContent(height: 200, color: Colors.purple), | |
| _SizedContent(height: 100, color: Colors.orange), | |
| _SizedContent(height: 50, color: Colors.brown), | |
| ], | |
| ), | |
| ), | |
| ), | |
| ); | |
| } | |
| } | |
| class _SizedContent extends StatelessWidget { | |
| const _SizedContent({required this.height, required this.color}); | |
| final double height; | |
| final Color color; | |
| @override | |
| Widget build(BuildContext context) { | |
| return DefaultTextStyle( | |
| style: const TextStyle(fontSize: 32, fontWeight: FontWeight.bold), | |
| child: Navigator( | |
| onGenerateRoute: (settings) { | |
| return MaterialPageRoute( | |
| builder: (c) => GestureDetector( | |
| onTap: () { | |
| Navigator.of(c).push( | |
| MaterialPageRoute( | |
| builder: (c) => GestureDetector( | |
| onTap: () { | |
| Navigator.of(c).pop(); | |
| }, | |
| child: Container( | |
| height: height * 2, | |
| color: color.withAlpha(180), | |
| child: Center(child: Text('Second Page!')), | |
| ), | |
| ), | |
| ), | |
| ); | |
| }, | |
| child: Container( | |
| height: height, | |
| color: color, | |
| child: Center(child: Text('First Page!')), | |
| ), | |
| ), | |
| ); | |
| }, | |
| ), | |
| ); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment