LoginPage(), "/home": (context) => HomePage() }, ); } } class HomePage extends StatelessWidget { @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(), body: Align( alignment: Alignment.center, // default child: SizedBox( width: 300, child: TextButton( onPressed: () { Navigator.pop(context); }, child: Text("뒤로가기"), style: TextButton.styleFrom( backgroundColor: Colors.black, foregroundColor: Colors.white, ), ), ), ), ); } } class LoginPage extends StatelessWidget { @"> LoginPage(), "/home": (context) => HomePage() }, ); } } class HomePage extends StatelessWidget { @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(), body: Align( alignment: Alignment.center, // default child: SizedBox( width: 300, child: TextButton( onPressed: () { Navigator.pop(context); }, child: Text("뒤로가기"), style: TextButton.styleFrom( backgroundColor: Colors.black, foregroundColor: Colors.white, ), ), ), ), ); } } class LoginPage extends StatelessWidget { @"> LoginPage(), "/home": (context) => HomePage() }, ); } } class HomePage extends StatelessWidget { @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(), body: Align( alignment: Alignment.center, // default child: SizedBox( width: 300, child: TextButton( onPressed: () { Navigator.pop(context); }, child: Text("뒤로가기"), style: TextButton.styleFrom( backgroundColor: Colors.black, foregroundColor: Colors.white, ), ), ), ), ); } } class LoginPage extends StatelessWidget { @">
import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: HomePage(),
      initialRoute: "/login",
      routes: {
        "/login": (context) => LoginPage(),
        "/home": (context) => HomePage()
      },
    );
  }
}

class HomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(),
      body: Align(
        alignment: Alignment.center, // default
        child: SizedBox(
          width: 300,
          child: TextButton(
            onPressed: () {
              Navigator.pop(context);
            },
            child: Text("뒤로가기"),
            style: TextButton.styleFrom(
              backgroundColor: Colors.black,
              foregroundColor: Colors.white,
            ),
          ),
        ),
      ),
    );
  }
}

class LoginPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Column(
        children: [
          SizedBox(
            width: 300,
            child: TextButton(
              onPressed: () {
                // HomePage -> LoginPage (2개가 쌓인다)
                Navigator.pushNamed(context, "/home");
              },
              child: Text("로그인"),
              style: TextButton.styleFrom(
                backgroundColor: Colors.black,
                foregroundColor: Colors.white,
              ),
            ),
          )
        ],
      ),
    );
  }
}