Skip to content

Instantly share code, notes, and snippets.

@hman278
Last active February 7, 2022 12:05
Show Gist options
  • Save hman278/d7419f99e0ca0bdc9e949cd6eea69cdd to your computer and use it in GitHub Desktop.
Save hman278/d7419f99e0ca0bdc9e949cd6eea69cdd to your computer and use it in GitHub Desktop.
navigation
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends MaterialApp {
const MyApp({Key? key}) : super(home: const TextPage(), key: key);
}
class TextPage extends StatefulWidget {
const TextPage({Key? key}) : super(key: key);
@override
_TextPageState createState() => _TextPageState();
}
class _TextPageState extends State<TextPage> {
String _text = '';
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Navigation app'),
actions: [
Row(
children: [
const Text('Next Page', style: TextStyle(fontSize: 20)),
const SizedBox(width: 10),
IconButton(
icon: const Icon(Icons.keyboard_arrow_right),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => TextInputPage(
callback: (value) =>
setState(() => _text = value),
)));
},
),
const SizedBox(width: 50),
],
)
],
),
body: Center(
child: Text(
_text,
style: const TextStyle(fontSize: 20),
)));
}
}
class TextInputPage extends StatelessWidget {
const TextInputPage({Key? key, required this.callback}) : super(key: key);
final Function(String val) callback;
static TextEditingController controller = TextEditingController();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Text Page')),
body: Center(
child: Padding(
padding: const EdgeInsets.all(100),
child: TextField(
controller: controller,
onChanged: (v) {
callback(controller.text);
},
decoration: const InputDecoration(
border: OutlineInputBorder(), labelText: 'Enter text'),
),
),
));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment