flutter 传值

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';

void main() => runApp(new MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      title: 'Flutter Demo',
      home: new TodoScreen(
          todos: new List.generate(
              20, (i) => new Todo(
              '我是表头 $i 项',
              '我是内容 $i')
          )
      ),
    );
  }
}

class Todo {
  final String title;
  final String description;

  Todo(this.title, this.description);
}

class TodoScreen extends StatelessWidget {
  final List<Todo> todos;

  TodoScreen({Key key, @required this.todos}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text('第一个页面'),
      ),
      body: new ListView.builder(
          itemBuilder: (context, index) {
            return new ListTile(
              title: new Text(todos[index].title),
              subtitle: new Text(todos[index].description),
              onTap: (){
                Navigator.push(
                  context, new MaterialPageRoute(
                    builder: (context) => new DetailScreen(todo: todos[index]),
                ),);
              },
            );
          }),
    );
  }
}

class DetailScreen extends StatelessWidget {
  final Todo todo;

  DetailScreen({Key key, @required this.todo}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text("${todo.title}"),
      ),
      body: new Padding(
        padding: new EdgeInsets.all(16.0),
        child: new Text('${todo.description}'),
      ),
    );
  }
}

效果:

6F3C947F-92A7-4A72-A134-43FB5DD171C

FA90C7CA-73DA-4622-AA68-B5674B4673E7

限制滑动到空白的地方

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text('第一个页面'),
      ),
      body: new ListView.builder(
          itemBuilder: (context, index) {
            if (index < todos.length) {
              return new ListTile(
                title: new Text(todos[index].title),
                subtitle: new Text(todos[index].description),
                onTap: (){
                  Navigator.push(
                    context, new MaterialPageRoute(
                    builder: (context) => new DetailScreen(todo: todos[index]),
                  ),);
                },
              );
            }
          }),
    );
  }