From 3bee91f5323f1bcfb7add1adcc5c052ac098ca66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A5=9E=E6=A5=BD=E5=9D=82=E8=8A=B1=E7=81=AB?= Date: Mon, 23 Mar 2020 18:04:11 +0800 Subject: [PATCH] Optimize Collections --- lib/pages/about.dart | 4 ++-- lib/pages/details.dart | 9 ++++----- pubspec.yaml | 2 +- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/lib/pages/about.dart b/lib/pages/about.dart index c737468..39fbeb0 100644 --- a/lib/pages/about.dart +++ b/lib/pages/about.dart @@ -348,7 +348,7 @@ class _AboutPageState extends State { Future> _fetchData() async { List result = []; - List ids = Settings.marked; + List ids = Settings.marked.reversed.toList(); if (ids.isEmpty) { return result; } @@ -359,7 +359,7 @@ class _AboutPageState extends State { } for (int i = 0; i < ids.length; i++) { - result.add(await TujianApi.getDetails(ids[i])); + result.add((await TujianApi.getDetails(ids[i]))..marked = true); } AppModel.of(context).collections = result; return result; diff --git a/lib/pages/details.dart b/lib/pages/details.dart index 80999bc..cf28813 100644 --- a/lib/pages/details.dart +++ b/lib/pages/details.dart @@ -12,7 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -import 'dart:collection'; import 'dart:io'; import 'dart:math' as math; import 'dart:typed_data'; @@ -414,13 +413,13 @@ class _DetailsPageState extends State { } else { data.marked = !data.marked; } - HashSet hashSet = HashSet.from(Settings.marked); + List list = List.from(Settings.marked); if (data.marked) { - hashSet.add(data.id); + list.add(data.id); } else { - hashSet.remove(data.id); + list.remove(data.id); } - Settings.marked = hashSet.toList(); + Settings.marked = list.toList(); AppModel.of(context).collections = []; setState(() {}); } diff --git a/pubspec.yaml b/pubspec.yaml index 2628827..91044f9 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: dailypics description: A new Flutter application. -version: 2.1.4+200314 +version: 2.1.6+200322 environment: sdk: ">=2.3.0 <3.0.0"