Skip to content

Instantly share code, notes, and snippets.

@chooyan-eng
Created November 24, 2025 08:24
Show Gist options
  • Select an option

  • Save chooyan-eng/af3c5ba512ebeb8530777c791b7bdceb to your computer and use it in GitHub Desktop.

Select an option

Save chooyan-eng/af3c5ba512ebeb8530777c791b7bdceb to your computer and use it in GitHub Desktop.
Demonstration for changing nested Navigator size depending on current page.
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