Нижняя шторка showModalBottomSheet в Flutter
Дополнительные действия - выбор темы, фильтр,
короткая форма - часто выезжают снизу.
Функция
showModalBottomSheet
показывает панель над текущим экраном.
Содержимое - обычный виджет, чаще
Column
с отступами.
Шторку закрывают Navigator.pop(context)
из её контекста - так же, как диалог.
Параметр isScrollControlled: true
нужен, если панель должна занимать
большую часть высоты; для короткого меню
достаточно значения по умолчанию:
import 'package:flutter/material.dart';
void main() {
runApp(const MaterialApp(home: SheetDemoPage()));
}
class SheetDemoPage extends StatelessWidget {
const SheetDemoPage({super.key});
void openActions(BuildContext context) {
showModalBottomSheet<void>(
context: context,
builder: (sheetContext) {
return SafeArea( // clear of the gesture bar
child: Column(
mainAxisSize: MainAxisSize.min, // height from the content
children: [
ListTile(
leading: const Icon(Icons.share),
title: const Text('Share'),
onTap: () {
Navigator.pop(sheetContext);
},
),
ListTile(
leading: const Icon(Icons.delete),
title: const Text('Delete'),
onTap: () {
Navigator.pop(sheetContext);
},
),
],
),
);
},
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Sheet')),
body: Center(
child: ElevatedButton(
onPressed: () => openActions(context),
child: const Text('Actions'),
),
),
);
}
}
Откройте шторку с заголовком
'Sort' и тремя
ListTile:
'By date', 'By name', 'By price'. Любой пункт
закрывает шторку.