-
Notifications
You must be signed in to change notification settings - Fork 0
/
19.dart
130 lines (122 loc) · 3.51 KB
/
19.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import 'package:flutter/material.dart';
class Transporte {
final String titulo;
final IconData icone;
const Transporte(this.titulo, this.icone);
}
const List<Transporte> transportes = <Transporte>[
Transporte('Carro', Icons.directions_car),
Transporte('Bicicleta', Icons.directions_bike),
Transporte('Barco', Icons.directions_boat),
Transporte('Ônibus', Icons.directions_bus),
Transporte('Trem', Icons.directions_railway),
];
void main() => runApp(MeuAplicativo());
class MeuAplicativo extends StatelessWidget {
@override
Widget build(BuildContext context) => MaterialApp(
home: PrimeiraRota(),
debugShowCheckedModeBanner: false,
);
}
class PrimeiraRota extends StatefulWidget {
@override
PrimeiraRotaState createState() => PrimeiraRotaState();
}
class PrimeiraRotaState extends State<PrimeiraRota> {
Transporte transporte = transportes[0];
void selecionar(Transporte transporteEscolhido) =>
setState(() => this.transporte = transporteEscolhido);
List<PopupMenuItem<Transporte>> getListaItensMenu() {
List<PopupMenuItem<Transporte>> lista;
lista = transportes.skip(2).map(
(Transporte transporte) {
return PopupMenuItem<Transporte>(
value: transporte,
child: Text(transporte.titulo),
);
},
).toList();
return lista;
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
leading: IconButton(
icon: Icon(Icons.video_collection),
onPressed: () => Navigator.push(
context,
MaterialPageRoute(builder: (context) => SegundaRota()),
),
tooltip: 'Coleção de Vídeos',
),
title: Text('Primeira Rota'),
actions: <Widget>[
IconButton(
icon: Icon(transportes[0].icone),
onPressed: () => selecionar(transportes[0]),
),
IconButton(
icon: Icon(transportes[1].icone),
onPressed: () => selecionar(transportes[1]),
),
PopupMenuButton<Transporte>(
onSelected: selecionar,
itemBuilder: (BuildContext context) => getListaItensMenu(),
),
],
),
body: Padding(
padding: EdgeInsets.all(16),
child: Cartao(this.transporte),
),
);
}
}
class SegundaRota extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Segunda Rota"),
),
body: Center(
child: ElevatedButton(
onPressed: () => Navigator.pop(context),
child: Text('Voltar para a Primeira Rota'),
),
),
);
}
}
class Cartao extends StatelessWidget {
final Transporte transporte;
Cartao(this.transporte);
@override
Widget build(BuildContext context) {
return Card(
color: Colors.white,
child: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Icon(
this.transporte.icone,
size: 128,
color: Colors.grey[500],
),
Text(
this.transporte.titulo,
style: TextStyle(
fontSize: 40,
color: Colors.grey[500],
),
),
],
),
),
);
}
}