Flutter:如何更改CupertinoActionSheet的背景颜色?

fnvucqvd  于 2023-03-31  发布在  Flutter
关注(0)|答案(1)|浏览(448)

我怎样才能改变flutter中的CupertinoActionSheet背景颜色?我尝试了很多可能的方法。但是它的默认颜色没有改变。我该怎么做?

样品代码:

import 'package:flutter/cupertino.dart';
import 'package:service/services/page_navigation_service.dart';
import 'package:service/view/variables/colors_variable.dart';
import 'package:service/view/variables/text_style.dart';

class MyCupertinoBottomSheet extends StatelessWidget {
  final Widget child;
  final String? title;

  const MyCupertinoBottomSheet({Key? key, required this.child, this.title})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return CupertinoActionSheet(
      title: Text(
        title ?? "",
        style: CustomTextStyle.titleBoldStyleDarkGrey,
      ),
      message: Container(
        padding: const EdgeInsets.all(16.0),
        // height: MediaQuery.of(context).size.height * 0.5,
        decoration: const BoxDecoration(
          color: CustomColors.white,
          borderRadius: BorderRadius.only(
            topLeft: Radius.circular(16.0),
            topRight: Radius.circular(16.0),
          ),
        ),
        child: child,
      ),
      actions: [
        CupertinoActionSheetAction(
          onPressed: () {
            PageNavigationService.backScreen();
          },
          child: const Text('CONFIRM',
              style: CustomTextStyle.mediumBoldStylePrimary),
        ),
        CupertinoActionSheetAction(
          onPressed: () {
            PageNavigationService.backScreen();
          },
          child: const Text(
            'CLOSE',
            style: CustomTextStyle.mediumBoldStyleDarkGrey,
          ),
        ),
      ],
    );
  }
}

我也用了MaterialCupertinoTheme,但都不管用。

wqlqzqxt

wqlqzqxt1#

使用cupertinoTheme Package 您的CupertinoActionSheet,如下所示

CupertinoTheme(
        data: CupertinoThemeData(
          barBackgroundColor: Colors.blue, // Add your desired color
        ),
        child: CupertinoActionSheet(......),
),

相关问题