Flutter 如何在ShowDialog上制作样式小部件? 问题:

Flutter 如何在ShowDialog上制作样式小部件? 问题:,flutter,dart,Flutter,Dart,我已经完成了对话的其余部分,但顶部有一个圆形溢出化身。我现在不知道怎么做。如图所示 演示图片 可以通过插件解决。用徽章包裹QRCode,并将作为徽章位置的位置参数修改为准确的顶部和左侧值 Badge( position: BadgePosition.topLeft(top: 0,left: 0),//change this to get the right location badgeContent: YourAvatar(), child: YourQRIm

我已经完成了对话的其余部分,但顶部有一个圆形溢出化身。我现在不知道怎么做。如图所示

演示图片

可以通过插件解决。用徽章包裹QRCode,并将作为徽章位置的位置参数修改为准确的顶部左侧

Badge(
      position: BadgePosition.topLeft(top: 0,left: 0),//change this to get the right location
      badgeContent: YourAvatar(),
      child: YourQRImage(),
       
    )
  
可以通过插件解决。用徽章包裹QRCode,并将作为徽章位置的位置参数修改为准确的顶部左侧

Badge(
      position: BadgePosition.topLeft(top: 0,left: 0),//change this to get the right location
      badgeContent: YourAvatar(),
      child: YourQRImage(),
       
    )
  

您需要创建一个主屏幕小部件,在按下或轻触任何按钮时调用函数showDialog,传递您需要的参数,如QRCode图像和化身

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(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: FlatButton(
          color: Colors.blue,
          child: Text("My Dialog"),
          onPressed: () => {
            showDialog(
              context: context,
              barrierDismissible: true,
              builder: (BuildContext context) => MyDialog(),
            ),
          },
        ),
      ),
    );
  }
}
类MyHomePage扩展StatefulWidget{
MyHomePage({Key,this.title}):超级(Key:Key);
最后的字符串标题;
@凌驾
_MyHomePageState createState()=>\u MyHomePageState();
}
类_MyHomePageState扩展状态{
@凌驾
小部件构建(构建上下文){
返回脚手架(
appBar:appBar(
标题:文本(widget.title),
),
正文:中(
孩子:扁平按钮(
颜色:颜色,蓝色,
子:文本(“我的对话框”),
按下:()=>{
显示对话框(
上下文:上下文,
是的,
生成器:(BuildContext上下文)=>MyDialog(),
),
},
),
),
);
}
}
最后创建它的对话类,并使用Stack和Positioned将化身放在对话内容的顶部

class MyDialog extends StatelessWidget {
  MyDialog({
    Key key,
    // Something you need like a QRCode and Avatar Image
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    double radius = 50;
    double padding = 10;
    double hSize = 400;
    double wSize = 400;

    return Dialog(
      shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.circular(10),
      ),
      elevation: 0.0,
      backgroundColor: Colors.transparent,
      child: Container(
        width: 400,
        child: Stack(
          children: <Widget>[
            Container(
              padding: EdgeInsets.all(padding),
              margin: EdgeInsets.only(top: radius),
              decoration: new BoxDecoration(
                color: Colors.white,
                borderRadius: BorderRadius.circular(padding),
              ),
              height: hSize,
              width: wSize,
            ),
            Positioned(
              left: padding,
              right: padding,
              child: CircleAvatar(
                backgroundColor: Colors.indigo,
                radius: radius,
              ),
            ),
          ],
        ),
      ),
    );
  }
}
class MyDialog扩展了无状态小部件{
我的对话({
关键点,
//你需要的东西,比如QRCode和头像
}):super(key:key);
@凌驾
小部件构建(构建上下文){
双半径=50;
双填充=10;
双希则=400;
双wSize=400;
返回对话框(
形状:圆形矩形边框(
边界半径:边界半径。圆形(10),
),
标高:0.0,
背景颜色:颜色。透明,
子:容器(
宽度:400,
子:堆栈(
儿童:[
容器(
填充:边缘集。全部(填充),
边距:仅限边集(顶部:半径),
装饰:新盒子装饰(
颜色:颜色,白色,
边界半径:边界半径。圆形(填充),
),
身高:西泽,
宽度:wSize,
),
定位(
左:填充,
右:填充,
孩子:圆环星(
背景颜色:Colors.indigo,
半径:半径,
),
),
],
),
),
);
}
}
这是一个结果:


您需要创建一个主屏幕小部件,在按下或轻触任何按钮时调用函数showDialog,传递您需要的参数,如QRCode图像和化身

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(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: FlatButton(
          color: Colors.blue,
          child: Text("My Dialog"),
          onPressed: () => {
            showDialog(
              context: context,
              barrierDismissible: true,
              builder: (BuildContext context) => MyDialog(),
            ),
          },
        ),
      ),
    );
  }
}
类MyHomePage扩展StatefulWidget{
MyHomePage({Key,this.title}):超级(Key:Key);
最后的字符串标题;
@凌驾
_MyHomePageState createState()=>\u MyHomePageState();
}
类_MyHomePageState扩展状态{
@凌驾
小部件构建(构建上下文){
返回脚手架(
appBar:appBar(
标题:文本(widget.title),
),
正文:中(
孩子:扁平按钮(
颜色:颜色,蓝色,
子:文本(“我的对话框”),
按下:()=>{
显示对话框(
上下文:上下文,
是的,
生成器:(BuildContext上下文)=>MyDialog(),
),
},
),
),
);
}
}
最后创建它的对话类,并使用Stack和Positioned将化身放在对话内容的顶部

class MyDialog extends StatelessWidget {
  MyDialog({
    Key key,
    // Something you need like a QRCode and Avatar Image
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    double radius = 50;
    double padding = 10;
    double hSize = 400;
    double wSize = 400;

    return Dialog(
      shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.circular(10),
      ),
      elevation: 0.0,
      backgroundColor: Colors.transparent,
      child: Container(
        width: 400,
        child: Stack(
          children: <Widget>[
            Container(
              padding: EdgeInsets.all(padding),
              margin: EdgeInsets.only(top: radius),
              decoration: new BoxDecoration(
                color: Colors.white,
                borderRadius: BorderRadius.circular(padding),
              ),
              height: hSize,
              width: wSize,
            ),
            Positioned(
              left: padding,
              right: padding,
              child: CircleAvatar(
                backgroundColor: Colors.indigo,
                radius: radius,
              ),
            ),
          ],
        ),
      ),
    );
  }
}
class MyDialog扩展了无状态小部件{
我的对话({
关键点,
//你需要的东西,比如QRCode和头像
}):super(key:key);
@凌驾
小部件构建(构建上下文){
双半径=50;
双填充=10;
双希则=400;
双wSize=400;
返回对话框(
形状:圆形矩形边框(
边界半径:边界半径。圆形(10),
),
标高:0.0,
背景颜色:颜色。透明,
子:容器(
宽度:400,
子:堆栈(
儿童:[
容器(
填充:边缘集。全部(填充),
边距:仅限边集(顶部:半径),
装饰:新盒子装饰(
颜色:颜色,白色,
边界半径:边界半径。圆形(填充),
),
身高:西泽,
宽度:wSize,
),
定位(
左:填充,
右:填充,
孩子:圆环星(
背景颜色:Colors.indigo,
半径:半径,
),
),
],
),
),
);
}
}
这是一个结果:


使用
堆栈
widget使用
堆栈
小部件