This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/cupertino.dart'; | |
import 'package:flutter/material.dart'; | |
void main() => runApp(MyApp()); | |
final parser = RootRouterParser(); | |
final delegate = RootRouterDelegate(); | |
const indexes = ['First', 'Second', 'Third', 'Fourth', 'Fifth']; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Future<void> loadItemsOnMainThread() async { | |
_startFpsMeter(); | |
isLoading = true; | |
notifyListeners(); | |
List<Item> mainThreadItems; | |
for (int i = 0; i < 10; i++) { | |
bench.startTimer('Load items in main thread'); | |
mainThreadItems = await makeManyRequests(5); | |
final double diff = bench.endTimer('Load items in main thread'); | |
requestDurations.add(diff); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Future<void> loadItemsWithComputed() async { | |
_startFpsMeter(); | |
isLoading = true; | |
notifyListeners(); | |
List<Item> computedItems; | |
/// There were two variants of execution | |
/// Each set of 5 concurrent requests, run sequentially, | |
/// ran in compute function | |
if (true) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// This method is the entry point to the operation | |
Future<void> loadItemsWithIsolate() async { | |
/// We start the frame counter before the whole operation | |
_startFpsMeter(); | |
isLoading = true; | |
notifyListeners(); | |
/// We start counting the request time | |
bench.startTimer('Load items in separate isolate'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Event handler [Events.startLoadingItems] | |
Future<void> _loadingItems() async { | |
_items.clear(); | |
for (int i = 0; i < 10; i++) { | |
_items.addAll(await makeManyRequests(5)); | |
if (i < (10 - 1)) { | |
/// For all requests except the last one - we send only one event | |
send(Events.loadingItems); | |
} else { | |
/// For the last of 10 requests - send a message with data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Function for creating a copy of elements | |
/// used as source for filtering | |
void cacheItems() { | |
_notFilteredItems.clear(); | |
final List<Item> multipliedItems = []; | |
for (int i = 0; i < 10; i++) { | |
multipliedItems.addAll(items); | |
} | |
_notFilteredItems.addAll(multipliedItems); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Function that launches a test script | |
/// for entering characters into a text input | |
Future<void> _testSearch() async { | |
List<String> words = items.map((Item item) => item.profile.replaceAll('https://opencollective.com/', '')).toSet().toList(); | |
words = words | |
.map((String word) { | |
final String newWord = word.substring(0, min(word.length, 3)); | |
return newWord; | |
}) | |
.toSet() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// We enter characters with a delay of 800ms, | |
/// but if the data from the asynchronous filter (computed / isolate) | |
/// has not yet arrived, then we are waiting for them | |
Future<void> _setWord(String word) async { | |
if (!canPlaceNextLetter) { | |
await wait(800); | |
await _setWord(word); | |
} else { | |
searchController.value = TextEditingValue(text: word); | |
await wait(800); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Depending on the set flag [USE_SIMILARITY] | |
/// whether or not search with string similarity is used | |
List<Item> filterItems(Packet2<List<Item>, String> itemsAndInputValue) { | |
return itemsAndInputValue.value.where((Item item) { | |
return item.profile.contains(itemsAndInputValue.value2) || (USE_SIMILARITY && isStringsSimilar(item.profile, itemsAndInputValue.value2)); | |
}).toList(); | |
} | |
bool isStringsSimilar(String first, String second) { | |
return max(StringSimilarity.compareTwoStrings(first, second), StringSimilarity.compareTwoStrings(second, first)) >= 0.3); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Future<void> runSearchOnMainThread() async { | |
cacheItems(); | |
isLoading = true; | |
notifyListeners(); | |
searchController.addListener(_searchOnMainThread); | |
await _testSearch(); | |
searchController.removeListener(_searchOnMainThread); | |
isLoading = false; | |
notifyListeners(); | |
} |
OlderNewer