【问题标题】:How do I make Scaffold.bottomSheet partly transparent?如何使 Scaffold.bottomSheet 部分透明?
【发布时间】:2019-11-04 17:51:01
【问题描述】:

有没有办法让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'),
    );
  }
}

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

【问题讨论】:

    标签: flutter


    【解决方案1】:
    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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-11-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-20
      相关资源
      最近更新 更多