Flutter 透明背景色彈窗

之前用ScaffoldshowModalBottomSheet方法實(shí)現(xiàn)了一個(gè)半屏幕彈窗.后來需求調(diào)整,要改成背景完全透明的.

Future<T> showModalBottomSheet<T>({
  @required BuildContext context,
  @required WidgetBuilder builder,
  Color backgroundColor,
  double elevation,
  ShapeBorder shape,
  Clip clipBehavior,
  bool isScrollControlled = false,
  bool useRootNavigator = false,
  bool isDismissible = true,
})

showModalBottomSheetbackgroundColor參數(shù)確實(shí)是可以修改整體的背景顏色, 但即使設(shè)置為Colors.transparent也是自帶半透明的黑,而且不能完全透明.

試了幾個(gè)方案還是沒有解決,例如包裹opacity/用route設(shè)置barrier顏色/XXX.


開始搜索吧,百度一下沒什么靠譜的答案,在stackoverflow上有幾個(gè)類似的提問,下面是兩個(gè)最接近的.

但是仍然沒有解決.

感覺自己思維被局限在這一個(gè)showModalBottomSheet方法里了.
喝口水冷靜冷靜,換個(gè)思路,換個(gè)dialog實(shí)現(xiàn)起來很簡潔嘛

showGeneralDialog(
  context: context,
  barrierDismissible:true,
  barrierLabel: '',
  barrierColor: Colors.transparent,
  transitionDuration: Duration(milliseconds: 200),
  pageBuilder: (BuildContext context, Animation<double> animation,Animation<double> secondaryAnimation) {
    return Scaffold(backgroundColor: Colors.transparent, body:yourWidget);  
})

LGTM : )

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容