代码之家  ›  专栏  ›  技术社区  ›  user48956

为什么这个容器的背景是透明的,只对web透明?

  •  0
  • user48956  · 技术社区  · 5 年前

    我不明白。我有一个容器,它的背景色是(不透明的)蓝色。

    • enter image description here
    • 在网络上,它是透明的: enter image description here

    import 'package:flutter/material.dart';
    
    // The background color of the badges.
    const Color DEFAULT_BADGE_COLOR = Color.fromARGB(255, 109, 207, 214);
    
    Text colorText(String text, Color color, {double size: 10}) => Text.rich(
      TextSpan(
          text: text,
          style: TextStyle(
            fontSize: size,
            fontFamily: "Poppins",
            color: color,
          )),
      overflow: TextOverflow.ellipsis,
      maxLines: 1,
      softWrap: false,
    );
    
    Widget badge(String text, {Color color: DEFAULT_BADGE_COLOR,
      Color textColor: Colors.white,
      double textSize: 30,
      hInpadding: 0.4,
      vInpadding: 0}) =>
      Container(
            child: colorText(text, textColor, size: textSize),
            padding: EdgeInsets.fromLTRB(
                textSize * hInpadding,
                textSize * vInpadding,
                textSize * hInpadding,
                textSize * vInpadding),
            decoration: new BoxDecoration(
                color: color,
                borderRadius:
                new BorderRadius.all(new Radius.circular(textSize * 10))),
          );
    
    Widget content() =>
        Center(child: SizedBox(width:200, height:200, child:Stack(children:[
          Positioned(top:0, left:0, child:badge("ABCDEFG")),
          Positioned(top:10, left:10, child:badge("ABCDEFG")),
          Positioned(top:20, left:20, child:badge("ABCDEFG")),
    ])));
    
    
    class DemoApp extends StatelessWidget {
      WidgetBuilder content;
    
      DemoApp(this.content);
    
      @override
      Widget build(BuildContext context) =>
          MaterialApp(title: 'Flutter Playground', home: Material(child:content(context)));
    }
    
    main()=>runApp(DemoApp((c)=>content()));
    
    
    0 回复  |  直到 5 年前