Skip to content

Instantly share code, notes, and snippets.

@branflake2267
Created March 27, 2018 04:37
Show Gist options
  • Save branflake2267/667ecfab4e056a2734c88b004f11cc1d to your computer and use it in GitHub Desktop.
Save branflake2267/667ecfab4e056a2734c88b004f11cc1d to your computer and use it in GitHub Desktop.
Flutter - Passing data to the next page. Used in the youtube video.
import 'package:flutter/material.dart';
void main() => runApp(new MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: 'Flutter Demo',
theme: new ThemeData(
primarySwatch: Colors.blue,
),
home: new MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
@override
_MyHomePageState createState() => new _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
var _textController = new TextEditingController();
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text("Home Page"),
),
body: new ListView(
children: <Widget>[
new ListTile(
title: new TextField(
controller: _textController,
),
),
new ListTile(
title: new RaisedButton(
child: new Text("Next"),
onPressed: () {
var route = new MaterialPageRoute(
builder: (BuildContext context) =>
new NextPage(value: _textController.text),
);
Navigator.of(context).push(route);
},
),
),
],
),
);
}
}
class NextPage extends StatefulWidget {
final String value;
NextPage({Key key, this.value}) : super(key: key);
@override
_NextPageState createState() => new _NextPageState();
}
class _NextPageState extends State<NextPage> {
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text("Next Page"),
),
body: new Text("${widget.value}"),
);
}
}
@branflake2267
Copy link
Author

This source was used in this Youtube video: https://youtu.be/MsycCv5r2Wo

videos - flutter

@Roy-Tuhin
Copy link

What if I want to pass image (capture image) instead of text----> body: new Text("${widget.value}"),

@shreeniwaas
Copy link

how to pass images in next screen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment