72 lines
1.5 KiB
Dart
72 lines
1.5 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
class Todo {
|
|
final String title;
|
|
final String description;
|
|
|
|
const Todo(this.title, this.description);
|
|
}
|
|
|
|
void main() {
|
|
runApp(
|
|
MaterialApp(
|
|
title: 'Passing Data',
|
|
home: TodosScreen(
|
|
todos: List.generate(
|
|
20,
|
|
(i) => Todo(
|
|
'Todo $i',
|
|
'A description of what needs to be done for Todo $i',
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
class TodosScreen extends StatelessWidget {
|
|
const TodosScreen({super.key, required this.todos});
|
|
|
|
final List<Todo> todos;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: AppBar(title: const Text('Todos')),
|
|
body: ListView.builder(
|
|
itemCount: todos.length,
|
|
itemBuilder: (context, index) {
|
|
return ListTile(
|
|
title: Text(todos[index].title),
|
|
onTap: () {
|
|
Navigator.push(
|
|
context,
|
|
MaterialPageRoute<void>(
|
|
builder: (context) => DetailScreen(todo: todos[index]),
|
|
),
|
|
);
|
|
},
|
|
);
|
|
},
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class DetailScreen extends StatelessWidget {
|
|
const DetailScreen({super.key, required this.todo});
|
|
|
|
final Todo todo;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: AppBar(title: Text(todo.title)),
|
|
body: Padding(
|
|
padding: const EdgeInsets.all(16),
|
|
child: Text(todo.description),
|
|
),
|
|
);
|
|
}
|
|
}
|