小编Sin*_*afi的帖子

如何根据背景图片更改文本颜色 - Flutter

我想根据背景图像更改文本(和图标)颜色以提高可见性。

我试过: 使用palette_generator包,检查背景图像的主色,并 从flutter_statusbarcolor包中使用WhiteForgroundForColor函数(返回一个bool)为我的文本(和图标)颜色选择黑色或白色。

问题:有时主色会变成空。在我的测试中,这种情况发生在黑色和白色,我不知道有什么方法可以找出哪一种。

Future<bool> useWhiteTextColor(String imageUrl) async {
  PaletteGenerator paletteGenerator =
      await PaletteGenerator.fromImageProvider(
    NetworkImage(imageUrl),

    // Images are square
    size: Size(300, 300),

    // I want the dominant color of the top left section of the image
    region: Offset.zero & Size(40, 40),
  );

  Color dominantColor = paletteGenerator.dominantColor?.color;

  // Here's the problem 
  // Sometimes dominantColor returns null
  // With black and white background colors in my tests
  if (dominantColor == null) print('Dominant Color null'); …
Run Code Online (Sandbox Code Playgroud)

textcolor dart flutter

14
推荐指数
3
解决办法
8135
查看次数

Flutter如何检查Sliver AppBar是展开还是折叠?

我正在Flutter中使用带有背景小部件的SliverAppBar

问题是,展开后,标题和图标(引导和动作)应为白色,以便正确看到;折叠时,应将其更改为黑色

我如何能得到任何想法布尔出来的吗?或其他解决此问题的方法。

谢谢。

class SliverExample extends StatefulWidget {
  final Widget backgroundWidget;
  final Widget bodyWidgets;

  SliverExample({
    this.backgroundWidget,
    this.body,
  });
  @override
  _SliverExampleState createState() => _SliverExampleState();
}

class _SliverExampleState extends State<SliverExample> {

  // I need something like this
  // To determine if SliverAppBar is expanded or not.
  bool isAppBarExpanded = false;

  @override
  Widget build(BuildContext context) {

    // To change the item's color accordingly
    // To be used in multiple places …
Run Code Online (Sandbox Code Playgroud)

flutter flutter-sliver

7
推荐指数
4
解决办法
7095
查看次数

标签 统计

flutter ×2

dart ×1

flutter-sliver ×1

textcolor ×1