첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
본 블로그는 광고를 포함하고 있습니다.
광고 클릭에서 발생하는 수익금은 모두 블로그 콘텐츠 향상을 위해 쓰여집니다.

728x90
반응형
728x170

▶ person.dart

class Person {
  String name;
  int age;

  Person(this.name, this.age);
}

 

728x90

 

▶ detail_page.dart

import 'package:flutter/material.dart';
import 'package:test_app/person.dart';

class DetailPage extends StatelessWidget {
  final Person person;

  DetailPage({@required this.person});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Test Application / Detail Page'),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text(
                '${person.name}, ${person.age}'
            ),
            SizedBox(
              height: 10,
            ),
            RaisedButton(
              child: Text('메인 페이지'),
              color: Colors.orange,
              onPressed: () {
                Navigator.pop(context, 'OK');
              },
            )
          ],
        ),
      ),
    );
  }
}

 

300x250

 

▶ main_page.dart

import 'package:flutter/material.dart';
import 'package:test_app/person.dart';
import 'package:test_app/detail_page.dart';

class MainPage extends StatefulWidget {
  @override
  _MainPageState createState() => _MainPageState();
}

class _MainPageState extends State<MainPage> {
  String _result;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Test Application / Main Page'),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            RaisedButton(
              child: Text('상세 페이지'),
              color: Colors.orange,
              onPressed: () async {
                setState(() {
                  _result = '';
                });

                final Person person = Person('홍길동', 20);

                final result = await Navigator.push(
                  context,
                  MaterialPageRoute(builder: (context) => DetailPage(person: person)),
                );

                setState(() {
                  _result = result;
                });
              },
            ),
            Text(
              '결과 : $_result',
            ),
          ],
        ),
      ),
    );
  }
}

 

▶ main.dart

import 'package:flutter/material.dart';
import 'package:test_app/main_page.dart';

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

class TestApplication extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Test Application',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MainPage(),
    );
  }
}
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요