如何使Scaffold.bottomSheet部分透明?

时间:2019-11-04 17:51:01

标签: flutter

是否有一种方法可以使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周围留一个缺口)。

1 个答案:

答案 0 :(得分: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