diff --git a/lib/core/utils.dart b/lib/core/utils.dart index 150eced..5f4e411 100644 --- a/lib/core/utils.dart +++ b/lib/core/utils.dart @@ -2,8 +2,6 @@ import "package:flutter/material.dart"; import "package:fluttertoast/fluttertoast.dart"; import "package:url_launcher/url_launcher.dart"; -import "sources.dart"; - /// A transparent [SizedBox] with a width and height of 10.0 const seperator = SizedBox(width: 10.0, height: 10.0); @@ -63,43 +61,3 @@ Future launch(Uri url) async { await Fluttertoast.showToast(msg: "Cannot launch $url"); } } - -Widget renderOriginal(BuildContext context, AsyncSnapshot snapshot) { - if (snapshot.connectionState == ConnectionState.done) { - return Image.memory(snapshot.data!.data); - } else if (snapshot.connectionState == ConnectionState.waiting) { - return loadingIndicator(content: "Loading image"); - } else { - return errorIndicator(content: "Invalid state: ${snapshot.connectionState}"); - } -} - -Widget renderSmall(BuildContext context, AsyncSnapshot snapshot) { - var edge = MediaQuery.of(context).size.width / 2; - if (snapshot.connectionState == ConnectionState.done) { - return Image.memory( - snapshot.data!.data, - width: edge, - height: edge, - fit: BoxFit.cover, - ); - } else if (snapshot.connectionState == ConnectionState.waiting) { - return SizedBox( - width: edge, - height: edge, - child: loadingIndicator( - content: "Loading image", - size: edge / 4, - ), - ); - } else { - return SizedBox( - width: edge, - height: edge, - child: errorIndicator( - content: "Invalid state: ${snapshot.connectionState}", - size: edge / 4, - ), - ); - } -} diff --git a/lib/pages/images.dart b/lib/pages/images.dart index 93c1f56..a54924f 100644 --- a/lib/pages/images.dart +++ b/lib/pages/images.dart @@ -43,7 +43,7 @@ class _ImagesPageState extends State { closeDrawer(); singleProcessor.resetProgress(forced: true); - multiProcessor.clear(); + multiProcessor.clearProcess(); }; } @@ -255,7 +255,38 @@ class _ImagesPageState extends State { setState(() => _displayMultipleImages = false); } }, - child: FutureBuilder(future: process.future, builder: renderSmall), + child: FutureBuilder( + future: process.future, + builder: (context, snapshot) { + var edge = MediaQuery.of(context).size.width / 2; + if (snapshot.connectionState == ConnectionState.done) { + return Image.memory( + snapshot.data!.data, + width: edge, + height: edge, + fit: BoxFit.cover, + ); + } else if (snapshot.connectionState == ConnectionState.waiting) { + return SizedBox( + width: edge, + height: edge, + child: loadingIndicator( + content: "Loading image", + size: edge / 4, + ), + ); + } else { + return SizedBox( + width: edge, + height: edge, + child: errorIndicator( + content: "Invalid state: ${snapshot.connectionState}", + size: edge / 4, + ), + ); + } + }, + ), ); } @@ -277,7 +308,15 @@ class _ImagesPageState extends State { : Center( child: FutureBuilder( future: singleProcessor.inProgress.future, - builder: renderOriginal, + builder: (context, snapshot) { + if (snapshot.connectionState == ConnectionState.done) { + return Image.memory(snapshot.data!.data); + } else if (snapshot.connectionState == ConnectionState.waiting) { + return loadingIndicator(content: "Loading image"); + } else { + return errorIndicator(content: "Invalid state: ${snapshot.connectionState}"); + } + }, ), ), floatingActionButton: Column(