Чтобы установить цвет фона showModalBottomSheetво Flutter, вы можете использовать различные методы. Вот несколько примеров кода:
Метод 1: оберните содержимое нижнего листа виджетом Containerи установите его свойство color.
showModalBottomSheet(
context: context,
builder: (BuildContext context) {
return Container(
color: Colors.blue, // Set the desired background color
child: YourContentWidget(),
);
},
);
Метод 2. Используйте виджет Тема, чтобы определить собственную тему для нижнего листа.
showModalBottomSheet(
context: context,
builder: (BuildContext context) {
return Theme(
data: Theme.of(context).copyWith(
// Set the desired background color
canvasColor: Colors.blue,
),
child: YourContentWidget(),
);
},
);
Метод 3. Оберните вызов showModalBottomSheetвнутри виджета Containerи установите его свойство color.
Container(
color: Colors.blue, // Set the desired background color
child: showModalBottomSheet(
context: context,
builder: (BuildContext context) {
return YourContentWidget();
},
),
);
Метод 4. Создайте собственный виджет BottomSheetи установите для него цвет фона.
showModalBottomSheet(
context: context,
builder: (BuildContext context) {
return BottomSheet(
backgroundColor: Colors.blue, // Set the desired background color
onClosing: () {},
builder: (BuildContext context) {
return YourContentWidget();
},
);
},
);
Это всего лишь несколько способов установить цвет фона showModalBottomSheetво Flutter. Не стесняйтесь выбирать тот, который лучше всего соответствует вашим потребностям.