class ImagesView extends StatefulWidget {
final String pic;
const ImagesView({Key? key, required this.pic}) : super(key: key);
@override
State<ImagesView> createState() => _ImagesViewState();
}
class _ImagesViewState extends State<ImagesView> {
int downproess = 0;
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: () {
Get.back();
},
child: comBottonBar(
child: Scaffold(
appBar: AppBar(
leading: comLeading(),
actions: [
IconButton(
onPressed: () {
Get.bottomSheet(Container(
height: 120,
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(12),
topRight: Radius.circular(12)),
color: appColor.main),
child: SingleChildScrollView(
padding: EdgeInsets.all(12),
child: Column(
children: [
Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
toolsWidget(
iconData: CocoIconBold.Arrow_Bottom_3,
msg: '保存图片',
ontap: () async {
Get.back();
try {
var response = await dio.get(
widget.pic,
options: Options(
responseType: ResponseType.bytes),
onReceiveProgress: (count, total) {
setState(() {
downproess =
((count / total) * 100)
.toInt();
});
},
);
final result =
await ImageGallerySaver.saveImage(
Uint8List.fromList(
response.data),
quality: 80,
name: widget.pic.replaceAll(
'https://', ''));
comToast(msg: '保存成功');
} on DioError catch (e) {
comToast(msg: '保存失败');
Exception(e);
}
vibrate();
}),
],
),
const SizedBox(height: 12),
TextButton(
onPressed: () {
Get.back();
},
child: Text(
'关闭',
style: TextStyle(color: appColor.sub),
))
],
),
),
));
},
icon: Icon(
CocoIconBold.Menu_1,
size: 20,
))
],
),
body: Stack(alignment: Alignment.center, children: [
Padding(
padding: const EdgeInsets.all(12.0),
child: Center(
child: PhotoView(
loadingBuilder: (context, event) => Center(
child: comLoading(),
),
imageProvider: CachedNetworkImageProvider(widget.pic),
backgroundDecoration: BoxDecoration(),
)),
),
Visibility(
visible: downproess == 0 || downproess == 100 ? false : true,
child: CircularProgressIndicator(
value: downproess / 100,
backgroundColor: appColor.black.withOpacity(0.02),
valueColor: AlwaysStoppedAnimation<Color>(
(appColor.sub),
),
),
)
]),
),
),
);
}
}
版权属于:
narakuyang
作品采用:
《
署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0)
》许可协议授权
评论