Flutter: Základní widgety
Z MiS
(Rozdíly mezi verzemi)
(→Tlačítka: Jednoduché tlačítko.) |
(→ListView: Kostra ListView) |
||
| Řádka 34: | Řádka 34: | ||
== ListView == | == ListView == | ||
| + | * Pro zobrazení seznamu <code>seznam</code> můžeme použít ListView: | ||
| + | Expanded( | ||
| + | child: ListView.builder( | ||
| + | itemCount: _seznam.length, | ||
| + | itemBuilder: (context, index) { | ||
| + | return ListTile( | ||
| + | title: Text('${_seznam[index].abc}'), | ||
| + | subtitle: Text('${_seznam[index].def}'), | ||
| + | ); | ||
| + | }, | ||
| + | ), | ||
| + | ), | ||
== Jednoduchý dialog == | == Jednoduchý dialog == | ||
Verze z 21. 2. 2025, 06:26
Obsah |
Uspořádání stránky
Center( child: ... )
Column( mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[ ... ] )
Textová pole
TextField(
controller: _abcController,
decoration: const InputDecoration(
labelText: 'Popis – co zadávat',
),
keyboardType: TextInputType.number, // Pokud chceme omezit vstup na číselné hodnoty
),
- Kontroler textového pole
final TextEditingController _abcController = TextEditingController();
- Zpracování obsahu textového pole
final double totalPrice = double.parse(parsedValue = _abcController.text.trim());
- Obdobně lze
int.parse(...).
Tlačítka
ElevatedButton(
onPressed: _nazevMetodyReakce,
child: const Text('Popis tlačítka'),
),
ListView
- Pro zobrazení seznamu
seznammůžeme použít ListView:
Expanded(
child: ListView.builder(
itemCount: _seznam.length,
itemBuilder: (context, index) {
return ListTile(
title: Text('${_seznam[index].abc}'),
subtitle: Text('${_seznam[index].def}'),
);
},
),
),
Jednoduchý dialog
showDialog(
context: context,
builder: (context) {
return AlertDialog(
title: const Text('Nadpis dialogu'),
content: Text('Text zprávy...'),
actions: <Widget>[
TextButton(
onPressed: () {
Navigator.of(context).pop();
},
child: const Text('OK'),
),
],
);
},
);