From 72279ae75cee0e8ddf0f21ff2a530245cbb56346 Mon Sep 17 00:00:00 2001 From: violet-dev Date: Sun, 8 Sep 2024 14:42:41 +0900 Subject: [PATCH 01/10] Remove unused settings --- violet/lib/settings/settings.dart | 27 --------------------------- 1 file changed, 27 deletions(-) diff --git a/violet/lib/settings/settings.dart b/violet/lib/settings/settings.dart index 6fc16883d..bb1f26db5 100644 --- a/violet/lib/settings/settings.dart +++ b/violet/lib/settings/settings.dart @@ -23,10 +23,6 @@ class Settings { // Bookmark Git Settings static late String bookmarkRepository; // default 'example/bookmark' static late String bookmarkHost; // default 'gitee.com' - static late String - bookmarkPrivateKey; // default '-----BEGIN OPENSSH PRIVATE KEY-----\n-----END OPENSSH PRIVATE KEY-----' - static late String bookmarkPublicKey; // default '' - static late String bookmarkPrivateKeyPassword; // default '' // Timeout Settings static late bool ignoreTimeout; // default false @@ -326,10 +322,6 @@ class Settings { bookmarkRepository = await _getString('bookmarkRepository', 'example/bookmark'); bookmarkHost = await _getString('bookmarkHost', 'gitee.com'); - bookmarkPrivateKey = await _getString('bookmarkPrivateKey', - '-----BEGIN OPENSSH PRIVATE KEY-----\n-----END OPENSSH PRIVATE KEY-----'); - bookmarkPrivateKeyPassword = - await _getString('bookmarkPrivateKeyPassword', ''); ignoreTimeout = await _getBool('ignoretimeout'); useVioletServer = await _getBool('usevioletserver'); useDrawer = await _getBool('usedrawer'); @@ -532,25 +524,6 @@ class Settings { await prefs.setString('bookmarkHost', bookmarkHost); } - static Future setBookmarkPrivateKey(String value) async { - bookmarkPrivateKey = value; - - await prefs.setString('bookmarkPrivateKey', bookmarkPrivateKey); - } - - static Future setBookmarkPublicKey(String value) async { - bookmarkPublicKey = value; - - await prefs.setString('bookmarkPublicKey', bookmarkPublicKey); - } - - static Future setBookmarkPrivateKeyPassword(String value) async { - bookmarkPrivateKeyPassword = value; - - await prefs.setString( - 'bookmarkPrivateKeyPassword', bookmarkPrivateKeyPassword); - } - static Future setSearchResultType(int wh) async { searchResultType = wh; From 0414adaac6812af991b1dad457da709dbd14c3c1 Mon Sep 17 00:00:00 2001 From: violet-dev Date: Sun, 8 Sep 2024 14:57:12 +0900 Subject: [PATCH 02/10] Make enum `SearchResultType` --- violet/lib/pages/search/search_page.dart | 23 ++++++------ .../pages/search/search_page_controller.dart | 5 +-- violet/lib/pages/search/search_type.dart | 25 +++++++------ violet/lib/settings/settings.dart | 35 ++++++++++++++++--- 4 files changed, 60 insertions(+), 28 deletions(-) diff --git a/violet/lib/pages/search/search_page.dart b/violet/lib/pages/search/search_page.dart index 56a5c4199..3e9eb2285 100644 --- a/violet/lib/pages/search/search_page.dart +++ b/violet/lib/pages/search/search_page.dart @@ -571,12 +571,13 @@ class ResultPanelWidget extends StatelessWidget { @override Widget build(BuildContext context) { - final columnCount = Settings.searchResultType == 0 ? 3 : 2; + final columnCount = + Settings.searchResultType == SearchResultType.threeGrid ? 3 : 2; final windowWidth = MediaQuery.of(context).size.width; switch (Settings.searchResultType) { - case 0: - case 1: + case SearchResultType.threeGrid: + case SearchResultType.twoGrid: final simpleModeColumnCount = Settings.useTabletMode ? columnCount * 2 : columnCount; return SliverPadding( @@ -602,14 +603,14 @@ class ResultPanelWidget extends StatelessWidget { ), )); - case 2: - case 3: - case 4: + case SearchResultType.bigLine: + case SearchResultType.detail: + case SearchResultType.ultra: if (Settings.useTabletMode || MediaQuery.of(context).orientation == Orientation.landscape) { const kDetailModeColumnCount = 2; final aspectRatioHeight = - Settings.useTabletMode && Settings.searchResultType == 4 + Settings.useTabletMode && Settings.searchResultType.isUltra ? 220 : 130; @@ -634,8 +635,8 @@ class ResultPanelWidget extends StatelessWidget { index, windowWidth, (windowWidth - 4.0) / kDetailModeColumnCount, - showDetail: Settings.searchResultType >= 3, - showUltra: Settings.searchResultType == 4, + showDetail: Settings.searchResultType.isDetailLike, + showUltra: Settings.searchResultType.isUltra, addBottomPadding: true, ); }, @@ -650,8 +651,8 @@ class ResultPanelWidget extends StatelessWidget { index, windowWidth, windowWidth - 4.0, - showDetail: Settings.searchResultType >= 3, - showUltra: Settings.searchResultType == 4, + showDetail: Settings.searchResultType.isDetailLike, + showUltra: Settings.searchResultType.isUltra, addBottomPadding: true, ); }, diff --git a/violet/lib/pages/search/search_page_controller.dart b/violet/lib/pages/search/search_page_controller.dart index bea281cf3..21b2d20ab 100644 --- a/violet/lib/pages/search/search_page_controller.dart +++ b/violet/lib/pages/search/search_page_controller.dart @@ -76,7 +76,8 @@ class SearchPageController extends GetxController { // invisible article is not rendered yet // so we can find live elements if (key.value.currentContext != null) { - final bottomPadding = [8, 8, 0, 0, 0][Settings.searchResultType]; + final bottomPadding = + [8, 8, 0, 0, 0][Settings.searchResultType.index]; _itemHeight = key.value.currentContext!.size!.height + bottomPadding; break; } @@ -85,7 +86,7 @@ class SearchPageController extends GetxController { if (scrollController!.offset.isNaN) return; - final itemPerRow = [3, 2, 1, 1, 1][Settings.searchResultType]; + final itemPerRow = [3, 2, 1, 1, 1][Settings.searchResultType.index]; const searchBarHeight = 64 + 16; final curI = ((scrollController!.offset - searchBarHeight) / _itemHeight + 1) diff --git a/violet/lib/pages/search/search_type.dart b/violet/lib/pages/search/search_type.dart index 8873e26e9..39e2947c3 100644 --- a/violet/lib/pages/search/search_type.dart +++ b/violet/lib/pages/search/search_type.dart @@ -11,12 +11,12 @@ import 'package:violet/style/palette.dart'; class SearchType extends StatelessWidget { const SearchType({super.key}); - Color getColor(int i) { + Color getColor(SearchResultType type) { return Settings.themeWhat - ? Settings.searchResultType == i + ? Settings.searchResultType == type ? Colors.grey.shade200 : Colors.grey.shade400 - : Settings.searchResultType == i + : Settings.searchResultType == type ? Colors.grey.shade900 : Colors.grey.shade400; } @@ -36,11 +36,16 @@ class SearchType extends StatelessWidget { physics: const NeverScrollableScrollPhysics(), child: Column( children: [ - _typeItem(context, Icons.grid_on, 'srt0', 0), - _typeItem(context, MdiIcons.gridLarge, 'srt1', 1), - _typeItem(context, MdiIcons.viewAgendaOutline, 'srt2', 2), - _typeItem(context, MdiIcons.formatListText, 'srt3', 3), - _typeItem(context, MdiIcons.viewSplitVertical, 'srt4', 4, + _typeItem(context, Icons.grid_on, 'srt0', + SearchResultType.threeGrid), + _typeItem(context, MdiIcons.gridLarge, 'srt1', + SearchResultType.twoGrid), + _typeItem(context, MdiIcons.viewAgendaOutline, 'srt2', + SearchResultType.bigLine), + _typeItem(context, MdiIcons.formatListText, 'srt3', + SearchResultType.detail), + _typeItem(context, MdiIcons.viewSplitVertical, 'srt4', + SearchResultType.ultra, flip: true), ], ), @@ -52,8 +57,8 @@ class SearchType extends StatelessWidget { ); } - Widget _typeItem( - BuildContext context, IconData icon, String text, int selection, + Widget _typeItem(BuildContext context, IconData icon, String text, + SearchResultType selection, {bool flip = false}) { return ListTile( leading: Transform.scale( diff --git a/violet/lib/settings/settings.dart b/violet/lib/settings/settings.dart index bb1f26db5..a9abc94c0 100644 --- a/violet/lib/settings/settings.dart +++ b/violet/lib/settings/settings.dart @@ -32,8 +32,7 @@ class Settings { static late bool themeWhat; // default false == light static late Color majorColor; // default purple static late Color majorAccentColor; - static late int - searchResultType; // 0: 3 Grid, 1: 2 Grid, 2: Big Line, 3: Detail, 4: Ultra + static late SearchResultType searchResultType; static late int downloadResultType; static late int downloadAlignType; static late bool themeFlat; @@ -159,7 +158,8 @@ class Settings { } static Future init() async { - searchResultType = await _getInt('searchResultType', 4); + searchResultType = + SearchResultType.values[await _getInt('searchResultType', 4)]; downloadResultType = await _getInt('downloadResultType', 3); downloadAlignType = await _getInt('downloadAlignType', 0); @@ -524,10 +524,10 @@ class Settings { await prefs.setString('bookmarkHost', bookmarkHost); } - static Future setSearchResultType(int wh) async { + static Future setSearchResultType(SearchResultType wh) async { searchResultType = wh; - await prefs.setInt('searchResultType', searchResultType); + await prefs.setInt('searchResultType', searchResultType.index); } static Future setDownloadResultType(int wh) async { @@ -879,3 +879,28 @@ class Settings { await prefs.setBool('liteMode', nn); } } + +enum SearchResultType { + threeGrid, + twoGrid, + bigLine, + detail, + ultra, +} + +extension SearchResultTypeExtension on SearchResultType { + bool get isUltra { + return this == SearchResultType.ultra; + } + + bool get isDetailLike { + switch (this) { + case SearchResultType.detail: + case SearchResultType.ultra: + return true; + + default: + return false; + } + } +} From 66409000d9b47851c9ef5aea51be5fb9d6fe551f Mon Sep 17 00:00:00 2001 From: violet-dev Date: Sun, 8 Sep 2024 16:12:02 +0900 Subject: [PATCH 03/10] Introduce enum `ArtistType` --- violet/assets/locale/en.json | 4 +- violet/assets/locale/eo.json | 4 +- violet/assets/locale/it.json | 4 +- violet/assets/locale/ja.json | 4 +- violet/assets/locale/ko.json | 4 +- violet/assets/locale/pt.json | 4 +- violet/assets/locale/zh.json | 4 +- violet/assets/locale/zh_Hans.json | 4 +- violet/assets/locale/zh_Hant.json | 4 +- violet/lib/database/user/bookmark.dart | 70 +++-- .../pages/article_info/article_info_page.dart | 29 +- .../pages/artist_info/artist_info_page.dart | 258 +++++------------- .../pages/artist_info/series_list_page.dart | 2 - .../pages/artist_info/similar_list_page.dart | 37 +-- .../group/group_artist_article_list.dart | 9 +- .../bookmark/group/group_artist_list.dart | 73 ++--- violet/lib/pages/download/download_page.dart | 9 +- .../artist_collection/artist_list_page.dart | 13 +- .../info/lab/artist_search/artist_search.dart | 48 ++-- .../lab/bookmark/bookmarks_artist_list.dart | 43 +-- .../pages/main/info/lab/recent_comments.dart | 12 +- violet/lib/pages/settings/settings_page.dart | 8 +- violet/lib/util/strings.dart | 5 + 23 files changed, 237 insertions(+), 415 deletions(-) create mode 100644 violet/lib/util/strings.dart diff --git a/violet/assets/locale/en.json b/violet/assets/locale/en.json index 98058f24e..897e7ce66 100644 --- a/violet/assets/locale/en.json +++ b/violet/assets/locale/en.json @@ -66,8 +66,8 @@ "useinnerstorage": "Use Inner Storage", "default": "Default", "read": "Read", - "artists": "Artists", - "groups": "Groups", + "artist": "Artists", + "group": "Groups", "tags": "Tags", "series": "Series", "character": "Character", diff --git a/violet/assets/locale/eo.json b/violet/assets/locale/eo.json index 24a099fe7..27b8336f6 100644 --- a/violet/assets/locale/eo.json +++ b/violet/assets/locale/eo.json @@ -66,8 +66,8 @@ "useinnerstorage": "Use Inner Storage", "default": "Default", "read": "Leer", - "artists": "Artistas", - "groups": "Grupos", + "artist": "Artistas", + "group": "Grupos", "tags": "Etiquetas", "series": "Series", "character": "Personajes", diff --git a/violet/assets/locale/it.json b/violet/assets/locale/it.json index 9f73e184a..2cd9588b8 100644 --- a/violet/assets/locale/it.json +++ b/violet/assets/locale/it.json @@ -66,8 +66,8 @@ "useinnerstorage": "Use Inner Storage", "default": "Default", "read": "Leggi", - "artists": "Artisti", - "groups": "Gruppi", + "artist": "Artisti", + "group": "Gruppi", "tags": "Tags", "series": "Serie", "character": "Personaggi", diff --git a/violet/assets/locale/ja.json b/violet/assets/locale/ja.json index 78ec97fdd..d28790966 100644 --- a/violet/assets/locale/ja.json +++ b/violet/assets/locale/ja.json @@ -66,8 +66,8 @@ "useinnerstorage": "内部ストレージを使う", "default": "Default", "read": "読む", - "artists": "アーティスト", - "groups": "グループ", + "artist": "アーティスト", + "group": "グループ", "tags": "タグ", "series": "シリーズ", "character": "キャラクター", diff --git a/violet/assets/locale/ko.json b/violet/assets/locale/ko.json index 07e990cd1..d4f8ff58f 100644 --- a/violet/assets/locale/ko.json +++ b/violet/assets/locale/ko.json @@ -66,8 +66,8 @@ "useinnerstorage": "내부 저장소 사용", "default": "기본값", "read": "읽기", - "artists": "작가", - "groups": "그룹", + "artist": "작가", + "group": "그룹", "tags": "태그", "series": "시리즈", "character": "캐릭터", diff --git a/violet/assets/locale/pt.json b/violet/assets/locale/pt.json index 9228e0506..70fd3ba5a 100644 --- a/violet/assets/locale/pt.json +++ b/violet/assets/locale/pt.json @@ -66,8 +66,8 @@ "useinnerstorage": "Usar armazenamento interno", "default": "Padrão", "read": "Ler", - "artists": "Artistas", - "groups": "Grupos", + "artist": "Artistas", + "group": "Grupos", "tags": "Tags", "series": "Series", "character": "Personagem", diff --git a/violet/assets/locale/zh.json b/violet/assets/locale/zh.json index 2224d9d80..4c586b2d5 100644 --- a/violet/assets/locale/zh.json +++ b/violet/assets/locale/zh.json @@ -66,8 +66,8 @@ "useinnerstorage": "Use Inner Storage", "default": "Default", "read": "Read", - "artists": "Artists", - "groups": "Groups", + "artist": "Artists", + "group": "Groups", "tags": "Tags", "series": "Series", "character": "Character", diff --git a/violet/assets/locale/zh_Hans.json b/violet/assets/locale/zh_Hans.json index 24cca0f17..bd909793d 100644 --- a/violet/assets/locale/zh_Hans.json +++ b/violet/assets/locale/zh_Hans.json @@ -66,8 +66,8 @@ "useinnerstorage": "Use Inner Storage", "default": "Default", "read": "阅读", - "artists": "作者", - "groups": "团体", + "artist": "作者", + "group": "团体", "tags": "标签", "series": "系列", "character": "角色", diff --git a/violet/assets/locale/zh_Hant.json b/violet/assets/locale/zh_Hant.json index 53ff783a3..e9d06cae6 100644 --- a/violet/assets/locale/zh_Hant.json +++ b/violet/assets/locale/zh_Hant.json @@ -66,8 +66,8 @@ "useinnerstorage": "Use Inner Storage", "default": "Default", "read": "Read", - "artists": "Artists", - "groups": "Groups", + "artist": "Artists", + "group": "Groups", "tags": "Tags", "series": "Series", "character": "Character", diff --git a/violet/lib/database/user/bookmark.dart b/violet/lib/database/user/bookmark.dart index c82088508..a98f6eb44 100644 --- a/violet/lib/database/user/bookmark.dart +++ b/violet/lib/database/user/bookmark.dart @@ -61,6 +61,42 @@ class BookmarkArticle { } } +enum ArtistType { artist, group, uploader, series, character } + +extension ArtistTypeExtension on ArtistType { + bool get isGroup => this == ArtistType.group; + bool get isUploader => this == ArtistType.uploader; + bool get isCharacter => this == ArtistType.character; + bool get isSeries => this == ArtistType.series; +} + +class ArtistTypeHelper { + static ArtistType? fromString(String name) { + switch (name.toLowerCase()) { + case 'artist': + case 'artists': + return ArtistType.artist; + + case 'group': + case 'groups': + return ArtistType.group; + + case 'uploader': + case 'uploaders': + return ArtistType.uploader; + + case 'series': + return ArtistType.series; + + case 'character': + case 'characters': + return ArtistType.character; + } + + return null; + } +} + class BookmarkArtist { Map result; BookmarkArtist({required this.result}); @@ -72,7 +108,8 @@ class BookmarkArtist { // 2: uploader // 3: series // 4: character - int type() => result['IsGroup']; // backward compatibility + ArtistType type() => + ArtistType.values[result['IsGroup']]; // backward compatibility String datetime() => result['DateTime']; int group() => result['GroupId']; @@ -233,17 +270,17 @@ class Bookmark { bookmarkSet!.add(int.parse(article)); } - Future insertArtist(String artist, int isgroup, + Future insertArtist(String artist, ArtistType type, [DateTime? datetime, int group = 1]) async { datetime ??= DateTime.now(); var db = await CommonUserDatabase.getInstance(); await db.insert('BookmarkArtist', { 'Artist': artist, - 'IsGroup': isgroup, + 'IsGroup': type.index, 'DateTime': datetime.toString(), 'GroupId': group, }); - bookmarkArtistSet![isgroup]!.add(artist); + bookmarkArtistSet![type]!.add(artist); } Future insertUser(String user, @@ -454,17 +491,15 @@ class Bookmark { bookmarkSet!.remove(id); } - Map>? bookmarkArtistSet; - Future isBookmarkArtist(String name, int type) async { + Map>? bookmarkArtistSet; + Future isBookmarkArtist(String name, ArtistType type) async { if (bookmarkArtistSet == null) { - var artist = await getArtist(); - bookmarkArtistSet = >{}; - bookmarkArtistSet![0] = HashSet(); - bookmarkArtistSet![1] = HashSet(); - bookmarkArtistSet![2] = HashSet(); - bookmarkArtistSet![3] = HashSet(); - bookmarkArtistSet![4] = HashSet(); - for (var element in artist) { + final artist = await getArtist(); + bookmarkArtistSet = >{}; + for (final type in ArtistType.values) { + bookmarkArtistSet![type] = HashSet(); + } + for (final element in artist) { bookmarkArtistSet![element.type()]!.add(element.artist()); } } @@ -498,19 +533,18 @@ class Bookmark { return historyUserSet!.contains(user); } - Future bookmarkArtist(String name, int type, [int group = 1]) async { + Future bookmarkArtist(String name, ArtistType type, + [int group = 1]) async { if (await isBookmarkArtist(name, type)) return; bookmarkArtistSet![type]!.add(name); await insertArtist(name, type, null, group); } - Future unbookmarkArtist(String name, int type) async { + Future unbookmarkArtist(String name, ArtistType type) async { if (!await isBookmarkArtist(name, type)) return; var db = await CommonUserDatabase.getInstance(); await db.delete('BookmarkArtist', 'Artist=? AND IsGroup=?', [name, type]); bookmarkArtistSet![type]!.remove(name); - - print('delete $name, $type'); } Future bookmarkUser(String user, [int group = 1]) async { diff --git a/violet/lib/pages/article_info/article_info_page.dart b/violet/lib/pages/article_info/article_info_page.dart index c8ed8f4fc..afafd29dc 100644 --- a/violet/lib/pages/article_info/article_info_page.dart +++ b/violet/lib/pages/article_info/article_info_page.dart @@ -22,6 +22,7 @@ import 'package:violet/component/eh/eh_parser.dart'; import 'package:violet/component/hitomi/related.dart'; import 'package:violet/component/hitomi/tag_translate.dart'; import 'package:violet/database/query.dart'; +import 'package:violet/database/user/bookmark.dart'; import 'package:violet/database/user/download.dart'; import 'package:violet/database/user/record.dart'; import 'package:violet/locale/locale.dart'; @@ -372,22 +373,22 @@ class TagInfoAreaWidget extends StatelessWidget { 'language'), MultiChipWidget( queryResult.artists(), - Translations.of(context).trans('artists'), + Translations.of(context).trans('artist'), queryResult.artists() != null ? (queryResult.artists() as String) .split('|') .where((element) => element != '') - .map((e) => Tuple2('artists', e)) + .map((e) => Tuple2('artist', e)) .toList() : []), MultiChipWidget( queryResult.groups(), - Translations.of(context).trans('groups'), + Translations.of(context).trans('group'), queryResult.groups() != null ? (queryResult.groups() as String) .split('|') .where((element) => element != '') - .map((e) => Tuple2('groups', e)) + .map((e) => Tuple2('group', e)) .toList() : []), MultiChipWidget( @@ -924,14 +925,14 @@ class _Chip extends StatelessWidget { size: 18.0, color: Colors.white, ); - } else if (group == 'artists') { + } else if (group == 'artist') { mustHasMorePad = false; avatar = const Icon( MdiIcons.account, size: 18.0, color: Colors.white, ); - } else if (group == 'groups') { + } else if (group == 'group') { mustHasMorePad = false; avatar = const Icon( MdiIcons.accountGroup, @@ -989,21 +990,11 @@ class _Chip extends StatelessWidget { } }, onTap: () async { - if ((group == 'groups' || - group == 'artists' || - group == 'uploader' || - group == 'series' || - group == 'character') && - name.toLowerCase() != 'n/a') { + final type = ArtistTypeHelper.fromString(group); + if (type != null && name.toLowerCase() != 'n/a') { PlatformNavigator.navigateSlide( context, - ArtistInfoPage( - isGroup: group == 'groups', - isUploader: group == 'uploader', - isCharacter: group == 'character', - isSeries: group == 'series', - artist: name, - ), + ArtistInfoPage(name: name, type: type), ); } else if (group == 'id') { Clipboard.setData(ClipboardData(text: name)); diff --git a/violet/lib/pages/artist_info/artist_info_page.dart b/violet/lib/pages/artist_info/artist_info_page.dart index 0674784ce..ce87727a4 100644 --- a/violet/lib/pages/artist_info/artist_info_page.dart +++ b/violet/lib/pages/artist_info/artist_info_page.dart @@ -33,22 +33,17 @@ import 'package:violet/pages/segment/three_article_panel.dart'; import 'package:violet/server/community/anon.dart'; import 'package:violet/settings/settings.dart'; import 'package:violet/style/palette.dart'; +import 'package:violet/util/strings.dart'; import 'package:violet/widgets/article_item/article_list_item_widget.dart'; class ArtistInfoPage extends StatefulWidget { - final String artist; - final bool isGroup; - final bool isUploader; - final bool isSeries; - final bool isCharacter; + final String name; + final ArtistType type; const ArtistInfoPage({ super.key, - required this.artist, - this.isGroup = false, - this.isUploader = false, - this.isSeries = false, - this.isCharacter = false, + required this.name, + required this.type, }); @override @@ -61,8 +56,6 @@ class _ArtistInfoPageState extends State { int femaleTags = 0; int maleTags = 0; int tags = 0; - // Artist? Group? Uploader? - late String prefix; // Artist Articles late List cc; // Chart component lists @@ -95,28 +88,13 @@ class _ArtistInfoPageState extends State { // // Check bookmark // - var type = widget.isGroup - ? 1 - : widget.isUploader - ? 2 - : widget.isSeries - ? 3 - : widget.isCharacter - ? 4 - : 0; isBookmarked = await (await Bookmark.getInstance()) - .isBookmarkArtist(widget.artist, type); + .isBookmarkArtist(widget.name, widget.type); // // Get query // - cc = await query([ - widget.artist, - widget.isGroup, - widget.isUploader, - widget.isSeries, - widget.isCharacter - ]); + cc = await query(); // // Title based article clustering @@ -162,58 +140,51 @@ class _ArtistInfoPageState extends State { // // Similar Artists (or group, uploader) // - - if (widget.isGroup) { - similars = HitomiIndexs.calculateSimilarGroups(widget.artist); - } else if (widget.isUploader) { - similars = HitomiIndexs.calculateSimilarUploaders(widget.artist); - } else if (widget.isSeries) { - similars = HitomiIndexs.calculateSimilarSeries(widget.artist); - } else if (widget.isCharacter) { - similars = HitomiIndexs.calculateSimilarCharacter(widget.artist); - } else { - similars = HitomiIndexs.calculateSimilarArtists(widget.artist); + switch (widget.type) { + case ArtistType.artist: + similars = HitomiIndexs.calculateSimilarArtists(widget.name); + break; + case ArtistType.group: + similars = HitomiIndexs.calculateSimilarGroups(widget.name); + break; + case ArtistType.uploader: + similars = HitomiIndexs.calculateSimilarUploaders(widget.name); + break; + case ArtistType.series: + similars = HitomiIndexs.calculateSimilarSeries(widget.name); + break; + case ArtistType.character: + similars = HitomiIndexs.calculateSimilarCharacter(widget.name); + break; } similarsAll = similars; similars = similars.take(6).toList(); - prefix = 'artist:'; - if (widget.isGroup) { - prefix = 'group:'; - } else if (widget.isUploader) { - prefix = 'uploader:'; - } else if (widget.isSeries) { - prefix = 'series:'; - } else if (widget.isCharacter) { - prefix = 'character:'; - } - - await querySimilars(similars, prefix, qrs); + await querySimilars(similars, widget.type.name, qrs); - if (widget.isCharacter || widget.isSeries) { - if (widget.isCharacter) { + if (widget.type.isCharacter || widget.type.isSeries) { + if (widget.type.isCharacter) { relatedCharacterOrSeriesAll = - HitomiIndexs.calculateRelatedSeriesCharacter(widget.artist); - relatedCOSSingleAll = HitomiIndexs.getRelatedSeries(widget.artist); + HitomiIndexs.calculateRelatedSeriesCharacter(widget.name); + relatedCOSSingleAll = HitomiIndexs.getRelatedSeries(widget.name); } else { relatedCharacterOrSeriesAll = - HitomiIndexs.calculateRelatedCharacterSeries(widget.artist); - relatedCOSSingleAll = - HitomiIndexs.getRelatedCharacters(widget.artist); + HitomiIndexs.calculateRelatedCharacterSeries(widget.name); + relatedCOSSingleAll = HitomiIndexs.getRelatedCharacters(widget.name); } relatedCharacterOrSeries = relatedCharacterOrSeriesAll.take(6).toList(); relatedCOSSingle = relatedCOSSingleAll.take(6).toList(); await querySimilars( relatedCharacterOrSeries, - widget.isCharacter ? 'character:' : 'series:', + widget.type.name, qrsCharacterOrSeries, ); await querySimilars( relatedCOSSingle, - widget.isCharacter ? 'series:' : 'character:', + widget.type.name, qrsCOSSingle, ); } @@ -233,17 +204,8 @@ class _ArtistInfoPageState extends State { } Future readComments() async { - var tcomments = - (await VioletCommunityAnonymous.getArtistComments((widget.isGroup - ? 'group:' - : widget.isUploader - ? 'uploader:' - : widget.isSeries - ? 'series:' - : widget.isCharacter - ? 'character:' - : 'artist:') + - widget.artist))['result'] as List; + final tcomments = (await VioletCommunityAnonymous.getArtistComments( + '${widget.type.name}:${widget.name}'))['result'] as List; comments = tcomments .map((e) => Tuple3( @@ -261,7 +223,7 @@ class _ArtistInfoPageState extends State { for (int i = 0; i < similars.length; i++) { var postfix = similars[i].item1.toLowerCase().replaceAll(' ', '_'); var queryString = HitomiManager.translate2query( - '$prefix$postfix ${Settings.includeTags} ${Settings.excludeTags.where((e) => e.trim() != '').map((e) => '-$e').join(' ')}'); + '$prefix:$postfix ${Settings.includeTags} ${Settings.excludeTags.where((e) => e.trim() != '').map((e) => '-$e').join(' ')}'); final qm = QueryManager.queryPagination(queryString); qm.itemsPerPage = 10; @@ -306,20 +268,15 @@ class _ArtistInfoPageState extends State { } } - Future> query(dynamic obj) async { - var artist = obj[0] as String; - var isGroup = obj[1] as bool; - var isUploader = obj[2] as bool; - var isSeries = obj[3] as bool; - var isCharacter = obj[4] as bool; - - var query = HitomiManager.translate2query( - '${isGroup ? 'group:' : isUploader ? 'uploader:' : isSeries ? 'series:' : isCharacter ? 'character:' : 'artist:'}${artist.replaceAll(' ', '_')} ${Settings.includeTags} ${Settings.excludeTags.where((e) => e.trim() != '').map((e) => '-$e').join(' ')}'); - - // DateTime dt = DateTime.now(); - QueryManager qm = await QueryManager.query('$query ORDER BY Id DESC'); - // print((DateTime.now().difference(dt)).inSeconds); - + Future> query() async { + final token = '${widget.type.name}:${widget.name.replaceAll(' ', '_')}'; + final excludes = Settings.excludeTags + .where((e) => e.trim() != '') + .map((e) => '-$e') + .join(' '); + final query = HitomiManager.translate2query( + '$token ${Settings.includeTags} $excludes'); + final qm = await QueryManager.query('$query ORDER BY Id DESC'); return qm.results!; } @@ -402,17 +359,7 @@ class _ArtistInfoPageState extends State { controller: flareController, ), ), - Text( - (widget.isGroup - ? 'Groups: ' - : widget.isUploader - ? 'Uploader: ' - : widget.isSeries - ? 'Series: ' - : widget.isCharacter - ? 'Character: ' - : 'Artist: ') + - widget.artist, + Text('${widget.type.name.titlecase()}: ${widget.name}', style: const TextStyle(fontSize: 20, fontWeight: FontWeight.bold)), ], @@ -420,28 +367,19 @@ class _ArtistInfoPageState extends State { onTap: () async { isBookmarked = !isBookmarked; - var type = widget.isGroup - ? 1 - : widget.isUploader - ? 2 - : widget.isSeries - ? 3 - : widget.isCharacter - ? 4 - : 0; showToast( level: ToastLevel.check, message: - '${widget.artist}${Translations.of(context).trans(isBookmarked ? 'addtobookmark' : 'removetobookmark')}', + '${widget.name}${Translations.of(context).trans(isBookmarked ? 'addtobookmark' : 'removetobookmark')}', ); if (!isBookmarked) { await (await Bookmark.getInstance()) - .unbookmarkArtist(widget.artist, type); + .unbookmarkArtist(widget.name, widget.type); flareController.play('Unlike'); } else { await (await Bookmark.getInstance()) - .bookmarkArtist(widget.artist, type); + .bookmarkArtist(widget.name, widget.type); flareController.play('Like'); } }, @@ -560,16 +498,8 @@ class _ArtistInfoPageState extends State { visible: cc.length > maxItemCount, child: more(() => ArticleListPage( cc: cc, - name: (widget.isGroup - ? 'Groups: ' - : widget.isUploader - ? 'Uploader: ' - : widget.isSeries - ? 'Series: ' - : widget.isCharacter - ? 'Character: ' - : 'Artist: ') + - widget.artist))) + name: + '${widget.type.name.titlecase()}: ${widget.name}'))) ]), collapsed: Container(), ), @@ -595,7 +525,7 @@ class _ArtistInfoPageState extends State { ), ), ), - widget.isCharacter || widget.isSeries + widget.type.isCharacter || widget.type.isSeries ? ExpandableNotifier( child: Padding( padding: const EdgeInsets.symmetric(vertical: 4.0), @@ -608,7 +538,7 @@ class _ArtistInfoPageState extends State { header: Padding( padding: const EdgeInsets.fromLTRB(12, 12, 0, 0), child: Text( - '${Translations.of(context).trans('related')} ${widget.isSeries ? Translations.of(context).trans('iseries') : Translations.of(context).trans('icharacter')}'), + '${Translations.of(context).trans('related')} ${widget.type.isSeries ? Translations.of(context).trans('iseries') : Translations.of(context).trans('icharacter')}'), ), expanded: relatedArea(), collapsed: Container(), @@ -617,7 +547,7 @@ class _ArtistInfoPageState extends State { ), ) : Container(), - widget.isCharacter || widget.isSeries + widget.type.isCharacter || widget.type.isSeries ? ExpandableNotifier( child: Padding( padding: const EdgeInsets.symmetric(vertical: 4.0), @@ -630,7 +560,7 @@ class _ArtistInfoPageState extends State { header: Padding( padding: const EdgeInsets.fromLTRB(12, 12, 0, 0), child: Text( - '${Translations.of(context).trans('related')} ${widget.isCharacter ? Translations.of(context).trans('iseries') : Translations.of(context).trans('icharacter')}'), + '${Translations.of(context).trans('related')} ${widget.type.isCharacter ? Translations.of(context).trans('iseries') : Translations.of(context).trans('icharacter')}'), ), expanded: relatedSingleArea(), collapsed: Container(), @@ -650,7 +580,7 @@ class _ArtistInfoPageState extends State { header: Padding( padding: const EdgeInsets.fromLTRB(12, 12, 0, 0), child: Text( - '${Translations.of(context).trans('similar')} ${widget.isGroup ? Translations.of(context).trans('igroups') : widget.isUploader ? Translations.of(context).trans('iuploader') : widget.isSeries ? Translations.of(context).trans('iseries') : widget.isCharacter ? Translations.of(context).trans('icharacter') : Translations.of(context).trans('iartists')}'), + '${Translations.of(context).trans('similar')} ${widget.type.isGroup ? Translations.of(context).trans('igroups') : widget.type.isUploader ? Translations.of(context).trans('iuploader') : widget.type.isSeries ? Translations.of(context).trans('iseries') : widget.type.isCharacter ? Translations.of(context).trans('icharacter') : Translations.of(context).trans('iartists')}'), ), expanded: similarArea(), collapsed: Container(), @@ -765,38 +695,20 @@ class _ArtistInfoPageState extends State { itemBuilder: (BuildContext ctxt, int index) { if (index == similars.length) { return more(() => SimilarListPage( - prefix: prefix, similarsAll: similarsAll, - isGroup: widget.isGroup, - isUploader: widget.isUploader, - isCharacter: widget.isCharacter, - isSeries: widget.isSeries, + type: widget.type, )); } var e = similars[index]; var qq = qrs[index]; - var type = 'artist'; - if (widget.isGroup) { - type = 'group'; - } else if (widget.isUploader) { - type = 'uploader'; - } else if (widget.isSeries) { - type = 'series'; - } else if (widget.isCharacter) { - type = 'character'; - } - return ThreeArticlePanel( tappedRoute: () => ArtistInfoPage( - isGroup: widget.isGroup, - isUploader: widget.isUploader, - isCharacter: widget.isCharacter, - isSeries: widget.isSeries, - artist: e.item1, + type: widget.type, + name: e.item1, ), title: - ' ${e.item1} (${HitomiManager.getArticleCount(type, e.item1).toString()})', + ' ${e.item1} (${HitomiManager.getArticleCount(widget.type.name, e.item1).toString()})', count: '${Translations.of(context).trans('score')}: ${e.item2.toStringAsFixed(1)} ', articles: qq, @@ -816,7 +728,6 @@ class _ArtistInfoPageState extends State { if (index == 6) { return more(() => SeriesListPage( cc: cc, - prefix: prefix, series: series, )); } @@ -916,18 +827,7 @@ class _ArtistInfoPageState extends State { return; } await VioletCommunityAnonymous.postArtistComment( - null, - (widget.isGroup - ? 'group:' - : widget.isUploader - ? 'uploader:' - : widget.isSeries - ? 'series:' - : widget.isCharacter - ? 'character:' - : 'artist:') + - widget.artist, - text.text); + null, '${widget.type.name}:${widget.name}', text.text); await readComments(); Navigator.pop(context, true); }, @@ -973,30 +873,21 @@ class _ArtistInfoPageState extends State { itemBuilder: (BuildContext ctxt, int index) { if (index == relatedCharacterOrSeries.length) { return more(() => SimilarListPage( - prefix: prefix, similarsAll: relatedCharacterOrSeriesAll, - isGroup: widget.isGroup, - isUploader: widget.isUploader, - isCharacter: widget.isCharacter, - isSeries: widget.isSeries, + type: widget.type, )); } var e = relatedCharacterOrSeries[index]; var qq = qrsCharacterOrSeries[index]; - var cls = 'character'; - if (widget.isSeries) cls = 'series'; - return ThreeArticlePanel( tappedRoute: () => ArtistInfoPage( - isGroup: widget.isGroup, - isUploader: widget.isUploader, - isCharacter: widget.isCharacter, - isSeries: widget.isSeries, - artist: e.item1, + type: widget.type, + name: e.item1, ), - title: ' ${e.item1} (${HitomiManager.getArticleCount(cls, e.item1)})', + title: + ' ${e.item1} (${HitomiManager.getArticleCount(widget.type.name, e.item1)})', count: '${Translations.of(context).trans('score')}: ${e.item2.toStringAsFixed(1)} ', articles: qq, @@ -1014,29 +905,20 @@ class _ArtistInfoPageState extends State { itemBuilder: (BuildContext ctxt, int index) { if (index == relatedCOSSingle.length) { return more(() => SimilarListPage( - prefix: widget.isCharacter ? 'series:' : 'character:', similarsAll: relatedCOSSingleAll, - isGroup: widget.isGroup, - isUploader: widget.isUploader, - isSeries: widget.isCharacter, - isCharacter: widget.isSeries, + type: widget.type, )); } var e = relatedCOSSingle[index]; var qq = qrsCOSSingle[index]; - var cls = 'character'; - if (widget.isCharacter) cls = 'series'; - return ThreeArticlePanel( tappedRoute: () => ArtistInfoPage( - isGroup: widget.isGroup, - isUploader: widget.isUploader, - isSeries: widget.isCharacter, - isCharacter: widget.isSeries, - artist: e.item1, + type: widget.type, + name: e.item1, ), - title: ' ${e.item1} (${HitomiManager.getArticleCount(cls, e.item1)})', + title: + ' ${e.item1} (${HitomiManager.getArticleCount(widget.type.name, e.item1)})', count: '${Translations.of(context).trans('score')}: ${e.item2.toStringAsFixed(1)} ', articles: qq, diff --git a/violet/lib/pages/artist_info/series_list_page.dart b/violet/lib/pages/artist_info/series_list_page.dart index d76a6e3a6..d11368c4c 100644 --- a/violet/lib/pages/artist_info/series_list_page.dart +++ b/violet/lib/pages/artist_info/series_list_page.dart @@ -11,13 +11,11 @@ import 'package:violet/pages/segment/three_article_panel.dart'; import 'package:violet/settings/settings.dart'; class SeriesListPage extends StatelessWidget { - final String prefix; final List> series; final List cc; const SeriesListPage({ super.key, - required this.prefix, required this.series, required this.cc, }); diff --git a/violet/lib/pages/artist_info/similar_list_page.dart b/violet/lib/pages/artist_info/similar_list_page.dart index f848ce244..284b89e39 100644 --- a/violet/lib/pages/artist_info/similar_list_page.dart +++ b/violet/lib/pages/artist_info/similar_list_page.dart @@ -8,6 +8,7 @@ import 'package:tuple/tuple.dart'; import 'package:violet/algorithm/distance.dart'; import 'package:violet/component/hitomi/hitomi.dart'; import 'package:violet/database/query.dart'; +import 'package:violet/database/user/bookmark.dart'; import 'package:violet/locale/locale.dart'; import 'package:violet/pages/artist_info/artist_info_page.dart'; import 'package:violet/pages/segment/card_panel.dart'; @@ -15,29 +16,21 @@ import 'package:violet/pages/segment/three_article_panel.dart'; import 'package:violet/settings/settings.dart'; class SimilarListPage extends StatelessWidget { - final String prefix; - final bool isGroup; - final bool isUploader; - final bool isSeries; - final bool isCharacter; + final ArtistType type; final List> similarsAll; const SimilarListPage({ super.key, - required this.prefix, required this.similarsAll, - required this.isGroup, - required this.isUploader, - required this.isSeries, - required this.isCharacter, + required this.type, }); Future> _future(String e) async { var unescape = HtmlUnescape(); var postfix = e.toLowerCase().replaceAll(' ', '_'); - if (isUploader) postfix = e; + if (type.isUploader) postfix = e; var queryString = HitomiManager.translate2query( - '$prefix$postfix ${Settings.includeTags} ${Settings.excludeTags.where((e) => e.trim() != '').map((e) => '-$e').join(' ')}'); + '${type.name}:$postfix ${Settings.includeTags} ${Settings.excludeTags.where((e) => e.trim() != '').map((e) => '-$e').join(' ')}'); final qm = QueryManager.queryPagination(queryString); qm.itemsPerPage = 10; @@ -98,27 +91,13 @@ class SimilarListPage extends StatelessWidget { ); } - var type = 'artist'; - if (isGroup) { - type = 'group'; - } else if (isUploader) { - type = 'uploader'; - } else if (isSeries) { - type = 'series'; - } else if (isCharacter) { - type = 'character'; - } - return ThreeArticlePanel( tappedRoute: () => ArtistInfoPage( - isGroup: isGroup, - isUploader: isUploader, - isCharacter: isCharacter, - isSeries: isSeries, - artist: e.item1, + type: type, + name: e.item1, ), title: - ' ${e.item1} (${HitomiManager.getArticleCount(type, e.item1)})', + ' ${e.item1} (${HitomiManager.getArticleCount(type.name, e.item1)})', count: '${Translations.of(context).trans('score')}: ${e.item2.toStringAsFixed(1)} ', articles: snapshot.data!, diff --git a/violet/lib/pages/bookmark/group/group_artist_article_list.dart b/violet/lib/pages/bookmark/group/group_artist_article_list.dart index 35437572b..f17a46127 100644 --- a/violet/lib/pages/bookmark/group/group_artist_article_list.dart +++ b/violet/lib/pages/bookmark/group/group_artist_article_list.dart @@ -51,13 +51,8 @@ class _GroupArtistArticleListState extends State if (artists.isEmpty) return []; final queryString = HitomiManager.translate2query(artists - .map((e) => '${[ - 'artist', - 'group', - 'uploader', - 'series', - 'character' - ][e.type()]}:${e.artist().toLowerCase().replaceAll(' ', '_')} ${Settings.includeTags}') + .map((e) => + '${e.type().name}:${e.artist().toLowerCase().replaceAll(' ', '_')} ${Settings.includeTags}') .join(' or ')); final qm = QueryManager.queryPagination(queryString); diff --git a/violet/lib/pages/bookmark/group/group_artist_list.dart b/violet/lib/pages/bookmark/group/group_artist_list.dart index 60d72cec3..49649ce01 100644 --- a/violet/lib/pages/bookmark/group/group_artist_list.dart +++ b/violet/lib/pages/bookmark/group/group_artist_list.dart @@ -48,13 +48,8 @@ class _GroupArtistListState extends State var ids = >[]; for (int i = 0; i < artists.length; i++) { var postfix = artists[i].artist().toLowerCase().replaceAll(' ', '_'); - var queryString = HitomiManager.translate2query('${[ - 'artist', - 'group', - 'uploader', - 'series', - 'character' - ][artists[i].type()]}:$postfix ${Settings.includeTags}'); + var queryString = HitomiManager.translate2query( + '${artists[i].type().name}:$postfix ${Settings.includeTags}'); final qm = QueryManager.queryPagination(queryString); qm.itemsPerPage = 1; var query = (await qm.next())[0].id(); @@ -70,15 +65,10 @@ class _GroupArtistListState extends State artists = newedList; } - Future> _future(String e, int type) async { + Future> _future(String e, ArtistType type) async { var postfix = e.toLowerCase().replaceAll(' ', '_'); - var queryString = HitomiManager.translate2query('${[ - 'artist', - 'group', - 'uploader', - 'series', - 'character' - ][type]}:$postfix ${Settings.includeTags}'); + var queryString = HitomiManager.translate2query( + '${type.name}:$postfix ${Settings.includeTags}'); final qm = QueryManager.queryPagination(queryString); qm.itemsPerPage = 4; return await qm.next(); @@ -244,7 +234,7 @@ class _GroupArtistListState extends State color: checkMode && checked .where((element) => - element.item1 == e.type() && element.item2 == e.artist()) + element.$1 == e.type() && element.$2 == e.artist()) .isNotEmpty ? Colors.amber : Colors.transparent, @@ -256,8 +246,7 @@ class _GroupArtistListState extends State e.artist(), checked .where((element) => - element.item1 == e.type() && - element.item2 == e.artist()) + element.$1 == e.type() && element.$2 == e.artist()) .isEmpty); setState(() {}); return; @@ -266,11 +255,8 @@ class _GroupArtistListState extends State PlatformNavigator.navigateSlide( context, ArtistInfoPage( - isGroup: e.type() == 1, - isUploader: e.type() == 2, - isSeries: e.type() == 3, - isCharacter: e.type() == 4, - artist: e.artist(), + name: e.artist(), + type: e.type(), ), ); }, @@ -290,19 +276,7 @@ class _GroupArtistListState extends State mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Text( - ' ${[ - 'artist', - 'group', - 'uploader', - 'series', - 'character' - ][e.type()]}:${e.artist()} (${HitomiManager.getArticleCount([ - 'artist', - 'group', - 'uploader', - 'series', - 'character' - ][e.type()], e.artist())})', + ' ${e.type().name}:${e.artist()} (${HitomiManager.getArticleCount(e.type().name, e.artist())})', style: const TextStyle(fontSize: 17)), ], ), @@ -357,8 +331,7 @@ class _GroupArtistListState extends State FloatingActionButton( onPressed: () { for (var element in artists) { - checked - .add(Tuple2(element.type(), element.artist())); + checked.add((element.type(), element.artist())); } setState(() {}); }, @@ -376,7 +349,7 @@ class _GroupArtistListState extends State Translations.of(context).trans('bookmark'))) { var bookmark = await Bookmark.getInstance(); for (var element in checked) { - await bookmark.unbookmarkArtist(element.item2, element.item1); + await bookmark.unbookmarkArtist(element.$2, element.$1); } checked.clear(); refresh(); @@ -419,23 +392,23 @@ class _GroupArtistListState extends State bool checkMode = false; bool checkModePre = false; - List> checked = []; + List<(ArtistType, String)> checked = []; - void longpress(int type, String artist) { + void longpress(ArtistType type, String artist) { if (!checkMode) { checkMode = true; checkModePre = true; - checked.add(Tuple2(type, artist)); + checked.add((type, artist)); setState(() {}); } } - void check(int type, String artist, bool check) { + void check(ArtistType type, String artist, bool check) { if (check) { - checked.add(Tuple2(type, artist)); + checked.add((type, artist)); } else { - checked.removeWhere( - (element) => element.item1 == type && element.item2 == artist); + checked + .removeWhere((element) => element.$1 == type && element.$2 == artist); if (checked.isEmpty) { setState(() { checkModePre = false; @@ -506,8 +479,8 @@ class _GroupArtistListState extends State for (int i = 0; i < artists.length; i++) { invIdIndex['${artists[i].artist()}|${artists[i].type()}'] = i; } - checked.sort((x, y) => invIdIndex['${x.item2}|${x.item1}']! - .compareTo(invIdIndex['${y.item2}|${y.item1}']!)); + checked.sort((x, y) => invIdIndex['${x.$2}|${x.$1}']! + .compareTo(invIdIndex['${y.$2}|${y.$1}']!)); // 1. Get bookmark articles on source groupid var bm = await Bookmark.getInstance(); @@ -523,10 +496,10 @@ class _GroupArtistListState extends State for (var e in checked.reversed) { // 3. Delete source bookmarks - await bm.unbookmarkArtist(e.item2, e.item1); + await bm.unbookmarkArtist(e.$2, e.$1); // 4. Add src bookmarks with new groupid await bm.insertArtist( - e.item2, e.item1, DateTime.now(), groups[choose].id()); + e.$2, e.$1, DateTime.now(), groups[choose].id()); } // 5. Update UI diff --git a/violet/lib/pages/download/download_page.dart b/violet/lib/pages/download/download_page.dart index 386947938..c995b36bd 100644 --- a/violet/lib/pages/download/download_page.dart +++ b/violet/lib/pages/download/download_page.dart @@ -41,6 +41,7 @@ import 'package:violet/script/script_manager.dart'; import 'package:violet/settings/settings.dart'; import 'package:violet/style/palette.dart'; import 'package:violet/util/helper.dart'; +import 'package:violet/util/strings.dart'; import 'package:violet/widgets/debounce_widget.dart'; import 'package:violet/widgets/search_bar.dart'; import 'package:violet/widgets/theme_switchable_state.dart'; @@ -632,7 +633,7 @@ class _DownloadPageState extends ThemeSwitchableState child: Container( padding: const EdgeInsets.fromLTRB(8, 8, 8, 8), child: Text( - e.$1.split(' ').map((e) => e.capitalize()).join(' '), + e.$1.split(' ').map((e) => e.titlecase()).join(' '), style: const TextStyle( fontWeight: FontWeight.bold, fontSize: 20.0), ), @@ -1239,9 +1240,3 @@ class _DownloadPageState extends ThemeSwitchableState queryResults[int.parse(url)] = qm.results!.first; } } - -extension StringExtension on String { - String capitalize() { - return '${this[0].toUpperCase()}${substring(1).toLowerCase()}'; - } -} diff --git a/violet/lib/pages/main/artist_collection/artist_list_page.dart b/violet/lib/pages/main/artist_collection/artist_list_page.dart index 3fa442b28..e9283ad35 100644 --- a/violet/lib/pages/main/artist_collection/artist_list_page.dart +++ b/violet/lib/pages/main/artist_collection/artist_list_page.dart @@ -8,6 +8,7 @@ import 'package:uuid/uuid.dart'; import 'package:violet/algorithm/distance.dart'; import 'package:violet/component/hitomi/hitomi.dart'; import 'package:violet/database/query.dart'; +import 'package:violet/database/user/bookmark.dart'; import 'package:violet/model/article_list_item.dart'; import 'package:violet/pages/artist_info/artist_info_page.dart'; import 'package:violet/pages/segment/platform_navigator.dart'; @@ -134,14 +135,20 @@ class ArtistListPage extends StatelessWidget { final articleCount = HitomiManager.getArticleCount(classification, name); + late final ArtistType type; + if (isLast && classification == 'group') { + type = ArtistType.group; + } else { + type = ArtistType.artist; + } + return InkWell( onTap: () async { PlatformNavigator.navigateSlide( context, ArtistInfoPage( - isGroup: isLast && classification == 'group', - isUploader: false, - artist: name, + type: type, + name: name, ), ); }, diff --git a/violet/lib/pages/main/info/lab/artist_search/artist_search.dart b/violet/lib/pages/main/info/lab/artist_search/artist_search.dart index c9dadd91e..4cb1fa62a 100644 --- a/violet/lib/pages/main/info/lab/artist_search/artist_search.dart +++ b/violet/lib/pages/main/info/lab/artist_search/artist_search.dart @@ -11,6 +11,7 @@ import 'package:violet/algorithm/distance.dart'; import 'package:violet/component/hitomi/hitomi.dart'; import 'package:violet/component/hitomi/indexs.dart'; import 'package:violet/database/query.dart'; +import 'package:violet/database/user/bookmark.dart'; import 'package:violet/locale/locale.dart'; import 'package:violet/pages/artist_info/artist_info_page.dart'; import 'package:violet/pages/main/info/lab/artist_search/tag_group_modify.dart'; @@ -29,7 +30,7 @@ class ArtistSearch extends StatefulWidget { } class _ArtistSearchState extends State { - String selectedType = 'artists'; + ArtistType selectedType = ArtistType.artist; Map tagGroup = { 'female:sole_female': 10, @@ -47,11 +48,11 @@ class _ArtistSearchState extends State { final tagGroup = {}; final tagSrcs = { - 'artists': HitomiIndexs.tagArtist, - 'groups': HitomiIndexs.tagGroup, - 'series': HitomiIndexs.tagSeries, - 'character': HitomiIndexs.tagCharacter, - 'uploader': HitomiIndexs.tagUploader, + ArtistType.artist: HitomiIndexs.tagArtist, + ArtistType.group: HitomiIndexs.tagGroup, + ArtistType.series: HitomiIndexs.tagSeries, + ArtistType.character: HitomiIndexs.tagCharacter, + ArtistType.uploader: HitomiIndexs.tagUploader, }; for (var element in this.tagGroup.entries) { @@ -217,19 +218,19 @@ class _ArtistSearchState extends State { } typeSelector() { - final dropDown = DropdownButton( + final dropDown = DropdownButton( value: selectedType, - items: ['artists', 'groups', 'series', 'character', 'uploader'] - .map>((String value) { - return DropdownMenuItem( + items: ArtistType.values + .map>((ArtistType value) { + return DropdownMenuItem( value: value, child: Text( - Translations.instance!.trans(value), + Translations.instance!.trans(value.name), style: const TextStyle(fontSize: 16), ), ); }).toList(), - onChanged: (String? newValue) { + onChanged: (ArtistType? newValue) { similarsAll = []; setState(() { @@ -245,15 +246,6 @@ class _ArtistSearchState extends State { return dropDown; } - String getNormalizedType() { - if (selectedType == 'artists') { - return 'artist'; - } else if (selectedType == 'groups') { - return 'group'; - } - return selectedType; - } - artistListArea() { return ListView.builder( key: listViewKey, @@ -272,18 +264,13 @@ class _ArtistSearchState extends State { ); } - final type = getNormalizedType(); - return ThreeArticlePanel( tappedRoute: () => ArtistInfoPage( - isGroup: type == 'group', - isUploader: type == 'uploader', - isCharacter: type == 'character', - isSeries: type == 'series', - artist: e.item1, + type: selectedType, + name: e.item1, ), title: - ' ${e.item1} (${HitomiManager.getArticleCount(type, e.item1)})', + ' ${e.item1} (${HitomiManager.getArticleCount(selectedType.name, e.item1)})', count: '${Translations.of(context).trans('score')}: ${e.item2.toStringAsFixed(1)} ', articles: snapshot.data!, @@ -297,11 +284,10 @@ class _ArtistSearchState extends State { Future> artistListfuture(String e) async { final unescape = HtmlUnescape(); - final prefix = getNormalizedType(); final postfix = e.toLowerCase().replaceAll(' ', '_'); final queryString = HitomiManager.translate2query( - '$prefix:$postfix ${Settings.includeTags} ${Settings.excludeTags.where((e) => e.trim() != '').map((e) => '-$e').join(' ')}'); + '${selectedType.name}:$postfix ${Settings.includeTags} ${Settings.excludeTags.where((e) => e.trim() != '').map((e) => '-$e').join(' ')}'); final qm = QueryManager.queryPagination(queryString); qm.itemsPerPage = 10; diff --git a/violet/lib/pages/main/info/lab/bookmark/bookmarks_artist_list.dart b/violet/lib/pages/main/info/lab/bookmark/bookmarks_artist_list.dart index 84ca53394..085ec0724 100644 --- a/violet/lib/pages/main/info/lab/bookmark/bookmarks_artist_list.dart +++ b/violet/lib/pages/main/info/lab/bookmark/bookmarks_artist_list.dart @@ -48,14 +48,9 @@ class _GroupArtistListState extends State Future _sortByLatest() async { var ids = >[]; for (int i = 0; i < artists.length; i++) { - var postfix = artists[i].artist().toLowerCase().replaceAll(' ', '_'); - var queryString = HitomiManager.translate2query('${[ - 'artist', - 'group', - 'uploader', - 'series', - 'character' - ][artists[i].type()]}:$postfix ${Settings.includeTags}'); + final postfix = artists[i].artist().toLowerCase().replaceAll(' ', '_'); + final queryString = HitomiManager.translate2query( + '${artists[i].type().name}:$postfix ${Settings.includeTags}'); final qm = QueryManager.queryPagination(queryString); qm.itemsPerPage = 1; var query = (await qm.next())[0].id(); @@ -71,15 +66,10 @@ class _GroupArtistListState extends State artists = newedList; } - Future> _future(String e, int type) async { + Future> _future(String e, ArtistType type) async { var postfix = e.toLowerCase().replaceAll(' ', '_'); - var queryString = HitomiManager.translate2query('${[ - 'artist', - 'group', - 'uploader', - 'series', - 'character' - ][type]}:$postfix ${Settings.includeTags}'); + var queryString = HitomiManager.translate2query( + '${type.name}:$postfix ${Settings.includeTags}'); final qm = QueryManager.queryPagination(queryString); qm.itemsPerPage = 3; return await qm.next(); @@ -222,11 +212,8 @@ class _GroupArtistListState extends State PlatformNavigator.navigateSlide( context, ArtistInfoPage( - isGroup: e.type() == 1, - isUploader: e.type() == 2, - isSeries: e.type() == 3, - isCharacter: e.type() == 4, - artist: e.artist(), + type: e.type(), + name: e.artist(), ), ); }, @@ -241,19 +228,7 @@ class _GroupArtistListState extends State mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Text( - ' ${[ - 'artist', - 'group', - 'uploader', - 'series', - 'character' - ][e.type()]}:${e.artist()} (${HitomiManager.getArticleCount([ - 'artist', - 'group', - 'uploader', - 'series', - 'character' - ][e.type()], e.artist())})', + ' ${e.type().name}:${e.artist()} (${HitomiManager.getArticleCount(e.type().name, e.artist())})', style: const TextStyle(fontSize: 17)), ], ), diff --git a/violet/lib/pages/main/info/lab/recent_comments.dart b/violet/lib/pages/main/info/lab/recent_comments.dart index 0213d1842..955f4e9e7 100644 --- a/violet/lib/pages/main/info/lab/recent_comments.dart +++ b/violet/lib/pages/main/info/lab/recent_comments.dart @@ -4,6 +4,7 @@ import 'package:flutter/material.dart'; import 'package:intl/intl.dart'; import 'package:tuple/tuple.dart'; +import 'package:violet/database/user/bookmark.dart'; import 'package:violet/pages/artist_info/artist_info_page.dart'; import 'package:violet/pages/segment/card_panel.dart'; import 'package:violet/pages/segment/platform_navigator.dart'; @@ -52,14 +53,11 @@ class _LabRecentCommentsState extends State { var e = comments[index]; return InkWell( onTap: () async { - var group = e.item4.split(':').first; - var name = e.item4.split(':').last; + final group = e.item4.split(':').first; + final name = e.item4.split(':').last; _navigate(ArtistInfoPage( - isGroup: group == 'groups' || group == 'group', - isUploader: group == 'uploader', - isCharacter: group == 'character', - isSeries: group == 'series', - artist: name, + type: ArtistTypeHelper.fromString(group)!, + name: name, )); }, splashColor: Colors.white, diff --git a/violet/lib/pages/settings/settings_page.dart b/violet/lib/pages/settings/settings_page.dart index 9f1289959..82cd61dd0 100644 --- a/violet/lib/pages/settings/settings_page.dart +++ b/violet/lib/pages/settings/settings_page.dart @@ -2153,8 +2153,12 @@ class _SettingsPageState extends State await bookmark.insertArticle(tar, DateTime.now(), group); } else if (tar.contains(':') && ['artist', 'group'].contains(tar.split(':')[0])) { - await bookmark.bookmarkArtist(tar.split(':')[1], - tar.split(':')[0] == 'artist' ? 0 : 1, group); + await bookmark.bookmarkArtist( + tar.split(':')[1], + tar.split(':')[0] == 'artist' + ? ArtistType.artist + : ArtistType.group, + group); } } diff --git a/violet/lib/util/strings.dart b/violet/lib/util/strings.dart new file mode 100644 index 000000000..68870c3ea --- /dev/null +++ b/violet/lib/util/strings.dart @@ -0,0 +1,5 @@ +extension StringExtension on String { + String titlecase() { + return '${this[0].toUpperCase()}${substring(1).toLowerCase()}'; + } +} From 44921560e51ec4d8a6879a0d35d7de9b4051ce07 Mon Sep 17 00:00:00 2001 From: violet-dev Date: Sun, 8 Sep 2024 16:33:28 +0900 Subject: [PATCH 04/10] Make enum `DownloadResultType` --- violet/lib/pages/download/download_page.dart | 40 +++++++++---------- .../pages/download/download_view_type.dart | 22 +++++----- violet/lib/settings/settings.dart | 32 +++++++++++++-- 3 files changed, 60 insertions(+), 34 deletions(-) diff --git a/violet/lib/pages/download/download_page.dart b/violet/lib/pages/download/download_page.dart index c995b36bd..26f8182b7 100644 --- a/violet/lib/pages/download/download_page.dart +++ b/violet/lib/pages/download/download_page.dart @@ -209,7 +209,8 @@ class _DownloadPageState extends ThemeSwitchableState queryResults[element.id()] = element; } - if (Settings.downloadAlignType != 0 && Settings.downloadResultType == 0) { + if (Settings.downloadAlignType != 0 && + Settings.downloadResultType.isThreeGrid) { setState(() {}); } }); @@ -249,7 +250,7 @@ class _DownloadPageState extends ThemeSwitchableState ], ), if (Settings.downloadAlignType != 0 && - Settings.downloadResultType == 0) + Settings.downloadResultType.isThreeGrid) indexBar(), ], ), @@ -265,16 +266,15 @@ class _DownloadPageState extends ThemeSwitchableState >{}; _getDownloadWidgetKey() { - if (Settings.downloadResultType == 0 || Settings.downloadResultType == 1) { + if (Settings.downloadResultType.isGridLike) { return downloadItemWidgetKeys1; } - if (Settings.downloadResultType == 2 || Settings.downloadResultType == 3) { - if (Settings.useTabletMode || - MediaQuery.of(context).orientation == Orientation.landscape) { - return downloadItemWidgetKeys2; - } else { - return downloadItemWidgetKeys3; - } + + if (Settings.useTabletMode || + MediaQuery.of(context).orientation == Orientation.landscape) { + return downloadItemWidgetKeys2; + } else { + return downloadItemWidgetKeys3; } } @@ -282,8 +282,9 @@ class _DownloadPageState extends ThemeSwitchableState Widget _panel() { var windowWidth = lastWindowWidth = MediaQuery.of(context).size.width; - if (Settings.downloadResultType == 0 || Settings.downloadResultType == 1) { - if (Settings.downloadAlignType != 0 && Settings.downloadResultType == 0) { + if (Settings.downloadResultType.isGridLike) { + if (Settings.downloadAlignType != 0 && + Settings.downloadResultType.isThreeGrid) { return FutureBuilder( future: getGroupBy(), builder: (context, snapshot) { @@ -296,7 +297,7 @@ class _DownloadPageState extends ThemeSwitchableState ); } - var mm = Settings.downloadResultType == 0 ? 3 : 2; + var mm = Settings.downloadResultType.isThreeGrid ? 3 : 2; return SliverPadding( padding: const EdgeInsets.fromLTRB(8, 0, 8, 16), sliver: SliverGrid( @@ -336,8 +337,7 @@ class _DownloadPageState extends ThemeSwitchableState childCount: filterResult.length, ), )); - } else if (Settings.downloadResultType == 2 || - Settings.downloadResultType == 3) { + } else { if (Settings.useTabletMode || MediaQuery.of(context).orientation == Orientation.landscape) { return SliverPadding( @@ -368,7 +368,7 @@ class _DownloadPageState extends ThemeSwitchableState child: DownloadItemWidget( key: downloadItemWidgetKeys2[filterResult[index].id()], initialStyle: DownloadListItem( - showDetail: Settings.downloadResultType == 3, + showDetail: Settings.downloadResultType.isDetail, addBottomPadding: true, width: windowWidth - 4.0, ), @@ -395,7 +395,7 @@ class _DownloadPageState extends ThemeSwitchableState child: DownloadItemWidget( key: downloadItemWidgetKeys3[e.id()], initialStyle: DownloadListItem( - showDetail: Settings.downloadResultType == 3, + showDetail: Settings.downloadResultType.isDetail, addBottomPadding: true, width: windowWidth - 4.0, ), @@ -409,8 +409,6 @@ class _DownloadPageState extends ThemeSwitchableState ); } } - - throw Exception('unreachable'); } Future)>> getGroupBy() async { @@ -506,7 +504,7 @@ class _DownloadPageState extends ThemeSwitchableState void _scrollChanged() { if (!(Settings.downloadAlignType != 0 && - Settings.downloadResultType == 0)) { + Settings.downloadResultType.isThreeGrid)) { return; } @@ -586,7 +584,7 @@ class _DownloadPageState extends ThemeSwitchableState Widget _panelGroupBy(List<(String, List)> groupBy) { final windowWidth = lastWindowWidth = MediaQuery.of(context).size.width; - final columnCount = Settings.downloadResultType == 0 ? 3 : 2; + final columnCount = Settings.downloadResultType.isThreeGrid ? 3 : 2; final effectiveColumnCount = Settings.useTabletMode ? columnCount * 2 : columnCount; diff --git a/violet/lib/pages/download/download_view_type.dart b/violet/lib/pages/download/download_view_type.dart index 359fed616..a0b5fc2eb 100644 --- a/violet/lib/pages/download/download_view_type.dart +++ b/violet/lib/pages/download/download_view_type.dart @@ -10,12 +10,12 @@ import 'package:violet/style/palette.dart'; class DownloadViewType extends StatelessWidget { const DownloadViewType({super.key}); - Color getColor(int i) { + Color getColor(DownloadResultType type) { return Settings.themeWhat - ? Settings.downloadResultType == i + ? Settings.downloadResultType == type ? Colors.grey.shade200 : Colors.grey.shade400 - : Settings.downloadResultType == i + : Settings.downloadResultType == type ? Colors.grey.shade900 : Colors.grey.shade400; } @@ -35,10 +35,14 @@ class DownloadViewType extends StatelessWidget { physics: const NeverScrollableScrollPhysics(), child: Column( children: [ - _typeItem(context, Icons.grid_on, 'srt0', 0), - _typeItem(context, MdiIcons.gridLarge, 'srt1', 1), - _typeItem(context, MdiIcons.viewAgendaOutline, 'srt2', 2), - _typeItem(context, MdiIcons.formatListText, 'srt3', 3), + _typeItem(context, Icons.grid_on, 'srt0', + DownloadResultType.threeGrid), + _typeItem(context, MdiIcons.gridLarge, 'srt1', + DownloadResultType.twoGrid), + _typeItem(context, MdiIcons.viewAgendaOutline, 'srt2', + DownloadResultType.bigLine), + _typeItem(context, MdiIcons.formatListText, 'srt3', + DownloadResultType.detail), ], ), ), @@ -49,8 +53,8 @@ class DownloadViewType extends StatelessWidget { ); } - Widget _typeItem( - BuildContext context, IconData icon, String text, int selection) { + Widget _typeItem(BuildContext context, IconData icon, String text, + DownloadResultType selection) { return ListTile( leading: Icon(icon, color: getColor(selection)), title: Text(Translations.of(context).trans(text), diff --git a/violet/lib/settings/settings.dart b/violet/lib/settings/settings.dart index a9abc94c0..2c40e8ead 100644 --- a/violet/lib/settings/settings.dart +++ b/violet/lib/settings/settings.dart @@ -33,7 +33,7 @@ class Settings { static late Color majorColor; // default purple static late Color majorAccentColor; static late SearchResultType searchResultType; - static late int downloadResultType; + static late DownloadResultType downloadResultType; static late int downloadAlignType; static late bool themeFlat; static late bool themeBlack; // default false @@ -160,7 +160,8 @@ class Settings { static Future init() async { searchResultType = SearchResultType.values[await _getInt('searchResultType', 4)]; - downloadResultType = await _getInt('downloadResultType', 3); + downloadResultType = + DownloadResultType.values[await _getInt('downloadResultType', 3)]; downloadAlignType = await _getInt('downloadAlignType', 0); var includetags = prefs.getString('includetags'); @@ -530,10 +531,10 @@ class Settings { await prefs.setInt('searchResultType', searchResultType.index); } - static Future setDownloadResultType(int wh) async { + static Future setDownloadResultType(DownloadResultType wh) async { downloadResultType = wh; - await prefs.setInt('downloadResultType', downloadResultType); + await prefs.setInt('downloadResultType', downloadResultType.index); } static Future setDownloadAlignType(int wh) async { @@ -904,3 +905,26 @@ extension SearchResultTypeExtension on SearchResultType { } } } + +enum DownloadResultType { + threeGrid, + twoGrid, + bigLine, + detail, +} + +extension DownloadResultTypeExtension on DownloadResultType { + bool get isThreeGrid => this == DownloadResultType.threeGrid; + bool get isDetail => this == DownloadResultType.detail; + + bool get isGridLike { + switch (this) { + case DownloadResultType.threeGrid: + case DownloadResultType.twoGrid: + return true; + + default: + return false; + } + } +} From 4c8003cea7cf2a1c7e71fe2d27d12536cceb47c7 Mon Sep 17 00:00:00 2001 From: violet-dev Date: Sun, 8 Sep 2024 16:34:32 +0900 Subject: [PATCH 05/10] Enable rule `unrelated_type_equality_checks` --- violet/analysis_options.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/violet/analysis_options.yaml b/violet/analysis_options.yaml index d5bf5d72e..2bc2f1d8b 100644 --- a/violet/analysis_options.yaml +++ b/violet/analysis_options.yaml @@ -28,10 +28,12 @@ linter: sized_box_shrink_expand: true prefer_single_quotes: true always_use_package_imports: true + unrelated_type_equality_checks: true analyzer: errors: always_use_package_imports: error + unrelated_type_equality_checks: error exclude: - "rust_builder/**" - "lib/src/rust/**" From a6d6fc8d54746ea72861939bd19f38a8a623c408 Mon Sep 17 00:00:00 2001 From: violet-dev Date: Sun, 8 Sep 2024 16:37:44 +0900 Subject: [PATCH 06/10] Suppress lint info for salt files --- violet/analysis_options.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/violet/analysis_options.yaml b/violet/analysis_options.yaml index 2bc2f1d8b..c80b4b51b 100644 --- a/violet/analysis_options.yaml +++ b/violet/analysis_options.yaml @@ -38,6 +38,8 @@ analyzer: - "rust_builder/**" - "lib/src/rust/**" - "lib/pages/viewer/others/**" + - "lib/server/salt.dart" + - "lib/server/wsalt.dart" # Additional information about this file can be found at # https://dart.dev/guides/language/analysis-options From 859986b481aa1e0c80db993e9dde64cc899ae559 Mon Sep 17 00:00:00 2001 From: violet-dev Date: Sun, 8 Sep 2024 16:58:11 +0900 Subject: [PATCH 07/10] Suppress lint `use_build_context_synchronously` --- violet/analysis_options.yaml | 2 +- violet/lib/pages/after_loading/afterloading_page.dart | 2 ++ violet/lib/pages/article_info/article_info_page.dart | 2 ++ violet/lib/pages/bookmark/bookmark_page.dart | 6 +++--- violet/lib/pages/bookmark/crop_bookmark.dart | 3 +++ .../pages/bookmark/group/group_article_list_page.dart | 6 ++++-- violet/lib/pages/bookmark/group/group_artist_list.dart | 6 ++++-- violet/lib/pages/bookmark/group_modify.dart | 1 + violet/lib/pages/common/utils.dart | 1 + violet/lib/pages/community/community_page.dart | 5 +++++ violet/lib/pages/community/signin_dialog.dart | 2 ++ violet/lib/pages/community/signup_dialog.dart | 3 +++ violet/lib/pages/community/user_status_card_dead.dart | 5 +++++ .../database_download/database_download_page.dart | 1 + violet/lib/pages/download/download_align_type.dart | 2 ++ violet/lib/pages/download/download_item_widget.dart | 3 ++- violet/lib/pages/download/download_page.dart | 2 ++ violet/lib/pages/download/download_view_type.dart | 2 ++ violet/lib/pages/lock/lock_screen.dart | 10 +++++++--- violet/lib/pages/main/info/lab/bookmark/bookmarks.dart | 1 + violet/lib/pages/main/info/lab/bookmark_spy.dart | 1 + violet/lib/pages/main/info/lab/global_comments.dart | 2 ++ violet/lib/pages/main/info/lab_page.dart | 4 ++++ violet/lib/pages/main/main_page.dart | 8 ++++++-- violet/lib/pages/search/search_page.dart | 3 +++ violet/lib/pages/search/search_type.dart | 1 + violet/lib/pages/settings/bookmark_version_select.dart | 2 ++ violet/lib/pages/settings/db_rebuild_page.dart | 1 + violet/lib/pages/settings/import_from_eh.dart | 1 + violet/lib/pages/settings/lock_setting_page.dart | 5 +++-- violet/lib/pages/settings/login/ehentai_login.dart | 1 + violet/lib/pages/settings/restore_bookmark.dart | 3 +++ violet/lib/pages/settings/settings_page.dart | 2 ++ violet/lib/pages/settings/tag_rebuild_page.dart | 1 + violet/lib/pages/splash/splash_page.dart | 10 +++++++--- violet/lib/pages/viewer/horizontal_viewer_page.dart | 1 + violet/lib/pages/viewer/image/file_image.dart | 2 ++ violet/lib/pages/viewer/image/provider_image.dart | 1 + violet/lib/pages/viewer/overlay/viewer_overlay.dart | 6 +++++- violet/lib/pages/viewer/overlay/viewer_tab_panel.dart | 2 ++ violet/lib/pages/viewer/overlay/viewer_thumbnails.dart | 2 ++ violet/lib/pages/viewer/viewer_controller.dart | 2 ++ violet/lib/pages/viewer/viewer_page.dart | 2 ++ violet/lib/update/update_manager.dart | 5 ++++- .../widgets/article_item/article_list_item_widget.dart | 7 +++++-- 45 files changed, 117 insertions(+), 23 deletions(-) diff --git a/violet/analysis_options.yaml b/violet/analysis_options.yaml index c80b4b51b..f5e2f88c5 100644 --- a/violet/analysis_options.yaml +++ b/violet/analysis_options.yaml @@ -23,12 +23,12 @@ linter: # producing the lint. rules: avoid_print: false - use_build_context_synchronously: false # TODO(ykh09242): Enable this lint. sized_box_shrink_expand: true prefer_single_quotes: true always_use_package_imports: true unrelated_type_equality_checks: true + use_build_context_synchronously: true analyzer: errors: diff --git a/violet/lib/pages/after_loading/afterloading_page.dart b/violet/lib/pages/after_loading/afterloading_page.dart index 99266be41..82f2aa3ec 100644 --- a/violet/lib/pages/after_loading/afterloading_page.dart +++ b/violet/lib/pages/after_loading/afterloading_page.dart @@ -1,6 +1,8 @@ // This source code is a part of Project Violet. // Copyright (C) 2020-2024. violet-team. Licensed under the Apache-2.0 License. +// ignore_for_file: use_build_context_synchronously + import 'dart:async'; import 'dart:io'; diff --git a/violet/lib/pages/article_info/article_info_page.dart b/violet/lib/pages/article_info/article_info_page.dart index afafd29dc..016c210fb 100644 --- a/violet/lib/pages/article_info/article_info_page.dart +++ b/violet/lib/pages/article_info/article_info_page.dart @@ -299,6 +299,7 @@ class ArticleInfoPage extends StatelessWidget { navigatorFunc = Navigator.pushReplacement; } + if (!context.mounted) return; navigatorFunc( context, MaterialPageRoute( @@ -983,6 +984,7 @@ class _Chip extends StatelessWidget { Settings.excludeTags .add('${normalize(group)}:${name.replaceAll(' ', '_')}'); await Settings.setExcludeTags(Settings.excludeTags.join(' ')); + if (!context.mounted) return; await showOkDialog(context, '제외태그에 성공적으로 추가했습니다!'); } } else { diff --git a/violet/lib/pages/bookmark/bookmark_page.dart b/violet/lib/pages/bookmark/bookmark_page.dart index c3d82d7ab..79357f782 100644 --- a/violet/lib/pages/bookmark/bookmark_page.dart +++ b/violet/lib/pages/bookmark/bookmark_page.dart @@ -73,8 +73,8 @@ class _BookmarkPageState extends ThemeSwitchableState }), _dialButton(MdiIcons.group, 'newgroup', () async { (await Bookmark.getInstance()).createGroup( - Translations.of(context).trans('newgroup'), - Translations.of(context).trans('newgroup'), + Translations.instance!.trans('newgroup'), + Translations.instance!.trans('newgroup'), Colors.orange); setState(() {}); }), @@ -91,7 +91,7 @@ class _BookmarkPageState extends ThemeSwitchableState ? Palette.blackThemeBackground : Colors.grey.shade800 : Colors.white, - label: Translations.of(context).trans(label), + label: Translations.instance!.trans(label), labelStyle: TextStyle( fontSize: 14.0, color: Settings.themeWhat ? Colors.white : Colors.grey.shade800, diff --git a/violet/lib/pages/bookmark/crop_bookmark.dart b/violet/lib/pages/bookmark/crop_bookmark.dart index 7291660e4..43eaaed7a 100644 --- a/violet/lib/pages/bookmark/crop_bookmark.dart +++ b/violet/lib/pages/bookmark/crop_bookmark.dart @@ -246,6 +246,7 @@ class _CropBookmarkPageState extends State { var headers = await prov.getHeader(0); + if (!mounted) return; Navigator.push( context, MaterialPageRoute( @@ -281,6 +282,7 @@ class _CropBookmarkPageState extends State { onTap: () async { final crops = await (await Bookmark.getInstance()).getCropImages(); + if (!context.mounted) return; await showOkDialog( context, jsonEncode(crops), 'Export Crop Bookmarks'); }, @@ -392,6 +394,7 @@ class _CropBookmarkPageState extends State { bookmarks.add(bookmark); } + if (!context.mounted) return; PlatformNavigator.navigateSlide( context, CropBookmarkPage( diff --git a/violet/lib/pages/bookmark/group/group_article_list_page.dart b/violet/lib/pages/bookmark/group/group_article_list_page.dart index d2672df5e..c014c7194 100644 --- a/violet/lib/pages/bookmark/group/group_article_list_page.dart +++ b/violet/lib/pages/bookmark/group/group_article_list_page.dart @@ -549,6 +549,7 @@ class _GroupArticleListPageState extends State { groups = groups.where((e) => e.id() != currentGroup && e.id() != 1).toList(); int choose = -9999; + if (!mounted) return; if (await showDialog( context: context, builder: (BuildContext context) => AlertDialog( @@ -583,13 +584,14 @@ class _GroupArticleListPageState extends State { ), )) == 1) { + if (!mounted) return; if (await showYesNoDialog( context, - Translations.of(context) + Translations.instance! .trans('movetoto') .replaceAll('%1', groups[choose].name()) .replaceAll('%2', checked.length.toString()), - Translations.of(context).trans('movebookmark'))) { + Translations.instance!.trans('movebookmark'))) { // There is a way to change only the group, but there is also re-register a new bookmark. // I chose the latter to suit the user's intentions. diff --git a/violet/lib/pages/bookmark/group/group_artist_list.dart b/violet/lib/pages/bookmark/group/group_artist_list.dart index 49649ce01..600495ad1 100644 --- a/violet/lib/pages/bookmark/group/group_artist_list.dart +++ b/violet/lib/pages/bookmark/group/group_artist_list.dart @@ -429,6 +429,7 @@ class _GroupArtistListState extends State groups = groups.where((e) => e.id() != currentGroup && e.id() != 1).toList(); int choose = -9999; + if (!mounted) return; if (await showDialog( context: context, builder: (BuildContext context) => AlertDialog( @@ -463,13 +464,14 @@ class _GroupArtistListState extends State ), )) == 1) { + if (!mounted) return; if (await showYesNoDialog( context, - Translations.of(context) + Translations.instance! .trans('movetoto') .replaceAll('%1', groups[choose].name()) .replaceAll('%2', checked.length.toString()), - Translations.of(context).trans('movebookmark'))) { + Translations.instance!.trans('movebookmark'))) { // There is a way to change only the group, but there is also re-register a new bookmark. // I chose the latter to suit the user's intentions. diff --git a/violet/lib/pages/bookmark/group_modify.dart b/violet/lib/pages/bookmark/group_modify.dart index e976fa917..9bb79a050 100644 --- a/violet/lib/pages/bookmark/group_modify.dart +++ b/violet/lib/pages/bookmark/group_modify.dart @@ -71,6 +71,7 @@ class _GroupModifyPageState extends State { context, Translations.of(context).trans('deletegroupmsg'), Translations.of(context).trans('bookmark'))) { + if (!context.mounted) return; Navigator.pop(context, [2]); } }, diff --git a/violet/lib/pages/common/utils.dart b/violet/lib/pages/common/utils.dart index b41eba848..a2ba3c28b 100644 --- a/violet/lib/pages/common/utils.dart +++ b/violet/lib/pages/common/utils.dart @@ -26,6 +26,7 @@ Future showArticleInfo(BuildContext context, int id) async { final isBookmarked = await (await Bookmark.getInstance()).isBookmark(qr.id()); + if (!context.mounted) return; Provider? cache; showModalBottomSheet( context: context, diff --git a/violet/lib/pages/community/community_page.dart b/violet/lib/pages/community/community_page.dart index b73b68896..ed8d3e334 100644 --- a/violet/lib/pages/community/community_page.dart +++ b/violet/lib/pages/community/community_page.dart @@ -227,6 +227,7 @@ class _CommunityPageState extends State if (ync == true) { // signin + if (!mounted) return; var r = await showDialog( context: context, builder: (BuildContext context) { @@ -240,6 +241,7 @@ class _CommunityPageState extends State if (await VioletCommunitySession.checkUserAppId( _userAppId) != 'success') { + if (!mounted) return; await showOkDialog( context, 'You cannot continue,' @@ -250,6 +252,7 @@ class _CommunityPageState extends State ' please contact developer.'); return; } + if (!mounted) return; var r = await showDialog( context: context, builder: (BuildContext context) { @@ -264,11 +267,13 @@ class _CommunityPageState extends State if (await VioletCommunitySession.signUp( r[0], r[1], _userAppId, r[2]) == 'success') { + if (!mounted) return; await showOkDialog( context, 'Sign up is complete!'); id = r[0]; pw = r[1]; } else { + if (!mounted) return; await showOkDialog( context, 'Registration has been declined!'); return; diff --git a/violet/lib/pages/community/signin_dialog.dart b/violet/lib/pages/community/signin_dialog.dart index 919067ad7..868344639 100644 --- a/violet/lib/pages/community/signin_dialog.dart +++ b/violet/lib/pages/community/signin_dialog.dart @@ -27,11 +27,13 @@ class _SignInDialogState extends State { var pw = _descController.text.trim(); if (await VioletCommunitySession.signIn(id, pw) == null) { + if (!context.mounted) return; await showOkDialog(context, 'User is not registered, or password is different. If you continue to get this, please contact the developer.'); return; } + if (!context.mounted) return; Navigator.pop(context, [_nameController.text, _descController.text]); }, ); diff --git a/violet/lib/pages/community/signup_dialog.dart b/violet/lib/pages/community/signup_dialog.dart index 6e0d99558..204ec609a 100644 --- a/violet/lib/pages/community/signup_dialog.dart +++ b/violet/lib/pages/community/signup_dialog.dart @@ -37,17 +37,20 @@ class _SignUpDialogState extends State { } if (await VioletCommunitySession.checkId(id) != 'success') { + if (!context.mounted) return; await showOkDialog( context, 'Id already exists. Please use a different ID.'); return; } if (await VioletCommunitySession.checkNickName(nn) != 'success') { + if (!context.mounted) return; await showOkDialog(context, 'NickName already exists. Please use a different NickName.'); return; } + if (!context.mounted) return; Navigator.pop(context, [_idController.text, _pwController.text, _nnController.text]); }, diff --git a/violet/lib/pages/community/user_status_card_dead.dart b/violet/lib/pages/community/user_status_card_dead.dart index 8daf6abe0..f54a6fbb2 100644 --- a/violet/lib/pages/community/user_status_card_dead.dart +++ b/violet/lib/pages/community/user_status_card_dead.dart @@ -266,6 +266,7 @@ class _UserStatusCardState extends State if (ync == true) { // signin + if (!mounted) return; var r = await showDialog( context: context, builder: (BuildContext context) { @@ -279,6 +280,7 @@ class _UserStatusCardState extends State if (await VioletCommunitySession.checkUserAppId( _userAppId) != 'success') { + if (!mounted) return; await showOkDialog( context, 'You cannot continue, there is an account registered with your UserAppId.' @@ -286,6 +288,7 @@ class _UserStatusCardState extends State ' If you forgot your login information, please contact developer.'); return; } + if (!mounted) return; var r = await showDialog( context: context, builder: (BuildContext context) { @@ -300,10 +303,12 @@ class _UserStatusCardState extends State if (await VioletCommunitySession.signUp( r[0], r[1], _userAppId, r[2]) == 'success') { + if (!mounted) return; await showOkDialog(context, 'Sign up is complete!'); id = r[0]; pw = r[1]; } else { + if (!mounted) return; await showOkDialog( context, 'Registration has been declined!'); return; diff --git a/violet/lib/pages/database_download/database_download_page.dart b/violet/lib/pages/database_download/database_download_page.dart index 22142c132..5cbedbe37 100644 --- a/violet/lib/pages/database_download/database_download_page.dart +++ b/violet/lib/pages/database_download/database_download_page.dart @@ -186,6 +186,7 @@ class DataBaseDownloadPageState extends State { message: Translations.instance!.trans('dbdcomplete'), ); + if (!mounted) return; Navigator.of(context).pushReplacementNamed('/AfterLoading'); return; diff --git a/violet/lib/pages/download/download_align_type.dart b/violet/lib/pages/download/download_align_type.dart index b34d9f1ea..931afcd40 100644 --- a/violet/lib/pages/download/download_align_type.dart +++ b/violet/lib/pages/download/download_align_type.dart @@ -63,6 +63,8 @@ class DownloadAlignType extends StatelessWidget { softWrap: false, style: TextStyle(color: getColor(selection))), onTap: () async { await Settings.setDownloadAlignType(selection); + + if (!context.mounted) return; Navigator.pop(context); }, ); diff --git a/violet/lib/pages/download/download_item_widget.dart b/violet/lib/pages/download/download_item_widget.dart index bc7941c05..c1d390612 100644 --- a/violet/lib/pages/download/download_item_widget.dart +++ b/violet/lib/pages/download/download_item_widget.dart @@ -255,7 +255,7 @@ class DownloadItemWidgetState extends State icon: Icons.download, level: ToastLevel.check, message: - '${widget.item.info()!.split('[')[1].split(']').first}${Translations.of(context).trans('download')} ${Translations.of(context).trans('complete')}', + '${widget.item.info()!.split('[')[1].split(']').first}${Translations.instance!.trans('download')} ${Translations.instance!.trans('complete')}', ); } }); @@ -325,6 +325,7 @@ class DownloadItemWidgetState extends State await (await User.getInstance()) .insertUserLog(int.tryParse(widget.item.url()) ?? -1, 0); + if (!context.mounted) return; Navigator.push( context, MaterialPageRoute( diff --git a/violet/lib/pages/download/download_page.dart b/violet/lib/pages/download/download_page.dart index 26f8182b7..f684915c6 100644 --- a/violet/lib/pages/download/download_page.dart +++ b/violet/lib/pages/download/download_page.dart @@ -1,6 +1,8 @@ // This source code is a part of Project Violet. // Copyright (C) 2020-2024. violet-team. Licensed under the Apache-2.0 License. +// ignore_for_file: use_build_context_synchronously + import 'dart:async'; import 'dart:convert'; import 'dart:io'; diff --git a/violet/lib/pages/download/download_view_type.dart b/violet/lib/pages/download/download_view_type.dart index a0b5fc2eb..30ad4dc38 100644 --- a/violet/lib/pages/download/download_view_type.dart +++ b/violet/lib/pages/download/download_view_type.dart @@ -61,6 +61,8 @@ class DownloadViewType extends StatelessWidget { softWrap: false, style: TextStyle(color: getColor(selection))), onTap: () async { await Settings.setDownloadResultType(selection); + + if (!context.mounted) return; Navigator.pop(context); }, ); diff --git a/violet/lib/pages/lock/lock_screen.dart b/violet/lib/pages/lock/lock_screen.dart index 8a68688ff..eeb984849 100644 --- a/violet/lib/pages/lock/lock_screen.dart +++ b/violet/lib/pages/lock/lock_screen.dart @@ -263,9 +263,11 @@ class _LockScreenState extends State with TickerProviderStateMixin { if (dialog != null && dialog) { if (text.text == 'violet.jjang') { - await showOkDialog(context, Translations.of(context).trans('resetpin'), + if (!mounted) return; + await showOkDialog(context, Translations.instance!.trans('resetpin'), Translations.of(context).trans('authmanager')); + if (!mounted) return; Navigator.pushReplacementNamed(context, '/SplashPage'); } else { _controller.forward(); @@ -273,10 +275,11 @@ class _LockScreenState extends State with TickerProviderStateMixin { _controller.reverse(); setState(() {}); }); + if (!mounted) return; await showOkDialog( context, - Translations.of(context).trans('notcorrectsecondpass'), - Translations.of(context).trans('authmanager')); + Translations.instance!.trans('notcorrectsecondpass'), + Translations.instance!.trans('authmanager')); } } } @@ -286,6 +289,7 @@ class _LockScreenState extends State with TickerProviderStateMixin { final pinPass = prefs.getString('pinPass'); if (!widget.isRegisterMode && _pin.join() == pinPass) { + if (!mounted) return; if (widget.isSecureMode) { Navigator.of(context).pop(); } else { diff --git a/violet/lib/pages/main/info/lab/bookmark/bookmarks.dart b/violet/lib/pages/main/info/lab/bookmark/bookmarks.dart index 58f1c9c4a..b2d03074e 100644 --- a/violet/lib/pages/main/info/lab/bookmark/bookmarks.dart +++ b/violet/lib/pages/main/info/lab/bookmark/bookmarks.dart @@ -207,6 +207,7 @@ class _BookmarkPageState extends State { }); await dbraw.close(); + if (!mounted) return; await showOkDialog( context, '북마크 그룹을 성공적으로 끌어왔습니다!', 'Bookmark Spy'); } diff --git a/violet/lib/pages/main/info/lab/bookmark_spy.dart b/violet/lib/pages/main/info/lab/bookmark_spy.dart index cd22e8e5a..a921f59e7 100644 --- a/violet/lib/pages/main/info/lab/bookmark_spy.dart +++ b/violet/lib/pages/main/info/lab/bookmark_spy.dart @@ -136,6 +136,7 @@ class _LabBookmarkSpyPageState extends State { var bookmark = await Bookmark.getInstance(); await bookmark.setHistoryUser(data['user'] as String); + if (!mounted) return; await PlatformNavigator.navigateSlide( context, LabBookmarkPage(userAppId: data['user'] as String)); diff --git a/violet/lib/pages/main/info/lab/global_comments.dart b/violet/lib/pages/main/info/lab/global_comments.dart index 7f0d6e0a6..91474937b 100644 --- a/violet/lib/pages/main/info/lab/global_comments.dart +++ b/violet/lib/pages/main/info/lab/global_comments.dart @@ -174,6 +174,8 @@ class _LabGlobalCommentsState extends State { modReply = false; } text.text = ''; + + if (!context.mounted) return; FocusScope.of(context).unfocus(); setState(() {}); await readComments(); diff --git a/violet/lib/pages/main/info/lab_page.dart b/violet/lib/pages/main/info/lab_page.dart index 34ed55572..d52661c89 100644 --- a/violet/lib/pages/main/info/lab_page.dart +++ b/violet/lib/pages/main/info/lab_page.dart @@ -220,11 +220,13 @@ class _LaboratoryPageState extends State { ); if (dialog == true) { if (getValid('${text.text}saltff') == '605f372') { + if (!context.mounted) return; await showOkDialog(context, 'Successful!'); final prefs = await SharedPreferences.getInstance(); await prefs.setString('labmasterkey', text.text); } else { + if (!context.mounted) return; await showOkDialog(context, 'Fail!'); } } @@ -287,6 +289,7 @@ class _LaboratoryPageState extends State { null, () async { if (!await _checkMaterKey()) { + if (!context.mounted) return; await showOkDialog(context, 'You cannot use this feature!'); return; } @@ -327,6 +330,7 @@ class _LaboratoryPageState extends State { null, () async { if (!await _checkMaterKey()) { + if (!context.mounted) return; await showOkDialog(context, 'You cannot use this feature!'); return; } diff --git a/violet/lib/pages/main/main_page.dart b/violet/lib/pages/main/main_page.dart index 2ccded235..a00be3775 100644 --- a/violet/lib/pages/main/main_page.dart +++ b/violet/lib/pages/main/main_page.dart @@ -232,6 +232,7 @@ class _MainPageState extends ThemeSwitchableState if (!await Permission.manageExternalStorage.isGranted) { if (await Permission.manageExternalStorage.request() == PermissionStatus.denied) { + if (!mounted) return; await showOkDialog(context, 'If you do not allow file permissions, you cannot continue :('); return; @@ -285,8 +286,9 @@ class _MainPageState extends ThemeSwitchableState final prefs = await SharedPreferences.getInstance(); if (prefs.getBool('usevioletserver_check') != null) return; + if (!mounted) return; var bb = await showYesNoDialog( - context, Translations.of(context).trans('violetservermsg')); + context, Translations.instance!.trans('violetservermsg')); if (bb == false) { await prefs.setBool('usevioletserver_check', false); return; @@ -475,7 +477,7 @@ class _VersionAreaWidgetState extends State<_VersionAreaWidget> { latestDB.difference(DateTime.parse(lastDB)).inHours < 1) { showToast( level: ToastLevel.check, - message: Translations.of(context).trans('thisislatestbookmark'), + message: Translations.instance!.trans('thisislatestbookmark'), ); return; } @@ -492,6 +494,7 @@ class _VersionAreaWidgetState extends State<_VersionAreaWidget> { syncAvailable = false; }); + if (!mounted) return; await Navigator.of(context) .push(MaterialPageRoute( builder: (context) => DataBaseDownloadPage( @@ -506,6 +509,7 @@ class _VersionAreaWidgetState extends State<_VersionAreaWidget> { HitomiManager.tagmap = jsonDecode(text); await DataBaseManager.reloadInstance(); + if (!mounted) return; showToast( level: ToastLevel.check, message: Translations.of(context).trans('synccomplete'), diff --git a/violet/lib/pages/search/search_page.dart b/violet/lib/pages/search/search_page.dart index 3e9eb2285..f3f6b1710 100644 --- a/violet/lib/pages/search/search_page.dart +++ b/violet/lib/pages/search/search_page.dart @@ -1,6 +1,8 @@ // This source code is a part of Project Violet. // Copyright (C) 2020-2024. violet-team. Licensed under the Apache-2.0 License. +// ignore_for_file: use_build_context_synchronously + import 'dart:async'; import 'dart:math'; @@ -395,6 +397,7 @@ class _SearchPageState extends ThemeSwitchableState c.heroFlareControls.play('search2close'); + if (!mounted) return; final query = await Navigator.push( context, MaterialPageRoute( diff --git a/violet/lib/pages/search/search_type.dart b/violet/lib/pages/search/search_type.dart index 39e2947c3..e1d0c52f7 100644 --- a/violet/lib/pages/search/search_type.dart +++ b/violet/lib/pages/search/search_type.dart @@ -67,6 +67,7 @@ class SearchType extends StatelessWidget { softWrap: false, style: TextStyle(color: getColor(selection))), onTap: () async { await Settings.setSearchResultType(selection); + if (!context.mounted) return; Navigator.pop(context); }, ); diff --git a/violet/lib/pages/settings/bookmark_version_select.dart b/violet/lib/pages/settings/bookmark_version_select.dart index 94b4e5afd..4fe0d4ad1 100644 --- a/violet/lib/pages/settings/bookmark_version_select.dart +++ b/violet/lib/pages/settings/bookmark_version_select.dart @@ -118,7 +118,9 @@ class _BookmarkVersionSelectPageState extends State { version: data['vid'] as String, )); + if (!mounted) return; if (await showYesNoDialog(context, '이 북마크 버전을 선택할까요?')) { + if (!mounted) return; Navigator.pop(context, data['vid']); } }, diff --git a/violet/lib/pages/settings/db_rebuild_page.dart b/violet/lib/pages/settings/db_rebuild_page.dart index b1ed8d28c..e0a7c992d 100644 --- a/violet/lib/pages/settings/db_rebuild_page.dart +++ b/violet/lib/pages/settings/db_rebuild_page.dart @@ -24,6 +24,7 @@ class _DBRebuildPagePageState extends State { Future.delayed(const Duration(milliseconds: 100)).then((value) async { await indexing(); + if (!mounted) return; Navigator.pop(context); }); } diff --git a/violet/lib/pages/settings/import_from_eh.dart b/violet/lib/pages/settings/import_from_eh.dart index 29cb63900..f8a62cdb0 100644 --- a/violet/lib/pages/settings/import_from_eh.dart +++ b/violet/lib/pages/settings/import_from_eh.dart @@ -21,6 +21,7 @@ class _ImportFromEHPageState extends State { Future.delayed(const Duration(milliseconds: 100)).then((value) async { await EHBookmark.process(); + if (!mounted) return; Navigator.pop(context); }); } diff --git a/violet/lib/pages/settings/lock_setting_page.dart b/violet/lib/pages/settings/lock_setting_page.dart index 3ae742996..f2acbad03 100644 --- a/violet/lib/pages/settings/lock_setting_page.dart +++ b/violet/lib/pages/settings/lock_setting_page.dart @@ -111,8 +111,9 @@ class _LockSettingPageState extends State { Future _toggleAppLock() async { final prefs = await SharedPreferences.getInstance(); if (prefs.getString('pinPass') == null) { - showOkDialog(context, - Translations.of(context).trans('registerfinbeforeuseapplock')); + if (!mounted) return; + showOkDialog( + context, Translations.instance!.trans('registerfinbeforeuseapplock')); return; } diff --git a/violet/lib/pages/settings/login/ehentai_login.dart b/violet/lib/pages/settings/login/ehentai_login.dart index 9ff749424..581130d7d 100644 --- a/violet/lib/pages/settings/login/ehentai_login.dart +++ b/violet/lib/pages/settings/login/ehentai_login.dart @@ -73,6 +73,7 @@ class _LoginScreenState extends State { (cookies.containsKey('sk') || cookies.containsKey('igneous'))) { // await sessionStore.setSession(cookieString); // await _cookieManager.clearCookies(); + if (!mounted) return; Navigator.pop(context, cookieString); } else if (cookies.containsKey('ipb_member_id')) { controller.loadUrl('https://exhentai.org'); diff --git a/violet/lib/pages/settings/restore_bookmark.dart b/violet/lib/pages/settings/restore_bookmark.dart index f305065fa..2e1966cc3 100644 --- a/violet/lib/pages/settings/restore_bookmark.dart +++ b/violet/lib/pages/settings/restore_bookmark.dart @@ -119,10 +119,13 @@ class _RestoreBookmarkPageState extends State { level: ToastLevel.error, message: 'Bookmark Restoring Error!', ); + + if (!mounted) return; Navigator.pop(context, false); return; } + if (!mounted) return; Navigator.pop(context, true); }); } diff --git a/violet/lib/pages/settings/settings_page.dart b/violet/lib/pages/settings/settings_page.dart index 82cd61dd0..1755808fb 100644 --- a/violet/lib/pages/settings/settings_page.dart +++ b/violet/lib/pages/settings/settings_page.dart @@ -1,6 +1,8 @@ // This source code is a part of Project Violet. // Copyright (C) 2020-2024. violet-team. Licensed under the Apache-2.0 License. +// ignore_for_file: use_build_context_synchronously + import 'dart:convert'; import 'dart:io'; diff --git a/violet/lib/pages/settings/tag_rebuild_page.dart b/violet/lib/pages/settings/tag_rebuild_page.dart index a11c061e8..e99c5aab3 100644 --- a/violet/lib/pages/settings/tag_rebuild_page.dart +++ b/violet/lib/pages/settings/tag_rebuild_page.dart @@ -29,6 +29,7 @@ class _TagRebuildPageState extends State { Future.delayed(const Duration(milliseconds: 100)).then((value) async { await indexing(); + if (!mounted) return; Navigator.pop(context); }); } diff --git a/violet/lib/pages/splash/splash_page.dart b/violet/lib/pages/splash/splash_page.dart index f355792f0..245eeeee1 100644 --- a/violet/lib/pages/splash/splash_page.dart +++ b/violet/lib/pages/splash/splash_page.dart @@ -1,6 +1,8 @@ // This source code is a part of Project Violet. // Copyright (C) 2020-2024. violet-team. Licensed under the Apache-2.0 License. +// ignore_for_file: use_build_context_synchronously + import 'dart:async'; import 'dart:io'; @@ -581,7 +583,7 @@ class _SplashPageState extends State { await Directory('${dir.path}/data').delete(recursive: true); } catch (_) {} } - print(Translations.of(context).dbLanguageCode); + if (!mounted) return; Navigator.of(context).pushReplacement(MaterialPageRoute( builder: (context) => DataBaseDownloadPage( dbType: _database == Database.all @@ -718,8 +720,10 @@ class _SplashPageState extends State { .path; if (filename == null) { - await showOkDialog( - context, Translations.of(context).trans('dbalreadyerr')); + if (mounted) { + await showOkDialog( + context, Translations.of(context).trans('dbalreadyerr')); + } return ''; } diff --git a/violet/lib/pages/viewer/horizontal_viewer_page.dart b/violet/lib/pages/viewer/horizontal_viewer_page.dart index 87aaa06f4..168dcc14f 100644 --- a/violet/lib/pages/viewer/horizontal_viewer_page.dart +++ b/violet/lib/pages/viewer/horizontal_viewer_page.dart @@ -223,6 +223,7 @@ class _HorizontalViewerPageState extends State { c.urlCache[page.toInt() + 2]!.value); } await c.precache(context, page.toInt() - 1); + if (!mounted) return; await c.precache(context, page.toInt() + 1); } } diff --git a/violet/lib/pages/viewer/image/file_image.dart b/violet/lib/pages/viewer/image/file_image.dart index b496d50e2..be2d88a19 100644 --- a/violet/lib/pages/viewer/image/file_image.dart +++ b/violet/lib/pages/viewer/image/file_image.dart @@ -202,6 +202,8 @@ class ImageCropBookmark extends StatelessWidget { message: '$articleId(${page}p): [${area.toString().split('(')[1].split(')')[0]}] Saved!', ); + + if (!context.mounted) return; Navigator.pop(context); } } diff --git a/violet/lib/pages/viewer/image/provider_image.dart b/violet/lib/pages/viewer/image/provider_image.dart index 5f9b0d296..3b800b8bb 100644 --- a/violet/lib/pages/viewer/image/provider_image.dart +++ b/violet/lib/pages/viewer/image/provider_image.dart @@ -229,6 +229,7 @@ class ImageCropBookmark extends StatelessWidget { '$articleId(${page}p): [${area.toString().split('(')[1].split(')')[0]}] Saved!', ); + if (!context.mounted) return; Navigator.pop(context); } } diff --git a/violet/lib/pages/viewer/overlay/viewer_overlay.dart b/violet/lib/pages/viewer/overlay/viewer_overlay.dart index e13f7beab..99f7f7501 100644 --- a/violet/lib/pages/viewer/overlay/viewer_overlay.dart +++ b/violet/lib/pages/viewer/overlay/viewer_overlay.dart @@ -137,6 +137,7 @@ class _ViewerOverlayState extends State { borderRadius: const BorderRadius.all(Radius.circular(8.0)), onPressed: () async { await c.close(); + if (!mounted) return; Navigator.pop(context, c.page.value); }, child: Row( @@ -255,6 +256,7 @@ class _ViewerOverlayState extends State { color: Colors.white, onPressed: () async { await c.close(); + if (!mounted) return; Navigator.pop(context, c.page.value); }, ); @@ -269,6 +271,7 @@ class _ViewerOverlayState extends State { await (await Bookmark.getInstance()).isBookmark(c.articleId); if (c.bookmark.value) { + if (!mounted) return; if (!await showYesNoDialog(context, '북마크를 삭제할까요?', '북마크')) return; } @@ -281,7 +284,7 @@ class _ViewerOverlayState extends State { ignoreDrawer: true, reverse: true, msg: - '${c.articleId}${locale.Translations.of(context).trans(!c.bookmark.value ? 'addtobookmark' : 'removetobookmark')}', + '${c.articleId}${locale.Translations.instance!.trans(!c.bookmark.value ? 'addtobookmark' : 'removetobookmark')}', ), gravity: ToastGravity.TOP, toastDuration: const Duration(seconds: 4), @@ -326,6 +329,7 @@ class _ViewerOverlayState extends State { c.isStaring = false; c.stopTimer(); + if (!mounted) return; Provider? cache; showModalBottomSheet( context: context, diff --git a/violet/lib/pages/viewer/overlay/viewer_tab_panel.dart b/violet/lib/pages/viewer/overlay/viewer_tab_panel.dart index b7909ea5f..fb5923ef4 100644 --- a/violet/lib/pages/viewer/overlay/viewer_tab_panel.dart +++ b/violet/lib/pages/viewer/overlay/viewer_tab_panel.dart @@ -417,6 +417,7 @@ class __ArtistsArticleTabListState extends State<_ArtistsArticleTabList> var isBookmarked = await (await Bookmark.getInstance()).isBookmark(e.id()); + if (!mounted) return; Provider? cache; showModalBottomSheet( context: context, @@ -464,6 +465,7 @@ class __ArtistsArticleTabListState extends State<_ArtistsArticleTabList> var headers = await prov.getHeader(0); + if (!mounted) return; Navigator.push( context, MaterialPageRoute( diff --git a/violet/lib/pages/viewer/overlay/viewer_thumbnails.dart b/violet/lib/pages/viewer/overlay/viewer_thumbnails.dart index 753bf84d1..825355555 100644 --- a/violet/lib/pages/viewer/overlay/viewer_thumbnails.dart +++ b/violet/lib/pages/viewer/overlay/viewer_thumbnails.dart @@ -294,6 +294,8 @@ class _ViewerThumbnailState extends State { AlertDialog alert = AlertDialog( content: SelectableText(infoText), ); + + if (!mounted) return; await showDialog( context: context, builder: (BuildContext context) { diff --git a/violet/lib/pages/viewer/viewer_controller.dart b/violet/lib/pages/viewer/viewer_controller.dart index 344a5d709..71325de7e 100644 --- a/violet/lib/pages/viewer/viewer_controller.dart +++ b/violet/lib/pages/viewer/viewer_controller.dart @@ -216,6 +216,8 @@ class ViewerController extends GetxController { if (index < 0 || maxPage <= index) return; await load(index); + + if (!context.mounted) return; await precacheImage( CachedNetworkImageProvider( urlCache[index]!.value, diff --git a/violet/lib/pages/viewer/viewer_page.dart b/violet/lib/pages/viewer/viewer_page.dart index 098303c8d..d33773197 100644 --- a/violet/lib/pages/viewer/viewer_page.dart +++ b/violet/lib/pages/viewer/viewer_page.dart @@ -272,6 +272,7 @@ class _ViewerPageState extends State { } if (!moveAnywhere) { + if (!mounted) return; final isJump = await showYesNoDialog( context, locale.Translations.of(context) @@ -304,6 +305,7 @@ class _ViewerPageState extends State { var prov = await ProviderManager.get(article.id()); var headers = await prov.getHeader(0); + if (!mounted) return; Navigator.pushReplacement( context, PageRouteBuilder( diff --git a/violet/lib/update/update_manager.dart b/violet/lib/update/update_manager.dart index e5ad196fe..277ddc7c2 100644 --- a/violet/lib/update/update_manager.dart +++ b/violet/lib/update/update_manager.dart @@ -26,6 +26,7 @@ class UpdateManager { // Update is only available for Android. if (Platform.isAndroid) { + if (!context.mounted) return; updateCheckAndDownload(context); // @dependent: android } } @@ -54,6 +55,7 @@ class UpdateManager { if (!await Permission.manageExternalStorage.isGranted) { if (await Permission.manageExternalStorage.request() == PermissionStatus.denied) { + if (!context.mounted) return; await showOkDialog(context, 'If you do not allow file permissions, you cannot continue :('); return; @@ -95,8 +97,9 @@ class UpdateManager { final prefs = await SharedPreferences.getInstance(); if (prefs.getBool('usevioletserver_check') != null) return; + if (!context.mounted) return; final bb = await showYesNoDialog( - context, Translations.of(context).trans('violetservermsg')); + context, Translations.instance!.trans('violetservermsg')); if (bb == false) { await prefs.setBool('usevioletserver_check', false); return; diff --git a/violet/lib/widgets/article_item/article_list_item_widget.dart b/violet/lib/widgets/article_item/article_list_item_widget.dart index 27125cf10..69292cab7 100644 --- a/violet/lib/widgets/article_item/article_list_item_widget.dart +++ b/violet/lib/widgets/article_item/article_list_item_widget.dart @@ -331,6 +331,7 @@ class _ArticleListItemWidgetState extends State await prov.init(); + if (!mounted) return; Navigator.push( context, MaterialPageRoute( @@ -385,7 +386,7 @@ class _ArticleListItemWidgetState extends State ? Colors.redAccent.withOpacity(0.8) : Colors.greenAccent.withOpacity(0.8), msg: - '${data.queryResult.id()}${locale.Translations.of(context).trans(c.isBookmarked.value ? 'removetobookmark' : 'addtobookmark')}', + '${data.queryResult.id()}${locale.Translations.instance!.trans(c.isBookmarked.value ? 'removetobookmark' : 'addtobookmark')}', ), ignorePointer: true, gravity: ToastGravity.BOTTOM, @@ -764,7 +765,9 @@ class TagChip extends StatelessWidget { if (yn) { Settings.excludeTags.add(targetTag); await Settings.setExcludeTags(Settings.excludeTags.join(' ')); - await showOkDialog(context, '제외태그에 성공적으로 추가했습니다!'); + if (context.mounted) { + await showOkDialog(context, '제외태그에 성공적으로 추가했습니다!'); + } } } else { await showOkDialog(context, '$targetTag 태그는 이미 제외태그에 추가된 항목입니다!'); From b6722c11f8733861fdd7af26bfaa8bc86ec0a68e Mon Sep 17 00:00:00 2001 From: violet-dev Date: Sun, 8 Sep 2024 17:00:12 +0900 Subject: [PATCH 08/10] Use specific translation instance --- violet/lib/other/dialogs.dart | 14 +- .../after_loading/afterloading_page.dart | 6 +- .../pages/article_info/article_info_page.dart | 47 ++-- .../pages/artist_info/artist_info_page.dart | 34 +-- .../lib/pages/artist_info/search_type2.dart | 10 +- .../pages/artist_info/similar_list_page.dart | 2 +- violet/lib/pages/bookmark/bookmark_page.dart | 16 +- .../group/group_article_list_page.dart | 8 +- .../bookmark/group/group_artist_list.dart | 8 +- violet/lib/pages/bookmark/group_modify.dart | 16 +- .../lib/pages/bookmark/record_view_page.dart | 2 +- .../lib/pages/community/user_status_card.dart | 4 +- .../database_download_page.dart | 6 +- .../pages/download/download_align_type.dart | 10 +- .../pages/download/download_item_menu.dart | 2 +- violet/lib/pages/download/download_page.dart | 9 +- .../pages/download/download_view_type.dart | 2 +- violet/lib/pages/lock/lock_screen.dart | 22 +- .../artist_collection_page.dart | 4 +- .../main/card/artist_collection_card.dart | 2 +- .../lib/pages/main/card/update_log_card.dart | 2 +- violet/lib/pages/main/card/views_card.dart | 2 +- .../info/lab/artist_search/artist_search.dart | 2 +- .../lab/artist_search/tag_group_modify.dart | 4 +- .../main/info/lab/bookmark/bookmarks.dart | 8 +- .../pages/main/info/lab/global_comments.dart | 2 +- violet/lib/pages/main/info/lab_page.dart | 4 +- violet/lib/pages/main/info/violet_page.dart | 2 +- violet/lib/pages/main/main_page.dart | 43 ++- violet/lib/pages/main/views/views_page.dart | 8 +- violet/lib/pages/search/search_bar_page.dart | 20 +- violet/lib/pages/search/search_page.dart | 9 +- .../lib/pages/search/search_page_modify.dart | 8 +- violet/lib/pages/search/search_type.dart | 2 +- violet/lib/pages/segment/filter_page.dart | 8 +- .../settings/bookmark_version_select.dart | 2 +- .../lib/pages/settings/lock_setting_page.dart | 16 +- violet/lib/pages/settings/settings_page.dart | 264 +++++++++--------- violet/lib/pages/settings/tag_selector.dart | 12 +- violet/lib/pages/settings/version_page.dart | 2 +- violet/lib/pages/splash/splash_page.dart | 22 +- .../viewer/overlay/viewer_setting_panel.dart | 54 ++-- violet/lib/pages/viewer/viewer_page.dart | 4 +- violet/lib/update/update_manager.dart | 2 +- 44 files changed, 357 insertions(+), 369 deletions(-) diff --git a/violet/lib/other/dialogs.dart b/violet/lib/other/dialogs.dart index 26f6e1614..70bd36eb5 100644 --- a/violet/lib/other/dialogs.dart +++ b/violet/lib/other/dialogs.dart @@ -20,7 +20,7 @@ Future showOkDialog(BuildContext context, String message, onPressed: () { Navigator.pop(context); }, - child: Text(Translations.of(context).trans('ok')), + child: Text(Translations.instance!.trans('ok')), ), ], ), @@ -61,7 +61,7 @@ Future showOkCancelDialog({ Navigator.pop(context, true); } }, - child: Text(okText ?? Translations.of(context).trans('ok')), + child: Text(okText ?? Translations.instance!.trans('ok')), ), TextButton( style: TextButton.styleFrom(foregroundColor: Settings.majorColor), @@ -72,7 +72,7 @@ Future showOkCancelDialog({ Navigator.pop(context, false); } }, - child: Text(cancelText ?? Translations.of(context).trans('cancel')), + child: Text(cancelText ?? Translations.instance!.trans('cancel')), ), ], ), @@ -92,14 +92,14 @@ Future showYesNoDialog(BuildContext context, String message, onPressed: () { Navigator.pop(context, true); }, - child: Text(Translations.of(context).trans('yes')), + child: Text(Translations.instance!.trans('yes')), ), TextButton( style: TextButton.styleFrom(foregroundColor: Settings.majorColor), onPressed: () { Navigator.pop(context, false); }, - child: Text(Translations.of(context).trans('no')), + child: Text(Translations.instance!.trans('no')), ), ], ), @@ -120,14 +120,14 @@ Future showYesNoCancelDialog(BuildContext context, String message, onPressed: () { Navigator.pop(context, true); }, - child: Text(Translations.of(context).trans('yes')), + child: Text(Translations.instance!.trans('yes')), ), TextButton( style: TextButton.styleFrom(foregroundColor: Settings.majorColor), onPressed: () { Navigator.pop(context, false); }, - child: Text(Translations.of(context).trans('no')), + child: Text(Translations.instance!.trans('no')), ), ], ), diff --git a/violet/lib/pages/after_loading/afterloading_page.dart b/violet/lib/pages/after_loading/afterloading_page.dart index 82f2aa3ec..af7e6d600 100644 --- a/violet/lib/pages/after_loading/afterloading_page.dart +++ b/violet/lib/pages/after_loading/afterloading_page.dart @@ -118,7 +118,7 @@ class AfterLoadingPageState extends State List.generate(7, (index) => GlobalKey()); Widget _buildBottomNavigationBar(BuildContext context) { - final translations = Translations.of(context); + final translations = Translations.instance!; BottomNavigationBarItem buildItem(IconData iconData, String key) { return BottomNavigationBarItem( @@ -198,7 +198,7 @@ class AfterLoadingPageState extends State Widget _buildDrawer(BuildContext context) { final mediaQuery = MediaQuery.of(context); - final translations = Translations.of(context); + final translations = Translations.instance!; Widget buildButton(IconData iconData, int page, String key) { final color = Settings.majorColor; @@ -331,7 +331,7 @@ class AfterLoadingPageState extends State showToast( icon: Icons.logout, level: ToastLevel.warning, - message: Translations.of(context).trans('closedoubletap'), + message: Translations.instance!.trans('closedoubletap'), ); } }, diff --git a/violet/lib/pages/article_info/article_info_page.dart b/violet/lib/pages/article_info/article_info_page.dart index 016c210fb..43dbc615a 100644 --- a/violet/lib/pages/article_info/article_info_page.dart +++ b/violet/lib/pages/article_info/article_info_page.dart @@ -104,7 +104,7 @@ class ArticleInfoPage extends StatelessWidget { child: SizedBox( width: (width - 32 - 64 - 32) / 2, child: Text( - Translations.of(context).trans('download'), + Translations.instance!.trans('download'), textAlign: TextAlign.center, ), ), @@ -120,7 +120,7 @@ class ArticleInfoPage extends StatelessWidget { child: SizedBox( width: (width - 32 - 64 - 32) / 2, child: Text( - Translations.of(context).trans('read'), + Translations.instance!.trans('read'), textAlign: TextAlign.center, ), ), @@ -148,8 +148,7 @@ class ArticleInfoPage extends StatelessWidget { const Duration(milliseconds: 500)), header: Padding( padding: const EdgeInsets.fromLTRB(12, 12, 0, 0), - child: - Text(Translations.of(context).trans('preview')), + child: Text(Translations.instance!.trans('preview')), ), expanded: PreviewAreaWidget( queryResult: data.queryResult, @@ -180,7 +179,7 @@ class ArticleInfoPage extends StatelessWidget { header: Padding( padding: const EdgeInsets.fromLTRB(12, 12, 0, 0), child: Text( - '${Translations.of(context).trans('related')} ${Translations.of(context).trans('articles')}'), + '${Translations.instance!.trans('related')} ${Translations.instance!.trans('articles')}'), ), expanded: _RelatedArea( relatedIds: @@ -207,7 +206,7 @@ class ArticleInfoPage extends StatelessWidget { child: Container( width: (width - 32 - 64 - 32) / 2, child: Text( - Translations.of(context).trans('download'), + Translations.instance!.trans('download'), textAlign: TextAlign.center, ), ), @@ -221,7 +220,7 @@ class ArticleInfoPage extends StatelessWidget { child: Container( width: (width - 32 - 64 - 32) / 2, child: Text( - Translations.of(context).trans('read'), + Translations.instance!.trans('read'), textAlign: TextAlign.center, ), ), @@ -266,7 +265,7 @@ class ArticleInfoPage extends StatelessWidget { icon: Icons.download, level: ToastLevel.check, message: - '${data.queryResult.id()}${Translations.of(context).trans('addtodownloadqueue')}', + '${data.queryResult.id()}${Translations.instance!.trans('addtodownloadqueue')}', ); await ScriptManager.refresh(); @@ -358,7 +357,7 @@ class TagInfoAreaWidget extends StatelessWidget { children: [ MultiChipWidget( queryResult.tags(), - Translations.of(context).trans('tags'), + Translations.instance!.trans('tags'), queryResult.tags() != null ? (queryResult.tags() as String) .split('|') @@ -370,11 +369,11 @@ class TagInfoAreaWidget extends StatelessWidget { : []), SingleChipWidget( queryResult.language(), - Translations.of(context).trans('language').split(' ')[0].trim(), + Translations.instance!.trans('language').split(' ')[0].trim(), 'language'), MultiChipWidget( queryResult.artists(), - Translations.of(context).trans('artist'), + Translations.instance!.trans('artist'), queryResult.artists() != null ? (queryResult.artists() as String) .split('|') @@ -384,7 +383,7 @@ class TagInfoAreaWidget extends StatelessWidget { : []), MultiChipWidget( queryResult.groups(), - Translations.of(context).trans('group'), + Translations.instance!.trans('group'), queryResult.groups() != null ? (queryResult.groups() as String) .split('|') @@ -394,7 +393,7 @@ class TagInfoAreaWidget extends StatelessWidget { : []), MultiChipWidget( queryResult.series(), - Translations.of(context).trans('series'), + Translations.instance!.trans('series'), queryResult.series() != null ? (queryResult.series() as String) .split('|') @@ -404,7 +403,7 @@ class TagInfoAreaWidget extends StatelessWidget { : []), MultiChipWidget( queryResult.characters(), - Translations.of(context).trans('character'), + Translations.instance!.trans('character'), queryResult.characters() != null ? (queryResult.characters() as String) .split('|') @@ -413,13 +412,13 @@ class TagInfoAreaWidget extends StatelessWidget { .toList() : []), SingleChipWidget( - queryResult.type(), Translations.of(context).trans('type'), 'type'), + queryResult.type(), Translations.instance!.trans('type'), 'type'), SingleChipWidget(queryResult.uploader(), - Translations.of(context).trans('uploader'), 'uploader'), + Translations.instance!.trans('uploader'), 'uploader'), SingleChipWidget(queryResult.id().toString(), - Translations.of(context).trans('id'), 'id'), + Translations.instance!.trans('id'), 'id'), SingleChipWidget(queryResult.classname(), - Translations.of(context).trans('class'), 'class'), + Translations.instance!.trans('class'), 'class'), Container(height: 10), ], ); @@ -601,7 +600,7 @@ class __InfoAreaWidgetState extends State<_InfoAreaWidget> { header: Padding( padding: const EdgeInsets.fromLTRB(12, 12, 0, 0), child: Text( - '${Translations.of(context).trans('comment')} (${widget.comments.length})'), + '${Translations.instance!.trans('comment')} (${widget.comments.length})'), ), expanded: commentArea(context), collapsed: Container(), @@ -718,7 +717,7 @@ class __InfoAreaWidgetState extends State<_InfoAreaWidget> { TextEditingController text = TextEditingController(); Widget okButton = TextButton( style: TextButton.styleFrom(foregroundColor: Settings.majorColor), - child: Text(Translations.of(context).trans('ok')), + child: Text(Translations.instance!.trans('ok')), onPressed: () async { if ((await EHSession.postComment( 'https://exhentai.org/g/${widget.queryResult.id()}/${widget.queryResult.ehash()}', @@ -734,7 +733,7 @@ class __InfoAreaWidgetState extends State<_InfoAreaWidget> { ); Widget cancelButton = TextButton( style: TextButton.styleFrom(foregroundColor: Settings.majorColor), - child: Text(Translations.of(context).trans('cancel')), + child: Text(Translations.instance!.trans('cancel')), onPressed: () { Navigator.pop(context, false); }, @@ -1002,7 +1001,7 @@ class _Chip extends StatelessWidget { Clipboard.setData(ClipboardData(text: name)); showToast( level: ToastLevel.check, - message: Translations.of(context).trans('copied'), + message: Translations.instance!.trans('copied'), ); } }, @@ -1035,7 +1034,7 @@ class _RelatedArea extends StatelessWidget { () => ArticleListPage( cc: snapshot.data!, name: - '${Translations.of(context).trans('related')} ${Translations.of(context).trans('articles')}'), + '${Translations.instance!.trans('related')} ${Translations.instance!.trans('articles')}'), ), ), ]); @@ -1053,7 +1052,7 @@ class _RelatedArea extends StatelessWidget { child: Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, crossAxisAlignment: CrossAxisAlignment.center, - children: [Text(Translations.of(context).trans('more'))], + children: [Text(Translations.instance!.trans('more'))], ), ), ); diff --git a/violet/lib/pages/artist_info/artist_info_page.dart b/violet/lib/pages/artist_info/artist_info_page.dart index ce87727a4..82d4c552b 100644 --- a/violet/lib/pages/artist_info/artist_info_page.dart +++ b/violet/lib/pages/artist_info/artist_info_page.dart @@ -370,7 +370,7 @@ class _ArtistInfoPageState extends State { showToast( level: ToastLevel.check, message: - '${widget.name}${Translations.of(context).trans(isBookmarked ? 'addtobookmark' : 'removetobookmark')}', + '${widget.name}${Translations.instance!.trans(isBookmarked ? 'addtobookmark' : 'removetobookmark')}', ); if (!isBookmarked) { @@ -490,7 +490,7 @@ class _ArtistInfoPageState extends State { header: Padding( padding: const EdgeInsets.fromLTRB(12, 12, 0, 0), child: Text( - '${Translations.of(context).trans('articles')} (${cc.length})'), + '${Translations.instance!.trans('articles')} (${cc.length})'), ), expanded: Column(children: [ articleArea(), @@ -517,7 +517,7 @@ class _ArtistInfoPageState extends State { header: Padding( padding: const EdgeInsets.fromLTRB(12, 12, 0, 0), child: Text( - '${Translations.of(context).trans('comment')} (${(comments != null ? comments!.length : 0)})'), + '${Translations.instance!.trans('comment')} (${(comments != null ? comments!.length : 0)})'), ), expanded: commentArea(), collapsed: Container(), @@ -538,7 +538,7 @@ class _ArtistInfoPageState extends State { header: Padding( padding: const EdgeInsets.fromLTRB(12, 12, 0, 0), child: Text( - '${Translations.of(context).trans('related')} ${widget.type.isSeries ? Translations.of(context).trans('iseries') : Translations.of(context).trans('icharacter')}'), + '${Translations.instance!.trans('related')} ${widget.type.isSeries ? Translations.instance!.trans('iseries') : Translations.instance!.trans('icharacter')}'), ), expanded: relatedArea(), collapsed: Container(), @@ -560,7 +560,7 @@ class _ArtistInfoPageState extends State { header: Padding( padding: const EdgeInsets.fromLTRB(12, 12, 0, 0), child: Text( - '${Translations.of(context).trans('related')} ${widget.type.isCharacter ? Translations.of(context).trans('iseries') : Translations.of(context).trans('icharacter')}'), + '${Translations.instance!.trans('related')} ${widget.type.isCharacter ? Translations.instance!.trans('iseries') : Translations.instance!.trans('icharacter')}'), ), expanded: relatedSingleArea(), collapsed: Container(), @@ -580,7 +580,7 @@ class _ArtistInfoPageState extends State { header: Padding( padding: const EdgeInsets.fromLTRB(12, 12, 0, 0), child: Text( - '${Translations.of(context).trans('similar')} ${widget.type.isGroup ? Translations.of(context).trans('igroups') : widget.type.isUploader ? Translations.of(context).trans('iuploader') : widget.type.isSeries ? Translations.of(context).trans('iseries') : widget.type.isCharacter ? Translations.of(context).trans('icharacter') : Translations.of(context).trans('iartists')}'), + '${Translations.instance!.trans('similar')} ${widget.type.isGroup ? Translations.instance!.trans('igroups') : widget.type.isUploader ? Translations.instance!.trans('iuploader') : widget.type.isSeries ? Translations.instance!.trans('iseries') : widget.type.isCharacter ? Translations.instance!.trans('icharacter') : Translations.instance!.trans('iartists')}'), ), expanded: similarArea(), collapsed: Container(), @@ -599,7 +599,7 @@ class _ArtistInfoPageState extends State { header: Padding( padding: const EdgeInsets.fromLTRB(12, 12, 0, 0), child: Text( - '${Translations.of(context).trans('series')} (${series.length})'), + '${Translations.instance!.trans('series')} (${series.length})'), ), expanded: seriesArea(), collapsed: Container(), @@ -624,7 +624,7 @@ class _ArtistInfoPageState extends State { child: Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, crossAxisAlignment: CrossAxisAlignment.center, - children: [Text(Translations.of(context).trans('more'))], + children: [Text(Translations.instance!.trans('more'))], ), ), ); @@ -710,7 +710,7 @@ class _ArtistInfoPageState extends State { title: ' ${e.item1} (${HitomiManager.getArticleCount(widget.type.name, e.item1).toString()})', count: - '${Translations.of(context).trans('score')}: ${e.item2.toStringAsFixed(1)} ', + '${Translations.instance!.trans('score')}: ${e.item2.toStringAsFixed(1)} ', articles: qq, ); }, @@ -800,7 +800,7 @@ class _ArtistInfoPageState extends State { height: 100, child: Align( child: Text( - Translations.of(context).trans('nocomment'), + Translations.instance!.trans('nocomment'), textAlign: TextAlign.center, ), ), @@ -819,11 +819,11 @@ class _ArtistInfoPageState extends State { TextEditingController text = TextEditingController(); Widget okButton = TextButton( style: TextButton.styleFrom(foregroundColor: Settings.majorColor), - child: Text(Translations.of(context).trans('ok')), + child: Text(Translations.instance!.trans('ok')), onPressed: () async { if (text.text.length < 5 || text.text.length > 500) { await showOkDialog(context, 'Comment too short or long!', - Translations.of(context).trans('comment')); + Translations.instance!.trans('comment')); return; } await VioletCommunityAnonymous.postArtistComment( @@ -834,7 +834,7 @@ class _ArtistInfoPageState extends State { ); Widget cancelButton = TextButton( style: TextButton.styleFrom(foregroundColor: Settings.majorColor), - child: Text(Translations.of(context).trans('cancel')), + child: Text(Translations.instance!.trans('cancel')), onPressed: () { Navigator.pop(context, false); }, @@ -844,7 +844,7 @@ class _ArtistInfoPageState extends State { context: context, builder: (BuildContext context) => AlertDialog( contentPadding: const EdgeInsets.fromLTRB(12, 0, 12, 0), - title: Text(Translations.of(context).trans('writecomment')), + title: Text(Translations.instance!.trans('writecomment')), content: TextField( controller: text, autofocus: true, @@ -858,7 +858,7 @@ class _ArtistInfoPageState extends State { title: Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, crossAxisAlignment: CrossAxisAlignment.center, - children: [Text(Translations.of(context).trans('writecomment'))], + children: [Text(Translations.instance!.trans('writecomment'))], ), ), ); @@ -889,7 +889,7 @@ class _ArtistInfoPageState extends State { title: ' ${e.item1} (${HitomiManager.getArticleCount(widget.type.name, e.item1)})', count: - '${Translations.of(context).trans('score')}: ${e.item2.toStringAsFixed(1)} ', + '${Translations.instance!.trans('score')}: ${e.item2.toStringAsFixed(1)} ', articles: qq, ); }, @@ -920,7 +920,7 @@ class _ArtistInfoPageState extends State { title: ' ${e.item1} (${HitomiManager.getArticleCount(widget.type.name, e.item1)})', count: - '${Translations.of(context).trans('score')}: ${e.item2.toStringAsFixed(1)} ', + '${Translations.instance!.trans('score')}: ${e.item2.toStringAsFixed(1)} ', articles: qq, ); }, diff --git a/violet/lib/pages/artist_info/search_type2.dart b/violet/lib/pages/artist_info/search_type2.dart index 0ea99694c..617cc98ef 100644 --- a/violet/lib/pages/artist_info/search_type2.dart +++ b/violet/lib/pages/artist_info/search_type2.dart @@ -56,7 +56,7 @@ class SearchType2 extends StatelessWidget { children: [ ListTile( leading: Icon(Icons.grid_on, color: getColor(0)), - title: Text(Translations.of(context).trans('srt0'), + title: Text(Translations.instance!.trans('srt0'), style: TextStyle(color: getColor(0))), onTap: () async { Navigator.pop(context, 0); @@ -64,7 +64,7 @@ class SearchType2 extends StatelessWidget { ), ListTile( leading: Icon(MdiIcons.gridLarge, color: getColor(1)), - title: Text(Translations.of(context).trans('srt1'), + title: Text(Translations.instance!.trans('srt1'), style: TextStyle(color: getColor(1))), onTap: () async { Navigator.pop(context, 1); @@ -74,7 +74,7 @@ class SearchType2 extends StatelessWidget { leading: Icon(MdiIcons.viewAgendaOutline, color: getColor(2)), title: Text( - Translations.of(context).trans('srt2'), + Translations.instance!.trans('srt2'), style: TextStyle(color: getColor(2)), ), onTap: () async { @@ -85,7 +85,7 @@ class SearchType2 extends StatelessWidget { leading: Icon(MdiIcons.formatListText, color: getColor(3)), title: Text( - Translations.of(context).trans('srt3'), + Translations.instance!.trans('srt3'), style: TextStyle(color: getColor(3)), ), onTap: () async { @@ -98,7 +98,7 @@ class SearchType2 extends StatelessWidget { child: Icon(MdiIcons.viewSplitVertical, color: getColor(4))), title: Text( - Translations.of(context).trans('srt4'), + Translations.instance!.trans('srt4'), style: TextStyle(color: getColor(4)), ), onTap: () async { diff --git a/violet/lib/pages/artist_info/similar_list_page.dart b/violet/lib/pages/artist_info/similar_list_page.dart index 284b89e39..93987add6 100644 --- a/violet/lib/pages/artist_info/similar_list_page.dart +++ b/violet/lib/pages/artist_info/similar_list_page.dart @@ -99,7 +99,7 @@ class SimilarListPage extends StatelessWidget { title: ' ${e.item1} (${HitomiManager.getArticleCount(type.name, e.item1)})', count: - '${Translations.of(context).trans('score')}: ${e.item2.toStringAsFixed(1)} ', + '${Translations.instance!.trans('score')}: ${e.item2.toStringAsFixed(1)} ', articles: snapshot.data!, ); }, diff --git a/violet/lib/pages/bookmark/bookmark_page.dart b/violet/lib/pages/bookmark/bookmark_page.dart index 79357f782..5460c34d6 100644 --- a/violet/lib/pages/bookmark/bookmark_page.dart +++ b/violet/lib/pages/bookmark/bookmark_page.dart @@ -179,12 +179,12 @@ class _BookmarkPageState extends ThemeSwitchableState int id; if (index == -2) { - name = Translations.of(context).trans('readrecord'); - desc = Translations.of(context).trans('readrecorddesc'); + name = Translations.instance!.trans('readrecord'); + desc = Translations.instance!.trans('readrecorddesc'); id = -2; } else if (index == -1) { - name = Translations.of(context).trans('cropbookmark'); - desc = Translations.of(context).trans('cropbookmarkdesc'); + name = Translations.instance!.trans('cropbookmark'); + desc = Translations.instance!.trans('cropbookmarkdesc'); id = -1; } else { name = data!.name(); @@ -195,8 +195,8 @@ class _BookmarkPageState extends ThemeSwitchableState } if (name == 'violet_default') { - name = Translations.of(context).trans('unclassified'); - desc = Translations.of(context).trans('unclassifieddesc'); + name = Translations.instance!.trans('unclassified'); + desc = Translations.instance!.trans('unclassifieddesc'); } final random = Random(); @@ -273,8 +273,8 @@ class _BookmarkPageState extends ThemeSwitchableState if (index < 0 || (oname == 'violet_default' && index == 0)) { await showOkDialog( context, - Translations.of(context).trans('cannotmodifydefaultgroup'), - Translations.of(context).trans('bookmark')); + Translations.instance!.trans('cannotmodifydefaultgroup'), + Translations.instance!.trans('bookmark')); return; } diff --git a/violet/lib/pages/bookmark/group/group_article_list_page.dart b/violet/lib/pages/bookmark/group/group_article_list_page.dart index c014c7194..ca1df8278 100644 --- a/violet/lib/pages/bookmark/group/group_article_list_page.dart +++ b/violet/lib/pages/bookmark/group/group_article_list_page.dart @@ -249,10 +249,10 @@ class _GroupArticleListPageState extends State { onPressed: () async { if (await showYesNoDialog( context, - Translations.of(context) + Translations.instance! .trans('deletebookmarkmsg') .replaceAll('%s', checked.length.toString()), - Translations.of(context).trans('bookmark'))) { + Translations.instance!.trans('bookmark'))) { var bookmark = await Bookmark.getInstance(); for (var element in checked) { await bookmark.unbookmark(element); @@ -553,13 +553,13 @@ class _GroupArticleListPageState extends State { if (await showDialog( context: context, builder: (BuildContext context) => AlertDialog( - title: Text(Translations.of(context).trans('wheretomove')), + title: Text(Translations.instance!.trans('wheretomove')), actions: [ ElevatedButton( style: ElevatedButton.styleFrom( backgroundColor: Settings.majorColor, ), - child: Text(Translations.of(context).trans('cancel')), + child: Text(Translations.instance!.trans('cancel')), onPressed: () { Navigator.pop(context, 0); }, diff --git a/violet/lib/pages/bookmark/group/group_artist_list.dart b/violet/lib/pages/bookmark/group/group_artist_list.dart index 600495ad1..d89e85e7a 100644 --- a/violet/lib/pages/bookmark/group/group_artist_list.dart +++ b/violet/lib/pages/bookmark/group/group_artist_list.dart @@ -343,10 +343,10 @@ class _GroupArtistListState extends State onPressed: () async { if (await showYesNoDialog( context, - Translations.of(context) + Translations.instance! .trans('deletebookmarkmsg') .replaceAll('%s', checked.length.toString()), - Translations.of(context).trans('bookmark'))) { + Translations.instance!.trans('bookmark'))) { var bookmark = await Bookmark.getInstance(); for (var element in checked) { await bookmark.unbookmarkArtist(element.$2, element.$1); @@ -433,13 +433,13 @@ class _GroupArtistListState extends State if (await showDialog( context: context, builder: (BuildContext context) => AlertDialog( - title: Text(Translations.of(context).trans('wheretomove')), + title: Text(Translations.instance!.trans('wheretomove')), actions: [ ElevatedButton( style: ElevatedButton.styleFrom( backgroundColor: Settings.majorColor, ), - child: Text(Translations.of(context).trans('cancel')), + child: Text(Translations.instance!.trans('cancel')), onPressed: () { Navigator.pop(context, 0); }, diff --git a/violet/lib/pages/bookmark/group_modify.dart b/violet/lib/pages/bookmark/group_modify.dart index 9bb79a050..3a709eecb 100644 --- a/violet/lib/pages/bookmark/group_modify.dart +++ b/violet/lib/pages/bookmark/group_modify.dart @@ -35,13 +35,13 @@ class _GroupModifyPageState extends State { @override Widget build(BuildContext context) { return AlertDialog( - title: Text(Translations.of(context).trans('modifygroupinfo')), + title: Text(Translations.instance!.trans('modifygroupinfo')), contentPadding: const EdgeInsets.fromLTRB(12, 8, 12, 8), content: Column( mainAxisSize: MainAxisSize.min, children: [ Row(children: [ - Text('${Translations.of(context).trans('name')}: '), + Text('${Translations.instance!.trans('name')}: '), Expanded( child: TextField( controller: _nameController, @@ -49,7 +49,7 @@ class _GroupModifyPageState extends State { ), ]), Row(children: [ - Text('${Translations.of(context).trans('desc')}: '), + Text('${Translations.instance!.trans('desc')}: '), Expanded( child: TextField( controller: _descController, @@ -65,12 +65,12 @@ class _GroupModifyPageState extends State { style: ElevatedButton.styleFrom( backgroundColor: Colors.red, ), - child: Text(Translations.of(context).trans('delete')), + child: Text(Translations.instance!.trans('delete')), onPressed: () async { if (await showYesNoDialog( context, - Translations.of(context).trans('deletegroupmsg'), - Translations.of(context).trans('bookmark'))) { + Translations.instance!.trans('deletegroupmsg'), + Translations.instance!.trans('bookmark'))) { if (!context.mounted) return; Navigator.pop(context, [2]); } @@ -81,7 +81,7 @@ class _GroupModifyPageState extends State { style: ElevatedButton.styleFrom( backgroundColor: Settings.majorColor, ), - child: Text(Translations.of(context).trans('ok')), + child: Text(Translations.instance!.trans('ok')), onPressed: () { Navigator.pop(context, [ 1, @@ -95,7 +95,7 @@ class _GroupModifyPageState extends State { style: ElevatedButton.styleFrom( backgroundColor: Settings.majorColor, ), - child: Text(Translations.of(context).trans('cancel')), + child: Text(Translations.instance!.trans('cancel')), onPressed: () { Navigator.pop(context, [0]); }, diff --git a/violet/lib/pages/bookmark/record_view_page.dart b/violet/lib/pages/bookmark/record_view_page.dart index 71fd40306..800ca93f3 100644 --- a/violet/lib/pages/bookmark/record_view_page.dart +++ b/violet/lib/pages/bookmark/record_view_page.dart @@ -157,7 +157,7 @@ class RecordViewPage extends StatelessWidget { // ), // Text( // xx.lastPage().toString() + - // ' ${Translations.of(context).trans('readpage')} ', + // ' ${Translations.instance!.trans('readpage')} ', // style: TextStyle( // color: Settings.themeWhat // ? Colors.grey.shade300 diff --git a/violet/lib/pages/community/user_status_card.dart b/violet/lib/pages/community/user_status_card.dart index 8834d468c..8ec98e987 100644 --- a/violet/lib/pages/community/user_status_card.dart +++ b/violet/lib/pages/community/user_status_card.dart @@ -183,8 +183,8 @@ class _UserStatusCardState extends ThemeSwitchableState onTap: () async { await showOkDialog( context, - '$_userAppId\n\n${Translations.of(context).trans('userappmsg')}', - Translations.of(context).trans('uruserappid')); + '$_userAppId\n\n${Translations.instance!.trans('userappmsg')}', + Translations.instance!.trans('uruserappid')); }, ), ), diff --git a/violet/lib/pages/database_download/database_download_page.dart b/violet/lib/pages/database_download/database_download_page.dart index 5cbedbe37..841f93dca 100644 --- a/violet/lib/pages/database_download/database_download_page.dart +++ b/violet/lib/pages/database_download/database_download_page.dart @@ -446,11 +446,11 @@ class DataBaseDownloadPageState extends State { @override Widget build(BuildContext context) { if (baseString == '') { - baseString = Translations.of(context).trans('dbdwaitforrequest'); + baseString = Translations.instance!.trans('dbdwaitforrequest'); } return Scaffold( appBar: AppBar( - title: Text(Translations.of(context).trans('dbdname')), + title: Text(Translations.instance!.trans('dbdname')), backgroundColor: Colors.purple, ), body: Center( @@ -468,7 +468,7 @@ class DataBaseDownloadPageState extends State { height: 20.0, ), Text( - "${Translations.of(context).trans('dbddownloading')} $progressString", + "${Translations.instance!.trans('dbddownloading')} $progressString", style: const TextStyle( color: Colors.white, ), diff --git a/violet/lib/pages/download/download_align_type.dart b/violet/lib/pages/download/download_align_type.dart index 931afcd40..03d8c5e04 100644 --- a/violet/lib/pages/download/download_align_type.dart +++ b/violet/lib/pages/download/download_align_type.dart @@ -36,15 +36,15 @@ class DownloadAlignType extends StatelessWidget { child: Column( children: [ _typeItem(context, MdiIcons.clipboardListOutline, - Translations.of(context).trans('alignnone'), 0), + Translations.instance!.trans('alignnone'), 0), _typeItem(context, MdiIcons.accountOutline, - Translations.of(context).trans('alignartist'), 1), + Translations.instance!.trans('alignartist'), 1), _typeItem(context, MdiIcons.accountMultipleOutline, - Translations.of(context).trans('aligngroup'), 2), + Translations.instance!.trans('aligngroup'), 2), _typeItem(context, MdiIcons.fileOutline, - Translations.of(context).trans('alignpage'), 3), + Translations.instance!.trans('alignpage'), 3), _typeItem(context, MdiIcons.calendarClockOutline, - Translations.of(context).trans('alignrecentread'), 4), + Translations.instance!.trans('alignrecentread'), 4), ], ), ), diff --git a/violet/lib/pages/download/download_item_menu.dart b/violet/lib/pages/download/download_item_menu.dart index 42e5e2962..82bd1c36c 100644 --- a/violet/lib/pages/download/download_item_menu.dart +++ b/violet/lib/pages/download/download_item_menu.dart @@ -73,7 +73,7 @@ class DownloadImageMenu extends StatelessWidget { BuildContext context, IconData icon, String text, int selection) { return ListTile( leading: Icon(icon, color: getColor(selection)), - title: Text(text, //Translations.of(context).trans(text), + title: Text(text, //Translations.instance!.trans(text), style: TextStyle(color: getColor(selection))), onTap: () async { Navigator.pop(context, selection); diff --git a/violet/lib/pages/download/download_page.dart b/violet/lib/pages/download/download_page.dart index f684915c6..e409e84db 100644 --- a/violet/lib/pages/download/download_page.dart +++ b/violet/lib/pages/download/download_page.dart @@ -735,7 +735,7 @@ class _DownloadPageState extends ThemeSwitchableState disabledBorder: InputBorder.none, contentPadding: const EdgeInsets.only( left: 15, bottom: 11, top: 11, right: 15), - hintText: Translations.of(context).trans('addurl')), + hintText: Translations.instance!.trans('addurl')), ), leading: const SizedBox( width: 25, @@ -769,7 +769,7 @@ class _DownloadPageState extends ThemeSwitchableState Widget yesButton = TextButton( style: TextButton.styleFrom( foregroundColor: Settings.majorColor), - child: Text(Translations.of(context).trans('ok')), + child: Text(Translations.instance!.trans('ok')), onPressed: () { Navigator.pop(context, true); }, @@ -777,7 +777,7 @@ class _DownloadPageState extends ThemeSwitchableState Widget noButton = TextButton( style: TextButton.styleFrom( foregroundColor: Settings.majorColor), - child: Text(Translations.of(context).trans('cancel')), + child: Text(Translations.instance!.trans('cancel')), onPressed: () { Navigator.pop(context, false); }, @@ -789,8 +789,7 @@ class _DownloadPageState extends ThemeSwitchableState builder: (BuildContext context) => AlertDialog( contentPadding: const EdgeInsets.fromLTRB(12, 0, 12, 0), - title: - Text(Translations.of(context).trans('writeurl')), + title: Text(Translations.instance!.trans('writeurl')), content: TextField( controller: text, autofocus: true, diff --git a/violet/lib/pages/download/download_view_type.dart b/violet/lib/pages/download/download_view_type.dart index 30ad4dc38..4fc1036de 100644 --- a/violet/lib/pages/download/download_view_type.dart +++ b/violet/lib/pages/download/download_view_type.dart @@ -57,7 +57,7 @@ class DownloadViewType extends StatelessWidget { DownloadResultType selection) { return ListTile( leading: Icon(icon, color: getColor(selection)), - title: Text(Translations.of(context).trans(text), + title: Text(Translations.instance!.trans(text), softWrap: false, style: TextStyle(color: getColor(selection))), onTap: () async { await Settings.setDownloadResultType(selection); diff --git a/violet/lib/pages/lock/lock_screen.dart b/violet/lib/pages/lock/lock_screen.dart index eeb984849..255d00cf4 100644 --- a/violet/lib/pages/lock/lock_screen.dart +++ b/violet/lib/pages/lock/lock_screen.dart @@ -45,14 +45,14 @@ class _LockScreenState extends State with TickerProviderStateMixin { super.didChangeDependencies(); _message ??= widget.isRegisterMode - ? Translations.of(context).trans('insertpinforregister') - : Translations.of(context).trans('insertpinforcheck'); + ? Translations.instance!.trans('insertpinforregister') + : Translations.instance!.trans('insertpinforcheck'); } @override Widget build(BuildContext context) { final header = Text( - Translations.of(context).trans('pinauth'), + Translations.instance!.trans('pinauth'), style: const TextStyle( fontWeight: FontWeight.bold, fontSize: 20.0, @@ -79,7 +79,7 @@ class _LockScreenState extends State with TickerProviderStateMixin { child: GestureDetector( onTap: _passwordMissing, child: Text.rich(TextSpan( - text: Translations.of(context).trans('missingpass'), + text: Translations.instance!.trans('missingpass'), style: const TextStyle( color: Colors.blue, decoration: TextDecoration.underline, @@ -231,7 +231,7 @@ class _LockScreenState extends State with TickerProviderStateMixin { Future _passwordMissing() async { final Widget yesButton = TextButton( style: TextButton.styleFrom(foregroundColor: Settings.majorColor), - child: Text(Translations.of(context).trans('ok')), + child: Text(Translations.instance!.trans('ok')), onPressed: () { Navigator.pop(context, true); }, @@ -239,7 +239,7 @@ class _LockScreenState extends State with TickerProviderStateMixin { final Widget noButton = TextButton( style: TextButton.styleFrom(foregroundColor: Settings.majorColor), - child: Text(Translations.of(context).trans('cancel')), + child: Text(Translations.instance!.trans('cancel')), onPressed: () { Navigator.pop(context, false); }, @@ -252,7 +252,7 @@ class _LockScreenState extends State with TickerProviderStateMixin { context: context, builder: (BuildContext context) => AlertDialog( contentPadding: const EdgeInsets.fromLTRB(12, 0, 12, 0), - title: Text(Translations.of(context).trans('entersecondpass')), + title: Text(Translations.instance!.trans('entersecondpass')), content: TextField( controller: text, autofocus: true, @@ -265,7 +265,7 @@ class _LockScreenState extends State with TickerProviderStateMixin { if (text.text == 'violet.jjang') { if (!mounted) return; await showOkDialog(context, Translations.instance!.trans('resetpin'), - Translations.of(context).trans('authmanager')); + Translations.instance!.trans('authmanager')); if (!mounted) return; Navigator.pushReplacementNamed(context, '/SplashPage'); @@ -323,7 +323,7 @@ class _LockScreenState extends State with TickerProviderStateMixin { _controller.reverse(); _pin = List.filled(4, null); setState(() { - _message = Translations.of(context).trans('pinisnotcorrect'); + _message = Translations.instance!.trans('pinisnotcorrect'); }); }); } @@ -333,7 +333,7 @@ class _LockScreenState extends State with TickerProviderStateMixin { Future.delayed(const Duration(milliseconds: 300)).then((value) { showToast( level: ToastLevel.check, - message: Translations.of(context).trans('pinisregistered'), + message: Translations.instance!.trans('pinisregistered'), ); Navigator.pop(context); }); @@ -343,7 +343,7 @@ class _LockScreenState extends State with TickerProviderStateMixin { _isFirstPINInserted = true; _firstPIN = _pin.join(); _pin = List.filled(4, null); - _message = Translations.of(context).trans('retrypin'); + _message = Translations.instance!.trans('retrypin'); Future.delayed(const Duration(milliseconds: 300)).then((value) { setState(() {}); }); diff --git a/violet/lib/pages/main/artist_collection/artist_collection_page.dart b/violet/lib/pages/main/artist_collection/artist_collection_page.dart index 72b493028..407e023ba 100644 --- a/violet/lib/pages/main/artist_collection/artist_collection_page.dart +++ b/violet/lib/pages/main/artist_collection/artist_collection_page.dart @@ -35,9 +35,9 @@ class _ArtistCollectionPageState extends State { var name = item.key['default']; if (item.key.containsKey( - Translations.of(context).dbLanguageCode.split('_')[0])) { + Translations.instance!.dbLanguageCode.split('_')[0])) { name = - item.key[Translations.of(context).dbLanguageCode.split('_')[0]]; + item.key[Translations.instance!.dbLanguageCode.split('_')[0]]; } final artists = diff --git a/violet/lib/pages/main/card/artist_collection_card.dart b/violet/lib/pages/main/card/artist_collection_card.dart index ba5bc802e..80765c52c 100644 --- a/violet/lib/pages/main/card/artist_collection_card.dart +++ b/violet/lib/pages/main/card/artist_collection_card.dart @@ -84,7 +84,7 @@ class _ArtistCollectionCarddState extends State // // ), // ), Text( - Translations.of(context).trans('artistcollection'), + Translations.instance!.trans('artistcollection'), style: const TextStyle( // fontFamily: "Calibre-Semibold", // fontSize: 18, diff --git a/violet/lib/pages/main/card/update_log_card.dart b/violet/lib/pages/main/card/update_log_card.dart index 79896b5d7..9df37788c 100644 --- a/violet/lib/pages/main/card/update_log_card.dart +++ b/violet/lib/pages/main/card/update_log_card.dart @@ -69,7 +69,7 @@ class _UpdateLogCardState extends State mainAxisAlignment: MainAxisAlignment.center, children: [ Text( - Translations.of(context).trans('patchnote'), + Translations.instance!.trans('patchnote'), style: const TextStyle(color: Colors.white), ), ]), diff --git a/violet/lib/pages/main/card/views_card.dart b/violet/lib/pages/main/card/views_card.dart index 3e8457ff8..721ab0760 100644 --- a/violet/lib/pages/main/card/views_card.dart +++ b/violet/lib/pages/main/card/views_card.dart @@ -96,7 +96,7 @@ class _ViewsCardState extends State with TickerProviderStateMixin { // // ), // ), Text( - Translations.of(context).trans('realtimebest'), + Translations.instance!.trans('realtimebest'), style: const TextStyle(color: Colors.white), ), ]), diff --git a/violet/lib/pages/main/info/lab/artist_search/artist_search.dart b/violet/lib/pages/main/info/lab/artist_search/artist_search.dart index 4cb1fa62a..8e1025364 100644 --- a/violet/lib/pages/main/info/lab/artist_search/artist_search.dart +++ b/violet/lib/pages/main/info/lab/artist_search/artist_search.dart @@ -272,7 +272,7 @@ class _ArtistSearchState extends State { title: ' ${e.item1} (${HitomiManager.getArticleCount(selectedType.name, e.item1)})', count: - '${Translations.of(context).trans('score')}: ${e.item2.toStringAsFixed(1)} ', + '${Translations.instance!.trans('score')}: ${e.item2.toStringAsFixed(1)} ', articles: snapshot.data!, ); }, diff --git a/violet/lib/pages/main/info/lab/artist_search/tag_group_modify.dart b/violet/lib/pages/main/info/lab/artist_search/tag_group_modify.dart index a6328de70..369376f62 100644 --- a/violet/lib/pages/main/info/lab/artist_search/tag_group_modify.dart +++ b/violet/lib/pages/main/info/lab/artist_search/tag_group_modify.dart @@ -163,7 +163,7 @@ class _TagGroupItem extends StatelessWidget { Widget okButton = TextButton( style: TextButton.styleFrom(foregroundColor: Settings.majorColor), - child: Text(trans.Translations.of(context).trans('ok')), + child: Text(trans.Translations.instance!.trans('ok')), onPressed: () { Navigator.pop(context, true); }, @@ -171,7 +171,7 @@ class _TagGroupItem extends StatelessWidget { Widget cancelButton = TextButton( style: TextButton.styleFrom(foregroundColor: Settings.majorColor), - child: Text(trans.Translations.of(context).trans('cancel')), + child: Text(trans.Translations.instance!.trans('cancel')), onPressed: () { Navigator.pop(context, false); }, diff --git a/violet/lib/pages/main/info/lab/bookmark/bookmarks.dart b/violet/lib/pages/main/info/lab/bookmark/bookmarks.dart index b2d03074e..c0503df85 100644 --- a/violet/lib/pages/main/info/lab/bookmark/bookmarks.dart +++ b/violet/lib/pages/main/info/lab/bookmark/bookmarks.dart @@ -94,8 +94,8 @@ class _BookmarkPageState extends State { int id; if (index == -1) { - name = Translations.of(context).trans('readrecord'); - desc = Translations.of(context).trans('readrecorddesc'); + name = Translations.instance!.trans('readrecord'); + desc = Translations.instance!.trans('readrecorddesc'); id = -1; } else { name = data!.name(); @@ -105,8 +105,8 @@ class _BookmarkPageState extends State { } if (name == 'violet_default') { - name = Translations.of(context).trans('unclassified'); - desc = Translations.of(context).trans('unclassifieddesc'); + name = Translations.instance!.trans('unclassified'); + desc = Translations.instance!.trans('unclassifieddesc'); } return Container( diff --git a/violet/lib/pages/main/info/lab/global_comments.dart b/violet/lib/pages/main/info/lab/global_comments.dart index 91474937b..3c32953fd 100644 --- a/violet/lib/pages/main/info/lab/global_comments.dart +++ b/violet/lib/pages/main/info/lab/global_comments.dart @@ -161,7 +161,7 @@ class _LabGlobalCommentsState extends State { onPressed: () async { if (text.text.length < 5 || text.text.length > 500) { await showOkDialog(context, '너무 짧아요!', - Translations.of(context).trans('comment')); + Translations.instance!.trans('comment')); return; } if (!modReply) { diff --git a/violet/lib/pages/main/info/lab_page.dart b/violet/lib/pages/main/info/lab_page.dart index d52661c89..796278c29 100644 --- a/violet/lib/pages/main/info/lab_page.dart +++ b/violet/lib/pages/main/info/lab_page.dart @@ -191,7 +191,7 @@ class _LaboratoryPageState extends State { Widget yesButton = TextButton( style: TextButton.styleFrom( foregroundColor: Settings.majorColor), - child: Text(Translations.of(context).trans('ok')), + child: Text(Translations.instance!.trans('ok')), onPressed: () { Navigator.pop(context, true); }, @@ -199,7 +199,7 @@ class _LaboratoryPageState extends State { Widget noButton = TextButton( style: TextButton.styleFrom( foregroundColor: Settings.majorColor), - child: Text(Translations.of(context).trans('cancel')), + child: Text(Translations.instance!.trans('cancel')), onPressed: () { Navigator.pop(context, false); }, diff --git a/violet/lib/pages/main/info/violet_page.dart b/violet/lib/pages/main/info/violet_page.dart index 41fc397a4..0f584beea 100644 --- a/violet/lib/pages/main/info/violet_page.dart +++ b/violet/lib/pages/main/info/violet_page.dart @@ -56,7 +56,7 @@ class VioletPage extends StatelessWidget { Text( 'Violet은 강력한 검색기능 및 분석기능을 통해 사용자에게 다양한 경험을 제공하는 뷰어입니다.' ' Violet이 제공하는 편리하고도 강력한 기능들을 체험해보세요!', - // Translations.of(context).trans('infomessage'), + // Translations.instance!.trans('infomessage'), textAlign: TextAlign.center, style: TextStyle(fontSize: 11), ), diff --git a/violet/lib/pages/main/main_page.dart b/violet/lib/pages/main/main_page.dart index a00be3775..0f550cd6d 100644 --- a/violet/lib/pages/main/main_page.dart +++ b/violet/lib/pages/main/main_page.dart @@ -113,26 +113,26 @@ class _MainPageState extends ThemeSwitchableState uri: _discordUri, backgroundColor: const Color(0xFF7189da), icon: const Icon(MdiIcons.discord), - label: Text(Translations.of(context).trans('maindiscord')), + label: Text(Translations.instance!.trans('maindiscord')), ), CarouselButton( uri: _contactUri, backgroundColor: Colors.redAccent, icon: const Icon(MdiIcons.gmail), - label: Text(Translations.of(context).trans('maincontact')), + label: Text(Translations.instance!.trans('maincontact')), ), CarouselButton( uri: _gitHubUri, backgroundColor: const Color(0xFF24292E), icon: const Icon(MdiIcons.github), - label: Text(Translations.of(context).trans('maingithub')), + label: Text(Translations.instance!.trans('maingithub')), ), ]; final groups = [ Container(height: 16), _BuildGroupWidget( - name: Translations.of(context).trans('userstat'), + name: Translations.instance!.trans('userstat'), content: const _StatAreaWidget(), ), CarouselSlider( @@ -188,11 +188,11 @@ class _MainPageState extends ThemeSwitchableState }).toList(), ), _BuildGroupWidget( - name: Translations.of(context).trans('versionmanagement'), + name: Translations.instance!.trans('versionmanagement'), content: const _VersionAreaWidget(), ), _BuildGroupWidget( - name: Translations.of(context).trans('service'), + name: Translations.instance!.trans('service'), content: const _ServiceAreaWidget(), ), Container(height: 32), @@ -223,7 +223,7 @@ class _MainPageState extends ThemeSwitchableState Future.delayed(const Duration(milliseconds: 100)).then((value) async { if (UpdateSyncManager.updateRequire) { var bb = await showYesNoDialog(context, - '${Translations.of(context).trans('newupdate')} ${UpdateSyncManager.updateMessage} ${Translations.of(context).trans('wouldyouupdate')}'); + '${Translations.instance!.trans('newupdate')} ${UpdateSyncManager.updateMessage} ${Translations.instance!.trans('wouldyouupdate')}'); if (bb == false) return; } else { return; @@ -340,7 +340,7 @@ class _VersionAreaWidgetState extends State<_VersionAreaWidget> { children: [ Row( children: [ - Text(Translations.of(context).trans('curversion'), + Text(Translations.instance!.trans('curversion'), style: const TextStyle(color: Colors.grey)), const Text( ' ${UpdateSyncManager.majorVersion}.${UpdateSyncManager.minorVersion}.${UpdateSyncManager.patchVersion}'), @@ -350,14 +350,14 @@ class _VersionAreaWidgetState extends State<_VersionAreaWidget> { ' ${UpdateSyncManager.latestVersion}' ? Row( children: [ - Text(Translations.of(context).trans('latestversion'), + Text(Translations.instance!.trans('latestversion'), style: const TextStyle(color: Colors.grey)), Text(' ${UpdateSyncManager.latestVersion}'), ], ) : Row( children: [ - Text(Translations.of(context).trans('curlatestversion'), + Text(Translations.instance!.trans('curlatestversion'), style: const TextStyle(color: Colors.grey)), ], ), @@ -374,14 +374,14 @@ class _VersionAreaWidgetState extends State<_VersionAreaWidget> { onPressed: () { PlatformNavigator.navigateSlide(context, const PatchNotePage()); }, - child: Text(Translations.of(context).trans('patchnote')), + child: Text(Translations.instance!.trans('patchnote')), ), ), ], ); var databaseInfo = Row( children: [ - Text(Translations.of(context).trans('database'), + Text(Translations.instance!.trans('database'), style: const TextStyle(fontWeight: FontWeight.bold)), Expanded(child: Container()), Column( @@ -390,7 +390,7 @@ class _VersionAreaWidgetState extends State<_VersionAreaWidget> { Row( mainAxisAlignment: MainAxisAlignment.center, children: [ - Text(Translations.of(context).trans('local'), + Text(Translations.instance!.trans('local'), style: const TextStyle(color: Colors.grey)), FutureBuilder( future: SharedPreferences.getInstance(), @@ -408,7 +408,7 @@ class _VersionAreaWidgetState extends State<_VersionAreaWidget> { Row( mainAxisAlignment: MainAxisAlignment.center, children: [ - Text(Translations.of(context).trans('latest'), + Text(Translations.instance!.trans('latest'), style: const TextStyle(color: Colors.grey)), Text( ' ${DateFormat('yyyy.MM.dd').format(SyncManager.getLatestDB().getDateTime())}', @@ -445,8 +445,8 @@ class _VersionAreaWidgetState extends State<_VersionAreaWidget> { switching: true, ))); }, - child: Text( - ' ${Translations.of(context).trans('switching')} '), + child: + Text(' ${Translations.instance!.trans('switching')} '), ), badges.Badge( showBadge: syncAvailable, @@ -458,8 +458,7 @@ class _VersionAreaWidgetState extends State<_VersionAreaWidget> { backgroundColor: Settings.majorColor.withAlpha(220), ), onPressed: _onSyncPressed, - child: - Text(' ${Translations.of(context).trans('sync')} '), + child: Text(' ${Translations.instance!.trans('sync')} '), ), ), ], @@ -512,7 +511,7 @@ class _VersionAreaWidgetState extends State<_VersionAreaWidget> { if (!mounted) return; showToast( level: ToastLevel.check, - message: Translations.of(context).trans('synccomplete'), + message: Translations.instance!.trans('synccomplete'), ); }); } @@ -534,7 +533,7 @@ class _StatAreaWidget extends StatelessWidget { children: [ Column( children: [ - Text(Translations.of(context).trans('readpresent')), + Text(Translations.instance!.trans('readpresent')), Container(height: 8), FutureBuilder(future: Future.sync( () async { @@ -555,7 +554,7 @@ class _StatAreaWidget extends StatelessWidget { ), Column( children: [ - Text(Translations.of(context).trans('bookmark')), + Text(Translations.instance!.trans('bookmark')), Container(height: 8), FutureBuilder(future: Future.sync( () async { @@ -576,7 +575,7 @@ class _StatAreaWidget extends StatelessWidget { ), Column( children: [ - Text(Translations.of(context).trans('download')), + Text(Translations.instance!.trans('download')), Container(height: 8), FutureBuilder(future: Future.sync( () async { diff --git a/violet/lib/pages/main/views/views_page.dart b/violet/lib/pages/main/views/views_page.dart index 3e73e3daa..cf1a10a71 100644 --- a/violet/lib/pages/main/views/views_page.dart +++ b/violet/lib/pages/main/views/views_page.dart @@ -51,7 +51,7 @@ class _ViewsPageState extends State with TickerProviderStateMixin { Container(height: 4), Icon(Icons.star, color: Settings.themeWhat ? null : Colors.black), - Text(Translations.of(context).trans('daily'), + Text(Translations.instance!.trans('daily'), style: Settings.themeWhat ? null : const TextStyle(color: Colors.black)), @@ -66,7 +66,7 @@ class _ViewsPageState extends State with TickerProviderStateMixin { Container(height: 4), Icon(MdiIcons.calendarWeek, color: Settings.themeWhat ? null : Colors.black), - Text(Translations.of(context).trans('weekly'), + Text(Translations.instance!.trans('weekly'), style: Settings.themeWhat ? null : const TextStyle(color: Colors.black)), @@ -81,7 +81,7 @@ class _ViewsPageState extends State with TickerProviderStateMixin { Container(height: 4), Icon(MdiIcons.calendarMonth, color: Settings.themeWhat ? null : Colors.black), - Text(Translations.of(context).trans('monthly'), + Text(Translations.instance!.trans('monthly'), style: Settings.themeWhat ? null : const TextStyle(color: Colors.black)), @@ -96,7 +96,7 @@ class _ViewsPageState extends State with TickerProviderStateMixin { Container(height: 4), Icon(MdiIcons.heart, color: Settings.themeWhat ? null : Colors.black), - Text(Translations.of(context).trans('alltime'), + Text(Translations.instance!.trans('alltime'), style: Settings.themeWhat ? null : const TextStyle(color: Colors.black)), diff --git a/violet/lib/pages/search/search_bar_page.dart b/violet/lib/pages/search/search_bar_page.dart index 46b0eb4de..feb2febac 100644 --- a/violet/lib/pages/search/search_bar_page.dart +++ b/violet/lib/pages/search/search_bar_page.dart @@ -198,7 +198,7 @@ class _SearchBarPageState extends State ), contentPadding: const EdgeInsets.only(left: 15, bottom: 11, top: 11, right: 15), - hintText: Translations.of(context).trans('search'), + hintText: Translations.instance!.trans('search'), ), ), leading: Container( @@ -231,7 +231,7 @@ class _SearchBarPageState extends State style: ElevatedButton.styleFrom( backgroundColor: Settings.majorColor, ), - child: Text(Translations.of(context).trans('search')), + child: Text(Translations.instance!.trans('search')), onPressed: () async { var search = _searchController.text; if (search.split(' ').any((x) => x == 'random')) { @@ -289,8 +289,8 @@ class _SearchBarPageState extends State if (_searchLists.isEmpty || _nothing) { return Center( child: Text(_nothing - ? Translations.of(context).trans('nosearchresult') - : Translations.of(context).trans('inputsearchtoken'))); + ? Translations.instance!.trans('nosearchresult') + : Translations.instance!.trans('inputsearchtoken'))); } return ListView( padding: const EdgeInsets.symmetric(horizontal: 8), @@ -308,7 +308,7 @@ class _SearchBarPageState extends State _searchRelatedPanel() { if (_relatedLists.isEmpty) { return Center( - child: Text(Translations.of(context).trans('nosearchresult'))); + child: Text(Translations.instance!.trans('nosearchresult'))); } return ListView( padding: const EdgeInsets.symmetric(horizontal: 8), @@ -386,8 +386,8 @@ class _SearchBarPageState extends State ListTile( leading: Icon(Icons.translate, color: Settings.majorColor), - title: Text( - Translations.of(context).trans('tagtranslation')), + title: + Text(Translations.instance!.trans('tagtranslation')), trailing: Switch( value: Settings.searchTagTranslation, onChanged: (newValue) async { @@ -443,7 +443,7 @@ class _SearchBarPageState extends State ), ListTile( leading: Icon(MdiIcons.counter, color: Settings.majorColor), - title: Text(Translations.of(context).trans('showcount')), + title: Text(Translations.instance!.trans('showcount')), trailing: Switch( value: Settings.searchShowCount, onChanged: (newValue) async { @@ -470,7 +470,7 @@ class _SearchBarPageState extends State ListTile( leading: Icon(MdiIcons.chartBubble, color: Settings.majorColor), - title: Text(Translations.of(context).trans('fuzzysearch')), + title: Text(Translations.instance!.trans('fuzzysearch')), trailing: Switch( value: Settings.searchUseFuzzy, onChanged: (newValue) async { @@ -506,7 +506,7 @@ class _SearchBarPageState extends State // max: 2000.0, // divisions: (2000 - 60) ~/ 30, // label: - // '$_searchResultMaximum${Translations.of(context).trans('tagdisplay')}', + // '$_searchResultMaximum${Translations.instance!.trans('tagdisplay')}', // onChanged: (double value) { // setState(() { // _searchResultMaximum = diff --git a/violet/lib/pages/search/search_page.dart b/violet/lib/pages/search/search_page.dart index f3f6b1710..d473cf649 100644 --- a/violet/lib/pages/search/search_page.dart +++ b/violet/lib/pages/search/search_page.dart @@ -302,11 +302,10 @@ class _SearchPageState extends ThemeSwitchableState } searchBar() { - final searchHintText = - c.latestQuery != null && c.latestQuery!.item2.trim() != '' - ? c.latestQuery!.item2 - : widget.searchKeyWord ?? - trans.Translations.of(context).trans('search'); + final searchHintText = c.latestQuery != null && + c.latestQuery!.item2.trim() != '' + ? c.latestQuery!.item2 + : widget.searchKeyWord ?? trans.Translations.instance!.trans('search'); final textFormField = TextFormField( cursorColor: Colors.black, diff --git a/violet/lib/pages/search/search_page_modify.dart b/violet/lib/pages/search/search_page_modify.dart index b630ced5f..4ccc808b7 100644 --- a/violet/lib/pages/search/search_page_modify.dart +++ b/violet/lib/pages/search/search_page_modify.dart @@ -40,7 +40,7 @@ class _SearchPageModifyPageState extends State { mainAxisSize: MainAxisSize.min, children: [ Row(children: [ - Text('${Translations.of(context).trans('position')}: '), + Text('${Translations.instance!.trans('position')}: '), Expanded( child: TextField( controller: _pageController, @@ -62,7 +62,7 @@ class _SearchPageModifyPageState extends State { style: ElevatedButton.styleFrom( backgroundColor: Settings.majorColor, ), - child: Text(Translations.of(context).trans('ok')), + child: Text(Translations.instance!.trans('ok')), onPressed: () async { if (_pageController.text == '') { Navigator.pop(context, [ @@ -75,7 +75,7 @@ class _SearchPageModifyPageState extends State { widget.maxPage) { await showOkDialog( context, - Translations.of(context) + Translations.instance! .trans('setlowerthanmaxitemposition')); return; } @@ -90,7 +90,7 @@ class _SearchPageModifyPageState extends State { style: ElevatedButton.styleFrom( backgroundColor: Settings.majorColor, ), - child: Text(Translations.of(context).trans('cancel')), + child: Text(Translations.instance!.trans('cancel')), onPressed: () { Navigator.pop(context, [0]); }, diff --git a/violet/lib/pages/search/search_type.dart b/violet/lib/pages/search/search_type.dart index e1d0c52f7..e62a82c61 100644 --- a/violet/lib/pages/search/search_type.dart +++ b/violet/lib/pages/search/search_type.dart @@ -63,7 +63,7 @@ class SearchType extends StatelessWidget { return ListTile( leading: Transform.scale( scaleX: flip ? -1 : 1, child: Icon(icon, color: getColor(selection))), - title: Text(Translations.of(context).trans(text), + title: Text(Translations.instance!.trans(text), softWrap: false, style: TextStyle(color: getColor(selection))), onTap: () async { await Settings.setSearchResultType(selection); diff --git a/violet/lib/pages/segment/filter_page.dart b/violet/lib/pages/segment/filter_page.dart index 3be371f49..868e93ee7 100644 --- a/violet/lib/pages/segment/filter_page.dart +++ b/violet/lib/pages/segment/filter_page.dart @@ -321,7 +321,7 @@ class _FilterPageState extends State { ), contentPadding: const EdgeInsets.only(left: 15, bottom: 11, top: 11, right: 15), - hintText: trans.Translations.of(context).trans('search'), + hintText: trans.Translations.instance!.trans('search'), ), ); } @@ -333,7 +333,7 @@ class _FilterPageState extends State { runSpacing: -10.0, children: [ FilterChip( - label: Text(trans.Translations.of(context).trans('selectall')), + label: Text(trans.Translations.instance!.trans('selectall')), onSelected: (bool value) { _tags .where((element) => c.groupStates[element.item1]!) @@ -344,7 +344,7 @@ class _FilterPageState extends State { }, ), FilterChip( - label: Text(trans.Translations.of(context).trans('deselectall')), + label: Text(trans.Translations.instance!.trans('deselectall')), onSelected: (bool value) { _tags .where((element) => c.groupStates[element.item1]!) @@ -355,7 +355,7 @@ class _FilterPageState extends State { }, ), FilterChip( - label: Text(trans.Translations.of(context).trans('inverse')), + label: Text(trans.Translations.instance!.trans('inverse')), onSelected: (bool value) { _tags .where((element) => c.groupStates[element.item1]!) diff --git a/violet/lib/pages/settings/bookmark_version_select.dart b/violet/lib/pages/settings/bookmark_version_select.dart index 4fe0d4ad1..c3f06d1b5 100644 --- a/violet/lib/pages/settings/bookmark_version_select.dart +++ b/violet/lib/pages/settings/bookmark_version_select.dart @@ -107,7 +107,7 @@ class _BookmarkVersionSelectPageState extends State { child: ListTile( title: Text( timeago.format(DateTime.parse(data['dt']).toLocal(), - locale: Translations.of(context).locale.languageCode), + locale: Translations.instance!.locale.languageCode), style: const TextStyle(fontSize: 16.0)), subtitle: Text(formatBytes(data['size'] as int, 2)), onTap: () async { diff --git a/violet/lib/pages/settings/lock_setting_page.dart b/violet/lib/pages/settings/lock_setting_page.dart index f2acbad03..dc5ebfc7f 100644 --- a/violet/lib/pages/settings/lock_setting_page.dart +++ b/violet/lib/pages/settings/lock_setting_page.dart @@ -29,7 +29,7 @@ class _LockSettingPageState extends State { children: [ ListTile( leading: const Icon(Icons.numbers), - title: Text(Translations.of(context).trans('pinsetting')), + title: Text(Translations.instance!.trans('pinsetting')), onTap: () { Navigator.push( context, @@ -48,9 +48,9 @@ class _LockSettingPageState extends State { if ((snapshot.data as SharedPreferences) .getString('pinPass') != null) { - return Text(Translations.of(context).trans('setted')); + return Text(Translations.instance!.trans('setted')); } - return Text(Translations.of(context).trans('notsetted')); + return Text(Translations.instance!.trans('notsetted')); }), ), Container( @@ -63,9 +63,9 @@ class _LockSettingPageState extends State { ListTile( enabled: false, leading: const Icon(Icons.fingerprint), - title: Text(Translations.of(context).trans('fingersetting')), + title: Text(Translations.instance!.trans('fingersetting')), onTap: () {}, - trailing: Text(Translations.of(context).trans('notsetted')), + trailing: Text(Translations.instance!.trans('notsetted')), ), Container( width: double.infinity, @@ -77,9 +77,9 @@ class _LockSettingPageState extends State { ListTile( enabled: false, leading: const Icon(MdiIcons.humanMaleBoard), - title: Text(Translations.of(context).trans('etchumansetting')), + title: Text(Translations.instance!.trans('etchumansetting')), onTap: () {}, - trailing: Text(Translations.of(context).trans('notsetted')), + trailing: Text(Translations.instance!.trans('notsetted')), ), Container( width: double.infinity, @@ -90,7 +90,7 @@ class _LockSettingPageState extends State { ), ListTile( leading: const Icon(Icons.lock), - title: Text(Translations.of(context).trans('useapplocksetting')), + title: Text(Translations.instance!.trans('useapplocksetting')), onTap: () async { _toggleAppLock(); }, diff --git a/violet/lib/pages/settings/settings_page.dart b/violet/lib/pages/settings/settings_page.dart index 1755808fb..8ee96ae65 100644 --- a/violet/lib/pages/settings/settings_page.dart +++ b/violet/lib/pages/settings/settings_page.dart @@ -183,7 +183,7 @@ class _SettingsPageState extends State List _themeGroup() { return [ - SettingGroupName(name: Translations.of(context).trans('theme')), + SettingGroupName(name: Translations.instance!.trans('theme')), _buildItems([ InkWell( customBorder: const RoundedRectangleBorder( @@ -200,7 +200,7 @@ class _SettingsPageState extends State ).createShader(bounds), child: const Icon(MdiIcons.themeLightDark, color: Colors.white), ), - title: Text(Translations.of(context).trans('darkmode')), + title: Text(Translations.instance!.trans('darkmode')), trailing: SizedBox( width: 50, height: 50, @@ -238,7 +238,7 @@ class _SettingsPageState extends State ).createShader(bounds), child: const Icon(MdiIcons.formatColorFill, color: Colors.white), ), - title: Text(Translations.of(context).trans('colorsetting')), + title: Text(Translations.instance!.trans('colorsetting')), trailing: const Icon( // Icons.message, Icons.keyboard_arrow_right), @@ -247,7 +247,7 @@ class _SettingsPageState extends State context: context, builder: (BuildContext context) { return AlertDialog( - title: Text(Translations.of(context).trans('selectcolor')), + title: Text(Translations.instance!.trans('selectcolor')), content: SingleChildScrollView( child: BlockPicker( pickerColor: Settings.majorColor, @@ -313,7 +313,7 @@ class _SettingsPageState extends State : null, child: ListTile( leading: Icon(MdiIcons.brightness3, color: Settings.majorColor), - title: Text(Translations.of(context).trans('blackmode')), + title: Text(Translations.instance!.trans('blackmode')), trailing: Switch( value: Settings.themeBlack, onChanged: _themeSwitch @@ -368,7 +368,7 @@ class _SettingsPageState extends State InkWell( child: ListTile( leading: Icon(Mdi.buffer, color: Settings.majorColor), - title: Text(Translations.of(context).trans('useflattheme')), + title: Text(Translations.instance!.trans('useflattheme')), trailing: Switch( value: Settings.themeFlat, onChanged: (newValue) async { @@ -391,7 +391,7 @@ class _SettingsPageState extends State InkWell( child: ListTile( leading: Icon(MdiIcons.tabletDashboard, color: Settings.majorColor), - title: Text(Translations.of(context).trans('usetabletmode')), + title: Text(Translations.instance!.trans('usetabletmode')), trailing: Switch( value: Settings.useTabletMode, onChanged: (newValue) async { @@ -415,7 +415,7 @@ class _SettingsPageState extends State InkWell( child: ListTile( leading: Icon(MdiIcons.cellphoneText, color: Settings.majorColor), - title: Text(Translations.of(context).trans('userdrawer')), + title: Text(Translations.instance!.trans('userdrawer')), trailing: Switch( value: Settings.useDrawer, onChanged: (newValue) async { @@ -454,7 +454,7 @@ class _SettingsPageState extends State bottomRight: Radius.circular(8.0))), child: ListTile( leading: Icon(MdiIcons.feather, color: Settings.majorColor), - title: Text(Translations.of(context).trans('litemode')), + title: Text(Translations.instance!.trans('litemode')), trailing: Switch( value: Settings.liteMode, onChanged: (newValue) async { @@ -492,7 +492,7 @@ class _SettingsPageState extends State List _communityGroup() { return [ - SettingGroupName(name: Translations.of(context).trans('community')), + SettingGroupName(name: Translations.instance!.trans('community')), _buildItems( [ InkWell( @@ -505,7 +505,7 @@ class _SettingsPageState extends State MdiIcons.discord, color: Color(0xFF7189da), ), - title: Text(Translations.of(context).trans('discord')), + title: Text(Translations.instance!.trans('discord')), trailing: const Icon(Icons.open_in_new), ), onTap: () async { @@ -520,7 +520,7 @@ class _SettingsPageState extends State MdiIcons.gmail, color: Colors.redAccent, ), - title: Text(Translations.of(context).trans('contact')), + title: Text(Translations.instance!.trans('contact')), trailing: const Icon(Icons.keyboard_arrow_right), onTap: () async { final url = Uri( @@ -538,7 +538,7 @@ class _SettingsPageState extends State ListTile( leading: Icon(MdiIcons.accessPointNetwork, color: Settings.majorColor), - title: Text(Translations.of(context).trans('realtimeuserrecord')), + title: Text(Translations.instance!.trans('realtimeuserrecord')), trailing: const Icon(Icons.keyboard_arrow_right), onTap: () async { PlatformNavigator.navigateSlide( @@ -548,7 +548,7 @@ class _SettingsPageState extends State ListTile( leading: Icon(MdiIcons.commentTextMultiple, color: Settings.majorColor), - title: Text(Translations.of(context).trans('comment')), + title: Text(Translations.instance!.trans('comment')), trailing: const Icon(Icons.keyboard_arrow_right), onTap: () async { PlatformNavigator.navigateSlide( @@ -560,7 +560,7 @@ class _SettingsPageState extends State color: Settings.themeWhat ? Colors.yellowAccent : Colors.yellow.shade900), - title: Text(Translations.of(context).trans('artistcollection')), + title: Text(Translations.instance!.trans('artistcollection')), trailing: const Icon(Icons.keyboard_arrow_right), onTap: () async { PlatformNavigator.navigateSlide( @@ -570,7 +570,7 @@ class _SettingsPageState extends State ListTile( leading: const Icon(MdiIcons.bookOpenPageVariant, color: Colors.brown), - title: Text(Translations.of(context).trans('usermanual')), + title: Text(Translations.instance!.trans('usermanual')), trailing: const Icon(Icons.keyboard_arrow_right), onTap: () async { PlatformNavigator.navigateSlide(context, const UserManualPage()); @@ -584,7 +584,7 @@ class _SettingsPageState extends State child: ListTile( leading: const Icon(MdiIcons.frequentlyAskedQuestions, color: Colors.orange), - title: Text(Translations.of(context).trans('faq')), + title: Text(Translations.instance!.trans('faq')), trailing: const Icon(Icons.keyboard_arrow_right), ), onTap: () { @@ -598,7 +598,7 @@ class _SettingsPageState extends State List _searchGroup() { return [ - SettingGroupName(name: Translations.of(context).trans('search')), + SettingGroupName(name: Translations.instance!.trans('search')), _buildItems( [ InkWell( @@ -614,9 +614,9 @@ class _SettingsPageState extends State title: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - Text(Translations.of(context).trans('defaulttag')), + Text(Translations.instance!.trans('defaulttag')), Text( - Translations.of(context).trans('currenttag') + + Translations.instance!.trans('currenttag') + Settings.includeTags, overflow: TextOverflow.ellipsis, ), @@ -644,7 +644,7 @@ class _SettingsPageState extends State MdiIcons.tagOff, color: Settings.majorColor, ), - title: Text(Translations.of(context).trans('excludetag')), + title: Text(Translations.instance!.trans('excludetag')), trailing: const Icon(Icons.keyboard_arrow_right), onTap: () async { final vv = await showDialog( @@ -667,13 +667,13 @@ class _SettingsPageState extends State MdiIcons.tooltipEdit, color: Settings.majorColor, ), - title: Text(Translations.of(context).trans('tagrebuild')), + title: Text(Translations.instance!.trans('tagrebuild')), trailing: const Icon(Icons.keyboard_arrow_right), onTap: () async { if (await showYesNoDialog( context, - Translations.of(context).trans('tagrebuildmsg'), - Translations.of(context).trans('tagrebuild'))) { + Translations.instance!.trans('tagrebuildmsg'), + Translations.instance!.trans('tagrebuild'))) { await showDialog( context: context, builder: (BuildContext context) => const TagRebuildPage(), @@ -685,7 +685,7 @@ class _SettingsPageState extends State showToast( level: ToastLevel.check, message: - '${Translations.of(context).trans('tagrebuild')} ${Translations.of(context).trans('complete')}', + '${Translations.instance!.trans('tagrebuild')} ${Translations.instance!.trans('complete')}', ); } }, @@ -724,7 +724,7 @@ class _SettingsPageState extends State MdiIcons.searchWeb, color: Settings.majorColor, ), - title: Text(Translations.of(context).trans('usewebsearch')), + title: Text(Translations.instance!.trans('usewebsearch')), trailing: Switch( value: Settings.searchNetwork, onChanged: (newValue) async { @@ -755,8 +755,7 @@ class _SettingsPageState extends State MdiIcons.searchWeb, color: Settings.majorColor, ), - title: - Text(Translations.of(context).trans('usesearchexpunged')), + title: Text(Translations.instance!.trans('usesearchexpunged')), trailing: Switch( value: Settings.searchExpunged, onChanged: (newValue) async { @@ -816,7 +815,7 @@ class _SettingsPageState extends State Widget okButton = TextButton( style: TextButton.styleFrom( foregroundColor: Settings.majorColor), - child: Text(Translations.of(context).trans('ok')), + child: Text(Translations.instance!.trans('ok')), onPressed: () { try { cats = int.parse(catsController.text); @@ -831,7 +830,7 @@ class _SettingsPageState extends State Widget cancelButton = TextButton( style: TextButton.styleFrom( foregroundColor: Settings.majorColor), - child: Text(Translations.of(context).trans('cancel')), + child: Text(Translations.instance!.trans('cancel')), onPressed: () { Navigator.pop(context); }, @@ -875,7 +874,7 @@ class _SettingsPageState extends State List _systemGroup() { return [ - SettingGroupName(name: Translations.of(context).trans('system')), + SettingGroupName(name: Translations.instance!.trans('system')), _buildItems( [ InkWell( @@ -885,7 +884,7 @@ class _SettingsPageState extends State topRight: Radius.circular(8.0))), child: ListTile( leading: Icon(Icons.receipt, color: Settings.majorColor), - title: Text(Translations.of(context).trans('logrecord')), + title: Text(Translations.instance!.trans('logrecord')), trailing: const Icon(Icons.keyboard_arrow_right), ), onTap: () { @@ -894,7 +893,7 @@ class _SettingsPageState extends State ), ListTile( leading: Icon(Icons.language, color: Settings.majorColor), - title: Text(Translations.of(context).trans('language')), + title: Text(Translations.instance!.trans('language')), trailing: const Icon(Icons.keyboard_arrow_right), onTap: () { showDialog( @@ -910,7 +909,7 @@ class _SettingsPageState extends State title: const Text('Select Language'), onValuePicked: (Country country) async { var exc = country as ExCountry; - await Translations.of(context).load(exc.toString()); + await Translations.instance!.load(exc.toString()); await Settings.setLanguage(exc.toString()); setState(() { _shouldReload = true; @@ -946,8 +945,7 @@ class _SettingsPageState extends State if (Settings.language == 'ko') ListTile( leading: Icon(Icons.translate, color: Settings.majorColor), - title: - Text(Translations.of(context).trans('translatetagtokorean')), + title: Text(Translations.instance!.trans('translatetagtokorean')), trailing: Switch( value: Settings.translateTags, onChanged: (newValue) async { @@ -969,7 +967,7 @@ class _SettingsPageState extends State ListTile( leading: Icon(MdiIcons.imageSizeSelectLarge, color: Settings.majorColor), - title: Text(Translations.of(context).trans('lowresmode')), + title: Text(Translations.instance!.trans('lowresmode')), trailing: Switch( value: Settings.useLowPerf, onChanged: (newValue) async { @@ -991,7 +989,7 @@ class _SettingsPageState extends State if (!Settings.liteMode) ListTile( leading: Icon(Mdi.tableArrowRight, color: Settings.majorColor), - title: Text(Translations.of(context).trans('exportlog')), + title: Text(Translations.instance!.trans('exportlog')), trailing: const Icon(Icons.keyboard_arrow_right), onTap: () async { final ext = Platform.isIOS @@ -1020,13 +1018,13 @@ class _SettingsPageState extends State showToast( level: ToastLevel.check, - message: Translations.of(context).trans('complete'), + message: Translations.instance!.trans('complete'), ); }, ), ListTile( leading: Icon(Icons.info_outline, color: Settings.majorColor), - title: Text(Translations.of(context).trans('info')), + title: Text(Translations.instance!.trans('info')), trailing: const Icon(Icons.keyboard_arrow_right), onTap: () async { await showDialog( @@ -1039,7 +1037,7 @@ class _SettingsPageState extends State ), ListTile( leading: const Icon(MdiIcons.fileSign, color: Colors.cyan), - title: Text(Translations.of(context).trans('patchnote')), + title: Text(Translations.instance!.trans('patchnote')), trailing: const Icon(Icons.keyboard_arrow_right), onTap: () async { PlatformNavigator.navigateSlide(context, const PatchNotePage()); @@ -1052,7 +1050,7 @@ class _SettingsPageState extends State bottomRight: Radius.circular(8.0))), child: ListTile( leading: const Icon(MdiIcons.flask, color: Color(0xFF73BE1E)), - title: Text(Translations.of(context).trans('lab')), + title: Text(Translations.instance!.trans('lab')), trailing: const Icon(Icons.keyboard_arrow_right), ), onTap: () async { @@ -1066,7 +1064,7 @@ class _SettingsPageState extends State List _securityGroup() { return [ - SettingGroupName(name: Translations.of(context).trans('security')), + SettingGroupName(name: Translations.instance!.trans('security')), _buildItems( [ InkWell( @@ -1080,7 +1078,7 @@ class _SettingsPageState extends State Icons.lock_outline, color: Settings.majorColor, ), - title: Text(Translations.of(context).trans('lockapp')), + title: Text(Translations.instance!.trans('lockapp')), trailing: const Icon( // Icons.message, Icons.keyboard_arrow_right), @@ -1104,7 +1102,7 @@ class _SettingsPageState extends State MdiIcons.shieldLockOutline, color: Settings.majorColor, ), - title: Text(Translations.of(context).trans('securemode')), + title: Text(Translations.instance!.trans('securemode')), trailing: Switch( value: Settings.useSecureMode, onChanged: (newValue) async { @@ -1143,7 +1141,7 @@ class _SettingsPageState extends State List _databaseGroup() { return [ - SettingGroupName(name: Translations.of(context).trans('database')), + SettingGroupName(name: Translations.instance!.trans('database')), _buildItems( [ InkWell( @@ -1160,7 +1158,7 @@ class _SettingsPageState extends State child: ListTile( leading: Icon(MdiIcons.swapHorizontal, color: Settings.majorColor), - title: Text(Translations.of(context).trans('switching')), + title: Text(Translations.instance!.trans('switching')), trailing: const Icon(Icons.keyboard_arrow_right), ), ), @@ -1170,14 +1168,14 @@ class _SettingsPageState extends State MdiIcons.databaseEdit, color: Settings.majorColor, ), - title: Text(Translations.of(context).trans('dbrebuild')), + title: Text(Translations.instance!.trans('dbrebuild')), trailing: const Icon(Icons.keyboard_arrow_right), ), onTap: () async { if (await showYesNoDialog( context, - Translations.of(context).trans('dbrebuildmsg'), - Translations.of(context).trans('dbrebuild'))) { + Translations.instance!.trans('dbrebuildmsg'), + Translations.instance!.trans('dbrebuild'))) { await showDialog( context: context, builder: (BuildContext context) => const DBRebuildPage(), @@ -1186,7 +1184,7 @@ class _SettingsPageState extends State showToast( level: ToastLevel.check, message: - '${Translations.of(context).trans('dbrebuild')} ${Translations.of(context).trans('complete')}', + '${Translations.instance!.trans('dbrebuild')} ${Translations.instance!.trans('complete')}', ); } }, @@ -1197,7 +1195,7 @@ class _SettingsPageState extends State MdiIcons.vectorIntersection, color: Settings.majorColor, ), - title: Text(Translations.of(context).trans('dbopt')), + title: Text(Translations.instance!.trans('dbopt')), trailing: Switch( value: Settings.useOptimizeDatabase, onChanged: (newValue) async { @@ -1232,8 +1230,7 @@ class _SettingsPageState extends State latestDB.difference(DateTime.parse(lastDB)).inHours < 1) { showToast( level: ToastLevel.check, - message: - Translations.of(context).trans('thisislatestbookmark'), + message: Translations.instance!.trans('thisislatestbookmark'), ); return; } @@ -1263,14 +1260,14 @@ class _SettingsPageState extends State showToast( level: ToastLevel.check, - message: Translations.of(context).trans('synccomplete'), + message: Translations.instance!.trans('synccomplete'), ); }, ); }, child: ListTile( leading: Icon(MdiIcons.databaseSync, color: Settings.majorColor), - title: Text(Translations.of(context).trans('syncmanual')), + title: Text(Translations.instance!.trans('syncmanual')), trailing: const Icon(Icons.keyboard_arrow_right), ), ), @@ -1281,7 +1278,7 @@ class _SettingsPageState extends State List _networkingGroup() { return [ - SettingGroupName(name: Translations.of(context).trans('network')), + SettingGroupName(name: Translations.instance!.trans('network')), _buildItems( [ // InkWell( @@ -1307,7 +1304,7 @@ class _SettingsPageState extends State Icons.router, color: Settings.majorColor, ), - title: Text(Translations.of(context).trans('routing_rule')), + title: Text(Translations.instance!.trans('routing_rule')), trailing: const Icon(Icons.keyboard_arrow_right), onTap: () async { await showDialog( @@ -1330,7 +1327,7 @@ class _SettingsPageState extends State color: Settings.majorColor, ), title: - Text('Image ${Translations.of(context).trans('routing_rule')}'), + Text('Image ${Translations.instance!.trans('routing_rule')}'), trailing: const Icon(Icons.keyboard_arrow_right), onTap: () async { await showDialog( @@ -1345,7 +1342,7 @@ class _SettingsPageState extends State MdiIcons.commentSearch, color: Settings.majorColor, ), - title: Text(Translations.of(context).trans('messagesearchapi')), + title: Text(Translations.instance!.trans('messagesearchapi')), trailing: const Icon(Icons.keyboard_arrow_right), onTap: () async { TextEditingController text = @@ -1353,7 +1350,7 @@ class _SettingsPageState extends State Widget okButton = TextButton( style: TextButton.styleFrom(foregroundColor: Settings.majorColor), - child: Text(Translations.of(context).trans('ok')), + child: Text(Translations.instance!.trans('ok')), onPressed: () { Navigator.pop(context, true); }, @@ -1361,7 +1358,7 @@ class _SettingsPageState extends State Widget cancelButton = TextButton( style: TextButton.styleFrom(foregroundColor: Settings.majorColor), - child: Text(Translations.of(context).trans('cancel')), + child: Text(Translations.instance!.trans('cancel')), onPressed: () { Navigator.pop(context, false); }, @@ -1369,7 +1366,7 @@ class _SettingsPageState extends State Widget defaultButton = TextButton( style: TextButton.styleFrom(foregroundColor: Settings.majorColor), - child: Text(Translations.of(context).trans('default')), + child: Text(Translations.instance!.trans('default')), onPressed: () { _shouldReload = true; setState( @@ -1400,7 +1397,7 @@ class _SettingsPageState extends State MdiIcons.timerOff, color: Settings.majorColor, ), - title: Text(Translations.of(context).trans('ignoretimeout')), + title: Text(Translations.instance!.trans('ignoretimeout')), trailing: Switch( value: Settings.ignoreTimeout, onChanged: (newValue) async { @@ -1424,7 +1421,7 @@ class _SettingsPageState extends State width: 25, height: 25, ), - title: Text(Translations.of(context).trans('usevioletserver')), + title: Text(Translations.instance!.trans('usevioletserver')), trailing: Switch( value: Settings.useVioletServer, onChanged: (newValue) async { @@ -1451,7 +1448,7 @@ class _SettingsPageState extends State List _downloadGroup() { return [ - SettingGroupName(name: Translations.of(context).trans('download')), + SettingGroupName(name: Translations.instance!.trans('download')), _buildItems( [ InkWell( @@ -1473,7 +1470,7 @@ class _SettingsPageState extends State MdiIcons.downloadLock, color: Settings.majorColor, ), - title: Text(Translations.of(context).trans('useinnerstorage')), + title: Text(Translations.instance!.trans('useinnerstorage')), trailing: Switch( value: Settings.useInnerStorage, onChanged: Platform.isIOS @@ -1498,19 +1495,19 @@ class _SettingsPageState extends State crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( - Translations.of(context).trans('threadcount'), + Translations.instance!.trans('threadcount'), ), FutureBuilder( builder: (context, AsyncSnapshot snapshot) { if (!snapshot.hasData) { return Text( - '${Translations.of(context).trans('curthread')}: ', + '${Translations.instance!.trans('curthread')}: ', overflow: TextOverflow.ellipsis, ); } return Text( - '${Translations.of(context).trans('curthread')}: ${snapshot.data!.getInt('thread_count')}', + '${Translations.instance!.trans('curthread')}: ${snapshot.data!.getInt('thread_count')}', overflow: TextOverflow.ellipsis, ); }, @@ -1532,23 +1529,23 @@ class _SettingsPageState extends State onPressed: () async { if (int.tryParse(text.text) == null) { await showOkDialog( - context, Translations.of(context).trans('putonlynum')); + context, Translations.instance!.trans('putonlynum')); return; } if (int.parse(text.text) > 128) { await showOkDialog( - context, Translations.of(context).trans('toomuch')); + context, Translations.instance!.trans('toomuch')); return; } if (int.parse(text.text) == 0) { await showOkDialog( - context, Translations.of(context).trans('threadzero')); + context, Translations.instance!.trans('threadzero')); return; } Navigator.pop(context, true); }, - child: Text(Translations.of(context).trans('change'), + child: Text(Translations.instance!.trans('change'), style: TextStyle(color: Settings.majorColor)), ); Widget noButton = TextButton( @@ -1557,14 +1554,14 @@ class _SettingsPageState extends State onPressed: () { Navigator.pop(context, false); }, - child: Text(Translations.of(context).trans('cancel'), + child: Text(Translations.instance!.trans('cancel'), style: TextStyle(color: Settings.majorColor)), ); var dialog = await showDialog( context: context, builder: (context) => AlertDialog( contentPadding: const EdgeInsets.fromLTRB(12, 0, 12, 0), - title: Text(Translations.of(context).trans('setthread')), + title: Text(Translations.instance!.trans('setthread')), content: TextField( controller: text, autofocus: true, @@ -1584,7 +1581,7 @@ class _SettingsPageState extends State showToast( level: ToastLevel.check, - message: Translations.of(context).trans('changedthread'), + message: Translations.instance!.trans('changedthread'), ); setState(() {}); @@ -1604,7 +1601,7 @@ class _SettingsPageState extends State Widget yesButton = TextButton( style: TextButton.styleFrom( foregroundColor: Settings.majorColor), - child: Text(Translations.of(context).trans('ok')), + child: Text(Translations.instance!.trans('ok')), onPressed: () { Navigator.pop(context, true); }, @@ -1612,7 +1609,7 @@ class _SettingsPageState extends State Widget noButton = TextButton( style: TextButton.styleFrom( foregroundColor: Settings.majorColor), - child: Text(Translations.of(context).trans('cancel')), + child: Text(Translations.instance!.trans('cancel')), onPressed: () { Navigator.pop(context, false); }, @@ -1620,7 +1617,7 @@ class _SettingsPageState extends State Widget defaultButton = TextButton( style: TextButton.styleFrom( foregroundColor: Settings.majorColor), - child: Text(Translations.of(context).trans('default')), + child: Text(Translations.instance!.trans('default')), onPressed: () { _shouldReload = true; Settings.getDefaultDownloadPath() @@ -1632,8 +1629,8 @@ class _SettingsPageState extends State context: context, builder: (BuildContext context) => AlertDialog( contentPadding: const EdgeInsets.fromLTRB(12, 0, 12, 0), - title: Text( - Translations.of(context).trans('downloadpath')), + title: + Text(Translations.instance!.trans('downloadpath')), content: TextField( controller: text, autofocus: true, @@ -1661,9 +1658,9 @@ class _SettingsPageState extends State title: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - Text(Translations.of(context).trans('downloadpath')), + Text(Translations.instance!.trans('downloadpath')), Text( - '${Translations.of(context).trans('curdownloadpath')}: ${Settings.downloadBasePath}', + '${Translations.instance!.trans('curdownloadpath')}: ${Settings.downloadBasePath}', overflow: TextOverflow.ellipsis, ), ], @@ -1686,9 +1683,9 @@ class _SettingsPageState extends State title: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - Text(Translations.of(context).trans('downloadrule')), + Text(Translations.instance!.trans('downloadrule')), Text( - '${Translations.of(context).trans('curdownloadrule')}: ${Settings.downloadRule}', + '${Translations.instance!.trans('curdownloadrule')}: ${Settings.downloadRule}', overflow: TextOverflow.ellipsis, ), ], @@ -1701,7 +1698,7 @@ class _SettingsPageState extends State Widget okButton = TextButton( style: TextButton.styleFrom(foregroundColor: Settings.majorColor), - child: Text(Translations.of(context).trans('ok')), + child: Text(Translations.instance!.trans('ok')), onPressed: () { Navigator.pop(context, true); }, @@ -1709,7 +1706,7 @@ class _SettingsPageState extends State Widget cancelButton = TextButton( style: TextButton.styleFrom(foregroundColor: Settings.majorColor), - child: Text(Translations.of(context).trans('cancel')), + child: Text(Translations.instance!.trans('cancel')), onPressed: () { Navigator.pop(context, false); }, @@ -1717,7 +1714,7 @@ class _SettingsPageState extends State Widget defaultButton = TextButton( style: TextButton.styleFrom(foregroundColor: Settings.majorColor), - child: Text(Translations.of(context).trans('default')), + child: Text(Translations.instance!.trans('default')), onPressed: () { _shouldReload = true; setState(() => @@ -1731,7 +1728,7 @@ class _SettingsPageState extends State context: context, builder: (BuildContext context) => AlertDialog( contentPadding: const EdgeInsets.fromLTRB(12, 0, 12, 0), - title: Text(Translations.of(context).trans('downloadrule')), + title: Text(Translations.instance!.trans('downloadrule')), content: TextField( controller: text, autofocus: true, @@ -1768,7 +1765,7 @@ class _SettingsPageState extends State */ return [ - SettingGroupName(name: Translations.of(context).trans('bookmark')), + SettingGroupName(name: Translations.instance!.trans('bookmark')), _buildItems( [ InkWell( @@ -1783,7 +1780,7 @@ class _SettingsPageState extends State MdiIcons.bookArrowUpOutline, color: Settings.majorColor, ), - title: Text(Translations.of(context).trans('autobackupbookmark')), + title: Text(Translations.instance!.trans('autobackupbookmark')), trailing: Switch( value: Settings.autobackupBookmark, // onChanged: setAutoBackupBookmark, @@ -1799,13 +1796,13 @@ class _SettingsPageState extends State MdiIcons.bookArrowDownOutline, color: Settings.majorColor, ), - title: Text(Translations.of(context).trans('restoringbookmark')), + title: Text(Translations.instance!.trans('restoringbookmark')), trailing: const Icon(Icons.keyboard_arrow_right), onTap: () async { await showOkDialog( context, - Translations.of(context).trans('restorebookmarkmsg'), - Translations.of(context).trans('warning')); + Translations.instance!.trans('restorebookmarkmsg'), + Translations.instance!.trans('warning')); final prefs = await SharedPreferences.getInstance(); var myappid = prefs.getString('fa_userid'); @@ -1816,7 +1813,7 @@ class _SettingsPageState extends State Widget okButton = TextButton( style: TextButton.styleFrom( foregroundColor: Settings.majorColor), - child: Text(Translations.of(context).trans('ok')), + child: Text(Translations.instance!.trans('ok')), onPressed: () { Navigator.pop(context, true); }, @@ -1824,7 +1821,7 @@ class _SettingsPageState extends State Widget cancelButton = TextButton( style: TextButton.styleFrom( foregroundColor: Settings.majorColor), - child: Text(Translations.of(context).trans('cancel')), + child: Text(Translations.instance!.trans('cancel')), onPressed: () { Navigator.pop(context, false); }, @@ -1855,7 +1852,7 @@ class _SettingsPageState extends State await showOkDialog( context, "Invalid User-App-Id! If you're still getting this error, contact the developer.", - Translations.of(context).trans('restoringbookmark')); + Translations.instance!.trans('restoringbookmark')); return; } @@ -1865,7 +1862,7 @@ class _SettingsPageState extends State await showOkDialog( context, '북마크 버전 정보를 가져오는데 오류가 발생했습니다. UserAppId와 함께 개발자에게 문의하시기 바랍니다.', - Translations.of(context).trans('restoringbookmark')); + Translations.instance!.trans('restoringbookmark')); return; } @@ -1916,13 +1913,13 @@ class _SettingsPageState extends State showToast( level: ToastLevel.check, - message: Translations.of(context).trans('importbookmark'), + message: Translations.instance!.trans('importbookmark'), ); }, ), ListTile( leading: Icon(MdiIcons.import, color: Settings.majorColor), - title: Text(Translations.of(context).trans('importingbookmark')), + title: Text(Translations.instance!.trans('importingbookmark')), trailing: const Icon(Icons.keyboard_arrow_right), onTap: () async { await FilePicker.platform.clearTemporaryFiles(); @@ -1932,7 +1929,7 @@ class _SettingsPageState extends State if (pickedFilePath == null) { showToast( level: ToastLevel.error, - message: Translations.of(context).trans('noselectedb'), + message: Translations.instance!.trans('noselectedb'), ); return; @@ -1949,7 +1946,7 @@ class _SettingsPageState extends State showToast( level: ToastLevel.check, - message: Translations.of(context).trans('importbookmark'), + message: Translations.instance!.trans('importbookmark'), ); }, ), @@ -1958,7 +1955,7 @@ class _SettingsPageState extends State MdiIcons.export, color: Settings.majorColor, ), - title: Text(Translations.of(context).trans('exportingbookmark')), + title: Text(Translations.instance!.trans('exportingbookmark')), trailing: const Icon(Icons.keyboard_arrow_right), onTap: () async { final dir = Platform.isIOS @@ -1987,7 +1984,7 @@ class _SettingsPageState extends State showToast( level: ToastLevel.check, - message: Translations.of(context).trans('exportbookmark'), + message: Translations.instance!.trans('exportbookmark'), ); }, ), @@ -1997,7 +1994,7 @@ class _SettingsPageState extends State MdiIcons.cloudSearchOutline, color: Settings.majorColor, ), - title: Text(Translations.of(context).trans('importfromeh')), + title: Text(Translations.instance!.trans('importfromeh')), trailing: const Icon(Icons.keyboard_arrow_right), ), onTap: () async { @@ -2007,7 +2004,7 @@ class _SettingsPageState extends State if (ehc == null || ehc == '') { showToast( level: ToastLevel.error, - message: Translations.of(context).trans('setcookiefirst'), + message: Translations.instance!.trans('setcookiefirst'), ); return; } @@ -2020,7 +2017,7 @@ class _SettingsPageState extends State if (EHBookmark.bookmarkInfo == null) { showToast( level: ToastLevel.warning, - message: Translations.of(context).trans('bookmarkisempty'), + message: Translations.instance!.trans('bookmarkisempty'), ); return; } @@ -2032,7 +2029,7 @@ class _SettingsPageState extends State var qqq = await showYesNoDialog( context, - Translations.of(context) + Translations.instance! .trans('ensurecreatebookmark') .replaceAll('\$1', count.toString())); if (qqq) { @@ -2055,7 +2052,7 @@ class _SettingsPageState extends State showToast( level: ToastLevel.check, message: - Translations.of(context).trans('completeimportbookmark'), + Translations.instance!.trans('completeimportbookmark'), ); } }, @@ -2071,7 +2068,7 @@ class _SettingsPageState extends State MdiIcons.cloudSearchOutline, color: Settings.majorColor, ), - title: Text(Translations.of(context).trans('importfromjson')), + title: Text(Translations.instance!.trans('importfromjson')), trailing: const Icon(Icons.keyboard_arrow_right), ), onTap: () async { @@ -2098,8 +2095,7 @@ class _SettingsPageState extends State context: context, builder: (BuildContext context) { return AlertDialog( - title: - Text(Translations.of(context).trans('importfromjson')), + title: Text(Translations.instance!.trans('importfromjson')), contentPadding: const EdgeInsets.fromLTRB(12, 8, 12, 8), actions: [ importButton, @@ -2112,7 +2108,7 @@ class _SettingsPageState extends State mainAxisSize: MainAxisSize.min, crossAxisAlignment: CrossAxisAlignment.start, children: [ - Text(Translations.of(context) + Text(Translations.instance! .trans('pasteyourbookmarktext')), Row( children: [ @@ -2181,7 +2177,7 @@ class _SettingsPageState extends State List _componetGroup() { return [ - SettingGroupName(name: Translations.of(context).trans('component')), + SettingGroupName(name: Translations.instance!.trans('component')), _buildItems( [ InkWell( @@ -2272,7 +2268,7 @@ class _SettingsPageState extends State Widget okButton = TextButton( style: TextButton.styleFrom( foregroundColor: Settings.majorColor), - child: Text(Translations.of(context).trans('ok')), + child: Text(Translations.instance!.trans('ok')), onPressed: () { Navigator.pop(context, true); }, @@ -2280,7 +2276,7 @@ class _SettingsPageState extends State Widget cancelButton = TextButton( style: TextButton.styleFrom( foregroundColor: Settings.majorColor), - child: Text(Translations.of(context).trans('cancel')), + child: Text(Translations.instance!.trans('cancel')), onPressed: () { Navigator.pop(context, false); }, @@ -2367,7 +2363,7 @@ class _SettingsPageState extends State List _viewGroup() { return [ - SettingGroupName(name: Translations.of(context).trans('view')), + SettingGroupName(name: Translations.instance!.trans('view')), _buildItems( [ InkWell( @@ -2378,8 +2374,7 @@ class _SettingsPageState extends State MdiIcons.progressClock, color: Settings.majorColor, ), - title: - Text(Translations.of(context).trans('showarticleprogress')), + title: Text(Translations.instance!.trans('showarticleprogress')), trailing: Switch( value: Settings.showArticleProgress, onChanged: (newValue) async { @@ -2407,7 +2402,7 @@ class _SettingsPageState extends State List _updateGroup() { return [ - SettingGroupName(name: Translations.of(context).trans('update')), + SettingGroupName(name: Translations.instance!.trans('update')), _buildItems( [ InkWell( @@ -2421,7 +2416,7 @@ class _SettingsPageState extends State Icons.update, color: Settings.majorColor, ), - title: Text(Translations.of(context).trans('checkupdate')), + title: Text(Translations.instance!.trans('checkupdate')), trailing: const Icon( // Icons.message, Icons.keyboard_arrow_right), @@ -2432,12 +2427,12 @@ class _SettingsPageState extends State if (UpdateSyncManager.updateRequire) { showToast( level: ToastLevel.check, - message: Translations.of(context).trans('newupdate'), + message: Translations.instance!.trans('newupdate'), ); } else { showToast( level: ToastLevel.check, - message: Translations.of(context).trans('latestver'), + message: Translations.instance!.trans('latestver'), ); } }, @@ -2452,7 +2447,7 @@ class _SettingsPageState extends State MdiIcons.cellphoneArrowDown, color: Settings.majorColor, ), - title: Text(Translations.of(context).trans('manualupdate')), + title: Text(Translations.instance!.trans('manualupdate')), trailing: const Icon( // Icons.message, Icons.keyboard_arrow_right), @@ -2463,7 +2458,7 @@ class _SettingsPageState extends State if (!UpdateSyncManager.updateRequire) { showToast( level: ToastLevel.check, - message: Translations.of(context).trans('latestver'), + message: Translations.instance!.trans('latestver'), ); return; } @@ -2471,7 +2466,7 @@ class _SettingsPageState extends State if (Platform.isIOS) { showToast( level: ToastLevel.warning, - message: Translations.of(context).trans('cannotuseios'), + message: Translations.instance!.trans('cannotuseios'), ); return; } @@ -2490,7 +2485,7 @@ class _SettingsPageState extends State List _etcGroup() { return [ - SettingGroupName(name: Translations.of(context).trans('etc')), + SettingGroupName(name: Translations.instance!.trans('etc')), _buildItems( [ if (!Settings.liteMode) @@ -2504,7 +2499,7 @@ class _SettingsPageState extends State MdiIcons.discord, color: Color(0xFF7189da), ), - title: Text(Translations.of(context).trans('discord')), + title: Text(Translations.instance!.trans('discord')), trailing: const Icon(Icons.open_in_new), ), onTap: () async { @@ -2520,8 +2515,7 @@ class _SettingsPageState extends State MdiIcons.github, color: Colors.black, ), - title: - Text('GitHub ${Translations.of(context).trans('project')}'), + title: Text('GitHub ${Translations.instance!.trans('project')}'), trailing: const Icon(Icons.open_in_new), onTap: () async { final url = Uri.parse('https://github.com/project-violet/'); @@ -2542,7 +2536,7 @@ class _SettingsPageState extends State color: Colors.black, ), title: - Text('GitHub ${Translations.of(context).trans('project')}'), + Text('GitHub ${Translations.instance!.trans('project')}'), trailing: const Icon(Icons.open_in_new), ), onTap: () async { @@ -2558,7 +2552,7 @@ class _SettingsPageState extends State MdiIcons.gmail, color: Colors.redAccent, ), - title: Text(Translations.of(context).trans('contact')), + title: Text(Translations.instance!.trans('contact')), trailing: const Icon(Icons.keyboard_arrow_right), onTap: () async { final url = Uri( @@ -2578,7 +2572,7 @@ class _SettingsPageState extends State MdiIcons.heart, color: Colors.orange, ), - title: Text(Translations.of(context).trans('donate')), + title: Text(Translations.instance!.trans('donate')), trailing: const Icon( // Icons.email, Icons.open_in_new), @@ -2615,7 +2609,7 @@ class _SettingsPageState extends State MdiIcons.library, color: Settings.majorColor, ), - title: Text(Translations.of(context).trans('license')), + title: Text(Translations.instance!.trans('license')), trailing: const Icon(Icons.keyboard_arrow_right), ), onTap: () { diff --git a/violet/lib/pages/settings/tag_selector.dart b/violet/lib/pages/settings/tag_selector.dart index c8e87e698..28c1127f5 100644 --- a/violet/lib/pages/settings/tag_selector.dart +++ b/violet/lib/pages/settings/tag_selector.dart @@ -88,7 +88,7 @@ class _TagSelectorDialogState extends State { children: [ ListTile( contentPadding: const EdgeInsets.all(0), - leading: Text('${Translations.of(context).trans('tag')}:'), + leading: Text('${Translations.instance!.trans('tag')}:'), title: TextField( controller: _searchController, minLines: 1, @@ -102,8 +102,8 @@ class _TagSelectorDialogState extends State { child: _searchLists.isEmpty || _nothing ? Center( child: Text(_nothing - ? Translations.of(context).trans('nosearchresult') - : Translations.of(context) + ? Translations.instance!.trans('nosearchresult') + : Translations.instance! .trans('inputsearchtoken'))) : Padding( padding: const EdgeInsets.symmetric(horizontal: 0), @@ -120,7 +120,7 @@ class _TagSelectorDialogState extends State { ), ), widget.what == 'include' - ? Text(Translations.of(context).trans('tagmsgdefault'), + ? Text(Translations.instance!.trans('tagmsgdefault'), style: const TextStyle(fontSize: 14.0)) : Container() ], @@ -133,7 +133,7 @@ class _TagSelectorDialogState extends State { style: ElevatedButton.styleFrom( backgroundColor: Settings.majorColor, ), - child: Text(Translations.of(context).trans('ok')), + child: Text(Translations.instance!.trans('ok')), onPressed: () { Navigator.pop( context, Tuple2(1, _searchController.text)); @@ -143,7 +143,7 @@ class _TagSelectorDialogState extends State { style: ElevatedButton.styleFrom( backgroundColor: Settings.majorColor, ), - child: Text(Translations.of(context).trans('cancel')), + child: Text(Translations.instance!.trans('cancel')), onPressed: () { Navigator.pop( context, Tuple2(0, _searchController.text)); diff --git a/violet/lib/pages/settings/version_page.dart b/violet/lib/pages/settings/version_page.dart index e098f7f38..9a091d230 100644 --- a/violet/lib/pages/settings/version_page.dart +++ b/violet/lib/pages/settings/version_page.dart @@ -55,7 +55,7 @@ class VersionViewPage extends StatelessWidget { const Text(''), const Text('Project-Violet Android App'), Text( - Translations.of(context).trans('infomessage'), + Translations.instance!.trans('infomessage'), textAlign: TextAlign.center, style: const TextStyle(fontSize: 10), ), diff --git a/violet/lib/pages/splash/splash_page.dart b/violet/lib/pages/splash/splash_page.dart index 245eeeee1..01f6fa0d1 100644 --- a/violet/lib/pages/splash/splash_page.dart +++ b/violet/lib/pages/splash/splash_page.dart @@ -422,7 +422,7 @@ class _SplashPageState extends State { } _firstPage() { - final translations = Translations.of(context); + final translations = Translations.instance!; return Visibility( visible: showFirst, @@ -525,8 +525,8 @@ class _SplashPageState extends State { Expanded( child: Text( widget.switching - ? '${Translations.of(context).trans('database')} ${Translations.of(context).trans('switching')}' - : Translations.of(context).trans('welcome'), + ? '${Translations.instance!.trans('database')} ${Translations.instance!.trans('switching')}' + : Translations.instance!.trans('welcome'), maxLines: 4, style: const TextStyle( fontWeight: FontWeight.bold, @@ -556,7 +556,7 @@ class _SplashPageState extends State { mainAxisAlignment: MainAxisAlignment.end, crossAxisAlignment: CrossAxisAlignment.center, children: [ - Text(Translations.of(context).trans('download')), + Text(Translations.instance!.trans('download')), const Icon(Icons.keyboard_arrow_right), ], ), @@ -570,8 +570,8 @@ class _SplashPageState extends State { if (_database == Database.all) { if (!await showYesNoDialog( context, - Translations.of(context).trans('dbwarn'), - Translations.of(context).trans('warning'))) { + Translations.instance!.trans('dbwarn'), + Translations.instance!.trans('warning'))) { return; } } @@ -588,7 +588,7 @@ class _SplashPageState extends State { builder: (context) => DataBaseDownloadPage( dbType: _database == Database.all ? 'global' - : Translations.of(context).dbLanguageCode, + : Translations.instance!.dbLanguageCode, ))); } @@ -602,7 +602,7 @@ class _SplashPageState extends State { padding: const EdgeInsets.fromLTRB(0, 0, 0, 100), child: GestureDetector( child: SizedBox( - child: Text(Translations.of(context).trans('dbalready'), + child: Text(Translations.instance!.trans('dbalready'), style: TextStyle( color: widget.switching ? Settings.majorAccentColor @@ -617,7 +617,7 @@ class _SplashPageState extends State { // builder: (context) => DataBaseDownloadPage( // dbType: _database == Database.all // ? 'global' - // : Translations.of(context).locale.languageCode, + // : Translations.instance!.locale.languageCode, // isExistsDataBase: true, // dbPath: path, // ))); @@ -673,7 +673,7 @@ class _SplashPageState extends State { title: const Text('Select Language'), onValuePicked: (Country country) async { var exc = country as ExCountry; - await Translations.of(context).load(exc.toString()); + await Translations.instance!.load(exc.toString()); await Settings.setLanguage(exc.toString()); await Settings.resetIncludeTags(); setState(() {}); @@ -722,7 +722,7 @@ class _SplashPageState extends State { if (filename == null) { if (mounted) { await showOkDialog( - context, Translations.of(context).trans('dbalreadyerr')); + context, Translations.instance!.trans('dbalreadyerr')); } return ''; } diff --git a/violet/lib/pages/viewer/overlay/viewer_setting_panel.dart b/violet/lib/pages/viewer/overlay/viewer_setting_panel.dart index 43627179d..d8d220e0d 100644 --- a/violet/lib/pages/viewer/overlay/viewer_setting_panel.dart +++ b/violet/lib/pages/viewer/overlay/viewer_setting_panel.dart @@ -86,7 +86,7 @@ class _ViewerSettingPanelState extends State { ), _checkBox( value: Settings.isHorizontal, - title: locale.Translations.of(context).trans('toggleviewerstyle'), + title: locale.Translations.instance!.trans('toggleviewerstyle'), onChanged: (value) async { await Settings.setIsHorizontal(!Settings.isHorizontal); @@ -98,7 +98,7 @@ class _ViewerSettingPanelState extends State { }, ), _checkBox( - title: locale.Translations.of(context).trans('togglescrollvertical'), + title: locale.Translations.instance!.trans('togglescrollvertical'), value: Settings.scrollVertical, enabled: Settings.isHorizontal, onChanged: (value) async { @@ -112,7 +112,7 @@ class _ViewerSettingPanelState extends State { }, ), _checkBox( - title: locale.Translations.of(context).trans('togglerighttoleft'), + title: locale.Translations.instance!.trans('togglerighttoleft'), value: Settings.rightToLeft, onChanged: (value) async { await Settings.setRightToLeft(!Settings.rightToLeft); @@ -123,7 +123,7 @@ class _ViewerSettingPanelState extends State { }, ), _checkBox( - title: locale.Translations.of(context).trans('toggleanimatin'), + title: locale.Translations.instance!.trans('toggleanimatin'), value: Settings.animation, onChanged: (value) async { await Settings.setAnimation(!Settings.animation); @@ -134,7 +134,7 @@ class _ViewerSettingPanelState extends State { }, ), _checkBox( - title: locale.Translations.of(context).trans('togglepadding'), + title: locale.Translations.instance!.trans('togglepadding'), value: Settings.padding, onChanged: (value) async { await Settings.setPadding(!Settings.padding); @@ -145,7 +145,7 @@ class _ViewerSettingPanelState extends State { }, ), _checkBox( - title: locale.Translations.of(context).trans('disableoverlaybuttons'), + title: locale.Translations.instance!.trans('disableoverlaybuttons'), value: !Settings.disableOverlayButton, onChanged: (value) async { await Settings.setDisableOverlayButton( @@ -159,8 +159,7 @@ class _ViewerSettingPanelState extends State { if (!Platform.isIOS) _checkBox( value: Settings.moveToAppBarToBottom, - title: - locale.Translations.of(context).trans('movetoappbartobottom'), + title: locale.Translations.instance!.trans('movetoappbartobottom'), onChanged: (value) async { await Settings.setMoveToAppBarToBottom( !Settings.moveToAppBarToBottom); @@ -172,7 +171,7 @@ class _ViewerSettingPanelState extends State { ), _checkBox( value: Settings.showSlider, - title: locale.Translations.of(context).trans('showslider'), + title: locale.Translations.instance!.trans('showslider'), enabled: Settings.moveToAppBarToBottom, onChanged: (value) async { await Settings.setShowSlider(!Settings.showSlider); @@ -184,8 +183,7 @@ class _ViewerSettingPanelState extends State { ), _checkBox( value: Settings.showPageNumberIndicator, - title: - locale.Translations.of(context).trans('showpagenumberindicator'), + title: locale.Translations.instance!.trans('showpagenumberindicator'), onChanged: (value) async { await Settings.setShowPageNumberIndicator( !Settings.showPageNumberIndicator); @@ -197,7 +195,7 @@ class _ViewerSettingPanelState extends State { ), if (!Platform.isIOS) _checkBox( - title: locale.Translations.of(context).trans('disablefullscreen'), + title: locale.Translations.instance!.trans('disablefullscreen'), value: !Settings.disableFullScreen, onChanged: (value) async { await Settings.setDisableFullScreen(!Settings.disableFullScreen); @@ -230,29 +228,29 @@ class _ViewerSettingPanelState extends State { ), PopupMenuItem( value: 1, - child: Text(locale.Translations.of(context).trans('high')), + child: Text(locale.Translations.instance!.trans('high')), ), PopupMenuItem( value: 2, - child: Text(locale.Translations.of(context).trans('middle')), + child: Text(locale.Translations.instance!.trans('middle')), ), PopupMenuItem( value: 3, - child: Text(locale.Translations.of(context).trans('low')), + child: Text(locale.Translations.instance!.trans('low')), ), ], child: ListTile( dense: true, title: Text( - locale.Translations.of(context).trans('imgquality'), + locale.Translations.instance!.trans('imgquality'), style: const TextStyle(color: Colors.white), ), trailing: Text( [ 'None', - locale.Translations.of(context).trans('high'), - locale.Translations.of(context).trans('middle'), - locale.Translations.of(context).trans('low') + locale.Translations.instance!.trans('high'), + locale.Translations.instance!.trans('middle'), + locale.Translations.instance!.trans('low') ][imgqualityOption], style: const TextStyle(color: Colors.white), ), @@ -270,29 +268,29 @@ class _ViewerSettingPanelState extends State { itemBuilder: (BuildContext context) => >[ PopupMenuItem( value: 0, - child: Text(locale.Translations.of(context).trans('large')), + child: Text(locale.Translations.instance!.trans('large')), ), PopupMenuItem( value: 1, - child: Text(locale.Translations.of(context).trans('middle')), + child: Text(locale.Translations.instance!.trans('middle')), ), PopupMenuItem( value: 2, - child: Text(locale.Translations.of(context).trans('small')), + child: Text(locale.Translations.instance!.trans('small')), ), ], child: ListTile( dense: true, title: Text( - locale.Translations.of(context).trans('thumbnailslidersize'), + locale.Translations.instance!.trans('thumbnailslidersize'), style: const TextStyle(color: Colors.white), ), trailing: Text( [ - locale.Translations.of(context).trans('verylarge'), - locale.Translations.of(context).trans('large'), - locale.Translations.of(context).trans('middle'), - locale.Translations.of(context).trans('small') + locale.Translations.instance!.trans('verylarge'), + locale.Translations.instance!.trans('large'), + locale.Translations.instance!.trans('middle'), + locale.Translations.instance!.trans('small') ][Settings.thumbSize], style: const TextStyle(color: Colors.white), ), @@ -300,7 +298,7 @@ class _ViewerSettingPanelState extends State { ), _checkBox( value: Settings.showRecordJumpMessage, - title: locale.Translations.of(context).trans('showrecordjumpmessage'), + title: locale.Translations.instance!.trans('showrecordjumpmessage'), onChanged: (value) { Settings.setShowRecordJumpMessage(!Settings.showRecordJumpMessage); setState(() {}); diff --git a/violet/lib/pages/viewer/viewer_page.dart b/violet/lib/pages/viewer/viewer_page.dart index d33773197..84b204bf8 100644 --- a/violet/lib/pages/viewer/viewer_page.dart +++ b/violet/lib/pages/viewer/viewer_page.dart @@ -275,10 +275,10 @@ class _ViewerPageState extends State { if (!mounted) return; final isJump = await showYesNoDialog( context, - locale.Translations.of(context) + locale.Translations.instance! .trans('recordmessage') .replaceAll('%s', e.lastPage().toString()), - locale.Translations.of(context).trans('record'), + locale.Translations.instance!.trans('record'), ); if (!isJump) return; diff --git a/violet/lib/update/update_manager.dart b/violet/lib/update/update_manager.dart index 277ddc7c2..7726ef3b2 100644 --- a/violet/lib/update/update_manager.dart +++ b/violet/lib/update/update_manager.dart @@ -46,7 +46,7 @@ class UpdateManager { Future.delayed(const Duration(milliseconds: 100)).then((value) async { if (UpdateSyncManager.updateRequire) { var bb = await showYesNoDialog(context, - '${Translations.of(context).trans('newupdate')} ${UpdateSyncManager.updateMessage} ${Translations.of(context).trans('wouldyouupdate')}'); + '${Translations.instance!.trans('newupdate')} ${UpdateSyncManager.updateMessage} ${Translations.instance!.trans('wouldyouupdate')}'); if (bb == false) return; } else { return; From 1a3cf5876a567bccda1f2b9e86ac2d8cc537dffb Mon Sep 17 00:00:00 2001 From: violet-dev Date: Sun, 8 Sep 2024 17:23:25 +0900 Subject: [PATCH 09/10] Enable rule `avoid_unnecessary_containers` --- violet/analysis_options.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/violet/analysis_options.yaml b/violet/analysis_options.yaml index f5e2f88c5..3aae0169b 100644 --- a/violet/analysis_options.yaml +++ b/violet/analysis_options.yaml @@ -29,6 +29,7 @@ linter: always_use_package_imports: true unrelated_type_equality_checks: true use_build_context_synchronously: true + avoid_unnecessary_containers: true analyzer: errors: From 59b1a876cde09b20529ae1aefddf6b9155bf71d7 Mon Sep 17 00:00:00 2001 From: violet-dev Date: Sun, 8 Sep 2024 17:25:00 +0900 Subject: [PATCH 10/10] Enable rule `sized_box_for_whitespace` --- violet/analysis_options.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/violet/analysis_options.yaml b/violet/analysis_options.yaml index 3aae0169b..f3343d4b3 100644 --- a/violet/analysis_options.yaml +++ b/violet/analysis_options.yaml @@ -30,6 +30,7 @@ linter: unrelated_type_equality_checks: true use_build_context_synchronously: true avoid_unnecessary_containers: true + sized_box_for_whitespace: true analyzer: errors: