flutter - 如何制作响应式 svg -flutter
问题描述
获得响应式 svg 图像的最佳方法是什么,我考虑过使用 MediaQuery,但可能并不完全适合每个屏幕。
我使用了堆栈和定位,因为我有更多的东西要放在一个屏幕上,它们会重叠。
我想对此做出回应:
class Shape extends StatelessWidget {
static Route route() {
return MaterialPageRoute<void>(builder: (_) => Shape());
}
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.transparent,
leading: IconButton(
icon: const Icon(Icons.arrow_back_ios, color: Colors.black),
onPressed: () => Navigator.of(context).pop(),
),
),
body: _profilePage(context),
);
}
Widget _profilePage(BuildContext context) {
return SafeArea(
child: Align(
child: Center(
child: Stack(children: <Widget>[
Positioned(
width: MediaQuery.of(context).size.width * 1,
height: MediaQuery.of(context).size.height,
top: MediaQuery.of(context).size.width * 0.4,
child: _curved(context),
),
]),
),
),
);
// });
}
Widget _curved(BuildContext context) {
return SvgPicture.asset(
'assets/images/shape_curved.svg',
color:Colors.green,
allowDrawingOutsideViewBox: true,
);}
解决方案
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(children: [
Flexible(
flex: 2,
child: Container(
color: Colors.yellow,
child: Container(
decoration: BoxDecoration(
color: Colors.green,
borderRadius: BorderRadius.only(
bottomRight: Radius.circular(80.0),
))),
),
),
Flexible(
child: Container(
color: Colors.green,
child: Container(
decoration: BoxDecoration(
color: Colors.yellow,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(80.0),
))),
),
),
]),
);
}
}
推荐阅读
- git - 全局 .gitignore 不忽略文件
- angular - 在角度路由保护中使用可观察的 applicationRef.isStable 时出现奇怪的区域问题
- r - 您如何使用 mapply 函数从数据集中创建随机抽取?
- java - 如何使用数组列表中的索引并转换为 int?
- android - 如何从 adb 终端擦除缓存 android?
- angular - 使用 AWS Cognito 和 Keycloak 作为 OIDC 提供程序处理身份验证响应时出错
- python-3.x - 在 Pandas 中按组均值创建大均值中心变量
- python - 使用 pytest 选择覆盖测试套件
- c# - ZipFile ExtractToDirectory 错误的文件夹名称 Unicode
- python - Python - 使用重音字母