Skip to content

Commit

Permalink
Minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Serious-senpai committed Jan 16, 2023
1 parent 0b9a006 commit 11f7fd9
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 45 deletions.
42 changes: 0 additions & 42 deletions lib/core/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -63,43 +61,3 @@ Future<void> launch(Uri url) async {
await Fluttertoast.showToast(msg: "Cannot launch $url");
}
}

Widget renderOriginal(BuildContext context, AsyncSnapshot<ImageData> 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<ImageData> 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,
),
);
}
}
45 changes: 42 additions & 3 deletions lib/pages/images.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class _ImagesPageState extends State<ImagesPage> {

closeDrawer();
singleProcessor.resetProgress(forced: true);
multiProcessor.clear();
multiProcessor.clearProcess();
};
}

Expand Down Expand Up @@ -255,7 +255,38 @@ class _ImagesPageState extends State<ImagesPage> {
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,
),
);
}
},
),
);
}

Expand All @@ -277,7 +308,15 @@ class _ImagesPageState extends State<ImagesPage> {
: 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(
Expand Down

0 comments on commit 11f7fd9

Please sign in to comment.