꿈꾸는 시스템 디자이너

Flutter Example - Navigation & routing | Send data to a new screen 본문

Tutorial/Flutter with App

Flutter Example - Navigation & routing | Send data to a new screen

독행소년 2019. 9. 27. 00:21
import 'package:flutter/material.dart';

class NaviSendData extends StatelessWidget {
  List<String> fruits = ["Apples", "Oranges", "Bananas"];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text("First Screen")),
      body: ListView.builder(
        itemCount: fruits.length,
        itemBuilder: (context, index) {
          return Card(
            child: ListTile(
              title: Text("${fruits[index]}"),
              onTap: () {
                Navigator.push(
                    context,
                    MaterialPageRoute(
                        builder: (context) => NaviReceiveData(fruits[index])));
              },
            ),
          );
        },
      ),
    );
  }
}

class NaviReceiveData extends StatelessWidget {
  final String fruit;

  NaviReceiveData(this.fruit);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text("Second Screen")),
      body: Center(
        child: Row(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text("Received Data: "),
            Text(
              fruit,
              style: TextStyle(fontSize: 20),
            )
          ],
        ),
      ),
    );
  }
}

 

 

▶ Go to Table of Contents | 강의 목차로 이동


※ This example is also available in the Flutter Code Examples app. | 본 예제는 Flutter Code Examples 앱에서도 제공됩니다.

 

Flutter Code Examples - Google Play 앱

Are you a beginner at Flutter? Check out the various features of Flutter through the demo. Source code for all demos is also provided.

play.google.com

Comments