<aside> 💡 교재 7장 내용 간략하게 줄여서 강의하기
</aside>
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
initialRoute: "/login",
routes: {
"/login": (context) => LoginPage(),
"/home": (context) => HomePage(),
},
);
}
}
class HomePage extends StatelessWidget {
const HomePage({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(),
body: Center(
child: Text("HomePage"),
),
floatingActionButton: FloatingActionButton(
child: Icon(Icons.arrow_back),
onPressed: () {
Navigator.pop(context);
},
),
);
}
}
/**
* -1.0, -1.0 => 1.0, 1.0
* ex) -1.0, -1.0 (가장왼쪽 상단)
* ex) 0, 0 (가운데)
* ex) 1.0, 1.0 (오른쪽하단)
*/
class LoginPage extends StatelessWidget {
const LoginPage({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
body: Align(
alignment: Alignment(0.0, 0.0),
child: Text("LoginPage"),
),
floatingActionButton: FloatingActionButton(
child: Icon(Icons.ac_unit_sharp),
onPressed: () {
Navigator.pushNamed(context, "/home");
},
),
);
}
}