Skip to content
This repository has been archived by the owner on Nov 7, 2023. It is now read-only.

Commit

Permalink
refactor: synchronously use setState and only animateToPage when …
Browse files Browse the repository at this point in the history
…there is `hasClients`
  • Loading branch information
zyrouge committed Oct 25, 2021
1 parent 065c0c7 commit 3084ad2
Show file tree
Hide file tree
Showing 20 changed files with 316 additions and 222 deletions.
12 changes: 2 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,14 @@ The developer of this application does not have any affiliation with any of the
[![Latest release](https://img.shields.io/github/release/zyrouge/yukino-app.svg?style=flat)](https://github.com/zyrouge/yukino-app/releases/)
[![CodeFactor](https://www.codefactor.io/repository/github/yukino-app/yukino/badge/next)](https://www.codefactor.io/repository/github/yukino-app/yukino/overview/next)
[![Android (Apk)](https://github.com/yukino-app/yukino/actions/workflows/android-build.yml/badge.svg)](https://github.com/yukino-app/yukino/actions/workflows/android-build.yml)
[![Linux (AppImage)](https://github.com/yukino-app/yukino/actions/workflows/linux-build.yml/badge.svg)](https://github.com/yukino-app/yukino/actions/workflows/linux-build.yml)
[![Linux (AppImage & tar)](https://github.com/yukino-app/yukino/actions/workflows/linux-build.yml/badge.svg)](https://github.com/yukino-app/yukino/actions/workflows/linux-build.yml)
[![MacOS (Dmg)](https://github.com/yukino-app/yukino/actions/workflows/macos-build.yml/badge.svg)](https://github.com/yukino-app/yukino/actions/workflows/macos-build.yml)
[![Windows (Zip & Installer)](https://github.com/yukino-app/yukino/actions/workflows/windows-build.yml/badge.svg)](https://github.com/yukino-app/yukino/actions/workflows/windows-build.yml)
[![iOS (Ipa)](https://github.com/yukino-app/yukino/actions/workflows/ios-build.yml/badge.svg)](https://github.com/yukino-app/yukino/actions/workflows/ios-build.yml)

<!-- [![Site](https://github.com/zyrouge/yukino-app/actions/workflows/Deploy.yml/badge.svg)](https://github.com/zyrouge/yukino-app/actions/workflows/Deploy.yml) [![CodeQL](https://github.com/zyrouge/yukino-app/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/zyrouge/yukino-app/actions/workflows/codeql-analysis.yml) [![Publish (Electron)](<https://github.com/zyrouge/yukino-app/actions/workflows/Publish%20(Electron).yml/badge.svg?branch=main>)](<https://github.com/zyrouge/yukino-app/actions/workflows/Publish%20(Electron).yml>) [![Publish (Capacitor - Android)](<https://github.com/zyrouge/yukino-app/actions/workflows/Publish%20(Capacitor%20-%20Android).yml/badge.svg>)](<https://github.com/zyrouge/yukino-app/actions/workflows/Publish%20(Capacitor%20-%20Android).yml>) [![CodeFactor](https://www.codefactor.io/repository/github/zyrouge/yukino-app/badge/next)](https://www.codefactor.io/repository/github/zyrouge/yukino-app/overview/next)
## Download

You can download the latest version of app from the [releases](https://github.com/zyrouge/yukino-app/releases) tab.
## Preview
![Home](./screenshots/desktop/home.png)
> All previews available at [https://zyrouge.github.io/yukino-app/](https://zyrouge.github.io/yukino-app/) -->
You can download the latest version of app from the [releases](https://github.com/yukino-app/yukino/releases) tab.

## Links

Expand Down
4 changes: 2 additions & 2 deletions cli/flutter-cli/build/linux/tar/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { dirname, join } from "path";
import { ensureDir, createWriteStream } from "fs-extra";
import { ensureDir, readdir, createWriteStream } from "fs-extra";
import tar from "tar";
import { getVersion } from "../../../../others/version/print";
import { Logger } from "../../../../logger";
Expand All @@ -24,7 +24,7 @@ export const build = async () => {
gzip: true,
cwd: buildDir,
},
[buildDir]
await readdir(buildDir)
).pipe(stream);
await new Promise((resolve) => stream.once("close", resolve));

Expand Down
12 changes: 8 additions & 4 deletions lib/components/trackers/detailed_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -588,14 +588,18 @@ class _DetailedItemState extends State<DetailedItem> {
) =>
SafeArea(
child: widget.onEdit((final DetailedInfo info) {
setState(() {
item = info;
});
if (mounted) {
setState(() {
item = info;
});
}
}),
),
);

setState(() {});
if (mounted) {
setState(() {});
}
},
tooltip: Translator.t.edit(),
child: const Icon(Icons.edit),
Expand Down
3 changes: 2 additions & 1 deletion lib/components/trackers/profile_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ class _ProfilePageState extends State<ProfilePage>
);

tabController.addListener(() {
if (tabController.index != pageController.page) {
if (tabController.index != pageController.page &&
pageController.hasClients) {
pageController.animateToPage(
tabController.index,
duration: animationDuration,
Expand Down
24 changes: 15 additions & 9 deletions lib/components/trackers/trackers_tile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ class _TrackersTileItemState extends State<TrackersTileItem>
final ResolvedTrackerItem unknown, [
final dynamic data,
]) {
if (item.value != null &&
if (mounted &&
item.value != null &&
widget.tracker.isItemSameKind(item.value!, unknown)) {
setState(() {
item.resolve(unknown);
Expand Down Expand Up @@ -206,9 +207,11 @@ class _TrackersTileItemState extends State<TrackersTileItem>
value,
);

setState(() {
searches.resolve(results);
});
if (mounted) {
setState(() {
searches.resolve(results);
});
}
},
),
if (searches.hasResolved &&
Expand Down Expand Up @@ -249,11 +252,11 @@ class _TrackersTileItemState extends State<TrackersTileItem>
);
}

this.setState(() {
item.resolve(resolved);
});

if (mounted) {
this.setState(() {
item.resolve(resolved);
});

Navigator.of(context).pop();
}
},
Expand Down Expand Up @@ -450,7 +453,10 @@ class _TrackersTileItemState extends State<TrackersTileItem>
onChanged: (final bool enabled) async {
await widget.tracker
.setEnabled(widget.title, widget.plugin, enabled);
setState(() {});

if (mounted) {
setState(() {});
}
},
)
else
Expand Down
25 changes: 16 additions & 9 deletions lib/pages/anime_page/anime_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -154,20 +154,24 @@ class _PageState extends State<Page>
}

Future<void> goToPage(final Pages page) async {
await controller.animateToPage(
page.index,
duration: const Duration(milliseconds: 200),
curve: Curves.easeInOut,
);
if (controller.hasClients) {
await controller.animateToPage(
page.index,
duration: const Duration(milliseconds: 200),
curve: Curves.easeInOut,
);
}
}

void setEpisode(
final int? index,
) {
setState(() {
currentEpisodeIndex = index;
episode = index != null ? info!.sortedEpisodes[index] : null;
});
if (mounted) {
setState(() {
currentEpisodeIndex = index;
episode = index != null ? info!.sortedEpisodes[index] : null;
});
}
}

Widget getHero(
Expand Down Expand Up @@ -381,8 +385,10 @@ class _PageState extends State<Page>
locale = val;
info = null;
});

getInfo(removeCache: true);
}

Navigator.of(context).pop();
},
),
Expand Down Expand Up @@ -439,6 +445,7 @@ class _PageState extends State<Page>
setState(() {
info = null;
});

getInfo(removeCache: true);
},
tooltip: Translator.t.refetch(),
Expand Down

0 comments on commit 3084ad2

Please sign in to comment.