mirror of
https://github.com/rainloreley/shlink-manager.git
synced 2024-11-23 10:13:03 +01:00
fixed bug with newly created tags
This commit is contained in:
parent
8507aaa8bd
commit
21042fa2b7
|
@ -1,5 +1,6 @@
|
||||||
import 'package:dynamic_color/dynamic_color.dart';
|
import 'package:dynamic_color/dynamic_color.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:shlink_app/API/Classes/ShortURL/visits_summary.dart';
|
||||||
import 'package:shlink_app/API/Classes/Tag/tag_with_stats.dart';
|
import 'package:shlink_app/API/Classes/Tag/tag_with_stats.dart';
|
||||||
import 'package:shlink_app/util/build_api_error_snackbar.dart';
|
import 'package:shlink_app/util/build_api_error_snackbar.dart';
|
||||||
import 'package:shlink_app/util/string_to_color.dart';
|
import 'package:shlink_app/util/string_to_color.dart';
|
||||||
|
@ -49,7 +50,10 @@ class _TagSelectorViewState extends State<TagSelectorView> {
|
||||||
|
|
||||||
List<TagWithStats> mappedAlreadySelectedTags =
|
List<TagWithStats> mappedAlreadySelectedTags =
|
||||||
widget.alreadySelectedTags.map((e) {
|
widget.alreadySelectedTags.map((e) {
|
||||||
return l.firstWhere((t) => t.tag == e);
|
return l.firstWhere((t) => t.tag == e, orElse: () {
|
||||||
|
// account for newly created tags
|
||||||
|
return TagWithStats(e, 0, VisitsSummary(0,0,0));
|
||||||
|
});
|
||||||
}).toList();
|
}).toList();
|
||||||
|
|
||||||
setState(() {
|
setState(() {
|
||||||
|
@ -71,8 +75,8 @@ class _TagSelectorViewState extends State<TagSelectorView> {
|
||||||
|
|
||||||
void _sortLists() {
|
void _sortLists() {
|
||||||
setState(() {
|
setState(() {
|
||||||
availableTags.sort();
|
availableTags.sort((a, b) => a.tag.compareTo(b.tag));
|
||||||
filteredTags.sort();
|
filteredTags.sort((a, b) => a.tag.compareTo(b.tag));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,11 +95,12 @@ class _TagSelectorViewState extends State<TagSelectorView> {
|
||||||
}
|
}
|
||||||
|
|
||||||
void _addNewTag(String tag) {
|
void _addNewTag(String tag) {
|
||||||
if (tag != "" && !availableTags.contains(tag)) {
|
bool tagExists = availableTags.where((t) => t.tag == tag).toList().isNotEmpty;
|
||||||
TagWithStats _tagWithStats = availableTags.firstWhere((e) => e.tag == tag);
|
if (tag != "" && !tagExists) {
|
||||||
|
TagWithStats tagWithStats = TagWithStats(tag, 0, VisitsSummary(0, 0, 0));
|
||||||
setState(() {
|
setState(() {
|
||||||
availableTags.add(_tagWithStats);
|
availableTags.add(tagWithStats);
|
||||||
selectedTags.add(_tagWithStats);
|
selectedTags.add(tagWithStats);
|
||||||
_searchTextChanged(tag);
|
_searchTextChanged(tag);
|
||||||
});
|
});
|
||||||
_sortLists();
|
_sortLists();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user