Skip to content

Instantly share code, notes, and snippets.

@nilsreichardt
Created August 15, 2021 10:45
Show Gist options
  • Save nilsreichardt/e0d3b247da70f6080ea5917ce346c5a4 to your computer and use it in GitHub Desktop.
Save nilsreichardt/e0d3b247da70f6080ea5917ce346c5a4 to your computer and use it in GitHub Desktop.
Passing data via Flutter Navigator
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
home: HomePage(),
);
}
}
class HomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text("Home")),
body: Center(
child: ElevatedButton(
child: const Text("Button"),
onPressed: () {
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => const NextPage("Passed data"),
),
);
},
),
),
);
}
}
class NextPage extends StatelessWidget {
final String data;
const NextPage(this.data);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text("Home")),
body: Center(
child: Text(data)
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment