반응형
main.dart
import 'package:flutter/material.dart';
void main() {
runApp(MaterialApp(
initialRoute: '/first',
routes: {
'/first': (context) => const FirstPage(),
'/second': (context) => const SecondPage(),
},
));
}
first_page.dart
class FirstPage extends StatelessWidget {
const FirstPage({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Welcome to Flutter'),
),
body: Center(
child: ElevatedButton(
onPressed: () async {
Navigator.pushNamed(context, '/second', arguments: '인자로 데이터를 넘깁니다.');
},
child: const Text('다음화면'),
),
),
);
}
}
second_page.dart
class SecondPage extends StatelessWidget {
const SecondPage({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
String argument = ModalRoute.of(context)!.settings.arguments as String;
return Scaffold(
appBar: AppBar(
title: const Text('Second Page'),
),
body: Center(
child: Text(argument),
),
);
}
}
반응형
'flutter' 카테고리의 다른 글
[flutter] flutter에서 SQLite 사용하기 (0) | 2023.01.02 |
---|---|
[dart] List.generate (0) | 2023.01.01 |
플러터로 첫 코딩하기! 21- Button 의 필요요소 (0) | 2022.12.31 |
[flutter] project 기본 구조 (0) | 2022.12.31 |
플러터로 첫 코딩하기! 20 - Container 에 Image넣기! (0) | 2022.12.27 |