Màn hình 1

import 'package:flutter/material.dart';
import './second_screen.dart';

void main() => runApp(const MyApp());

class MyApp extends StatelessWidget {
const MyApp({super.key});

@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
useMaterial3: true,
),
home: const MyHomePage());
}
}

class MyHomePage extends StatelessWidget {
const MyHomePage({super.key});

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text(
'Flutter Example',
),
),
body: Center(
child: Center(
child: ElevatedButton(
child: const Text('Go to Second Screen with Data'),
onPressed: () {
String data = 'Trần Minh Thái - Screen 2';
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => SecondScreen(data: data)),
);
},
),
),
),
);
}
}

màn hình 2

import 'package:flutter/material.dart';

class SecondScreen extends StatelessWidget {
final String data;
const SecondScreen({super.key, required this.data});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Second Screen'),
),
body: Center(
child: Text('Truyền vào: $data'),
),
);
}
}