gpt4 book ai didi

flutter - 如何使 Scaffold.bottomSheet 部分透明?

转载 作者:行者123 更新时间:2023-12-05 08:26:01 30 4
gpt4 key购买 nike

有没有办法让 Scaffold.bottomSheet 部分透明(比如显示其背后正文内容的缺口)?我注意到即使只添加 Text 也会隐式地在其下方放置一个白色背景(Material?),我认为这是不可配置的。

class MyHomePage extends StatefulWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
color: Colors.blue,
child: // ...
),
bottomSheet: Text('This is a bottom sheet'),
);
}
}

A screenshot of an app with a white rectangle at the bottom, with a text within it.

FWIW,Scaffold.bottomNavigationBar 支持半透明(例如,您可以在 FAB 周围设置一个缺口)。

最佳答案

import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
home: MyHomePage(title: 'Flutter Demo Home Page'),
theme: ThemeData(
bottomSheetTheme: BottomSheetThemeData(
backgroundColor: Colors.black.withOpacity(0.5)),
),
);
}
}

class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);

final String title;

@override
_MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {

@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.blue,
appBar: AppBar(
title: Text(widget.title),
),
body: Center(),
bottomSheet: Container(
height: 40,
width: MediaQuery.of(context).size.width,
child: Center(child: Text('semi transparent bottom sheet :)', style: TextStyle(color: Colors.white),))
),
);
}
}

这之前是 posted

关于flutter - 如何使 Scaffold.bottomSheet 部分透明?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58698683/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com