Flutter 中带有描边圆形背景的对话框
Posted
技术标签:
【中文标题】Flutter 中带有描边圆形背景的对话框【英文标题】:Dialog with stroked round background in Flutter 【发布时间】:2020-03-21 12:40:43 【问题描述】:我想创建一个具有圆角背景的对话框,并且该背景具有 3 像素的描边,如附加图像。我在下面的代码中使用了圆角,但是如何在背景中添加笔触?
showDialog(
context: context,
builder: (BuildContext context)
return Dialog(
backgroundColor: pinkBackground,
shape: RoundedRectangleBorder(borderRadius:
BorderRadius.all(Radius.circular(10.0))),
child: Text(
"title",
style: getBodyTextStyle(),
)
);
,
);
【问题讨论】:
【参考方案1】:尝试将Container
添加为您的Dialog
孩子并在其中声明BoxDecoration
showDialog(
context: context,
builder: (BuildContext context)
return Dialog(
backgroundColor: AppColors.colorGreen,
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.all(Radius.circular(10.0))),
child: Container(
decoration: BoxDecoration(
border: Border.all(color: Colors.blueAccent,width: 2),
borderRadius:
BorderRadius.all(Radius.circular(10.0))),
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Text(
"title",
),
),
));
,
);
输出
【讨论】:
【参考方案2】:本地申请:
showDialog(
context: context,
builder: (context)
return Dialog(
backgroundColor: Colors.grey,
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(10.0)),
side: BorderSide(width: 3.0, color: Colors.black),
),
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Text(
"title",
style: getBodyTextStyle(),
),
),
);
,
);
全球应用:
class Application extends StatelessWidget
@override
Widget build(BuildContext context)
final baseThemeData = ThemeData.light();
final themeData = baseThemeData.copyWith(
dialogTheme: baseThemeData.dialogTheme.copyWith(
backgroundColor: Colors.grey,
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(10.0)),
side: BorderSide(width: 3.0, color: Colors.black),
),
),
);
return MaterialApp(
themeMode: ThemeMode.light,
theme: themeData,
...
);
void _openDialog(BuildContext context)
showDialog(
context: context,
builder: (context)
return Dialog(
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Text(
"title",
style: getBodyTextStyle(),
),
),
);
,
);
两种变体的结果:
【讨论】:
以上是关于Flutter 中带有描边圆形背景的对话框的主要内容,如果未能解决你的问题,请参考以下文章