在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
code import 'dart:io'; import 'dart:core'; import 'dart:collection'; import 'dart:async'; void main() { var lst = new List(); lst.add(3); lst.add(4); print(lst); print("-----------"); List<int> nameOfTest = List(3); nameOfTest[0] = 1; nameOfTest[1] = 2; nameOfTest[2] = 3; print(nameOfTest); print("-----------"); for(int element in nameOfTest){ print(element); } print("-----------"); nameOfTest.forEach((v) => print('${v}')); print("-----------"); for(int i = 0; i < nameOfTest.length; i++){ print(nameOfTest[i]); } print("-----------"); List<String> names = List(); names.add("Mana"); names.add("Babu"); names.add("Gopal"); names.add("Pota"); print(names); print("-----------"); var number1 = 1; var number2 = 1; while(number2 < 50){ print(number2); number2 += number1; number1 = number2 - number1; } print("Separator line: ============="); var fibonacciNumbers = [1, 2, 3, 5, 8, 13, 21, 34]; print(fibonacciNumbers.take(3).toList()); print("Separator line: ============="); print(fibonacciNumbers.skip(5).toList()); print("Separator line: ============="); print(fibonacciNumbers.skip(2).contains(5)); print("Separator line: ============="); print(fibonacciNumbers.take(3).skip(2).take(1).toList()); print("Separator line: ============="); var clonedFibonacciNumbers = List.from(fibonacciNumbers); print("Cloned list: $clonedFibonacciNumbers"); print("-----------"); var names1 = ["John", "Robert", "Smith", "Peter"]; names1.forEach((name) => print(name)); print("-----------"); var mappedNames = names.map((name) => "Absconding $name").toList(); print(mappedNames); print("-----------"); Set<String> countries = Set.from(['India', 'England', 'US']); for(String element in countries){ print(element); } Set<int> numbers = Set.from([1, 45, 58]); for(int element in numbers){ print(element); } Set<int> moreNumbers = Set(); moreNumbers.add(178); moreNumbers.add(568); moreNumbers.add(569); print(moreNumbers); print("-----------"); countries.forEach((v) => print('haha_${v}')); for(int element in moreNumbers){ if(moreNumbers.lookup(element) == 568){ print(element); break; } print("xixi"+(moreNumbers.lookup(element)).toString()); } print("-----------"); var fruitCollection = {'Mango', 'Apple', 'Jack fruit'}; print(fruitCollection.lookup('Something Else')); //lists List fruitCollections = ['Mango', 'Apple', 'Jack fruit']; var myIntegers = [1, 2, 3, '4monkey']; print(myIntegers[3]); print(fruitCollections[0]); print("-----------"); Map<String, String> countries1 = Map(); countries1['India'] = "Asia"; countries1["Germany"] = "Europe"; countries1["France"] = "Europe"; countries1["Brazil"] = "South America"; for(var key in countries1.keys){ print("Country's name: $key"); } for(String value in countries1.values){ print("Continent's name: $value"); } print("-----------"); countries1.forEach((key, value) => print("Country: $key and Continent: $value")); if(countries1.containsKey("Germany")){ countries1.update("Germany", (value) => "European Union"); print("Updated country Germany."); countries1.forEach((key, value) => print("Country: $key and Continent: $value")); } print("-----------"); countries1.remove("Brazil"); countries1.forEach((key, value) => print("Country: $key and Continent: $value")); print("-----------"); Map<String, int> telephoneNumbersOfCustomers = {"John" : 1234, "Mac" : 7534, "Molly" : 8934, "Plywod" : 1275, "Hagudu" : 2534}; telephoneNumbersOfCustomers.forEach((key, value) =>print("Customer: $key and Contact Number: $value")); print("-----------"); for(var key in countries1.keys){ print("Country's name: $key"); } print("-----------"); for(String value in countries1.values){ print("Continent's name: $value"); } countries1.forEach((key, value) => print("Country: $key and Continent: $value")); print("-----------"); List<Map<String, dynamic>> users = [{ "name": "Peters", "age": 18 }, { "name": "Miras", "age": 20 }, { "name": "Jasons", "age": 22 }]; var is18AndOver = users.every((user) => user["age"] > 20); print(is18AndOver); var is19AndOver = users.every((user) => user["age"] >= 18); print(is19AndOver); var hasNamesWithLetterA = users.every((user) => user.toString().startsWith("A")); print(hasNamesWithLetterA); var hasNamesWithLetterB = users.every((user) => user["name"].endsWith("s")); print(hasNamesWithLetterB); users.forEach((user) => print(user)); print(users); var overTwentyOne = users.where((user) => user["age"] > 21); print(overTwentyOne); print(overTwentyOne.length); var underEighteen = users.singleWhere((user) => user["age"] < 18, orElse: () => null); print(underEighteen); print("-----------"); List nums = [1, 2, 3, 4, 5, 6]; print(nums.take(0)); print(nums.take(5)); print("-----------"); print(nums.takeWhile((element) => element < 5)); print("-----------"); print(nums.skip(4)); print("-----------"); print(nums.skipWhile((element) => element <= 3)); print("-----------"); print(nums.toList(growable:false)); print("-----------"); List nums111 = [1, 2, 1]; print(nums111.toSet()); print("-----------"); nums = [1, 2, 3]; print(nums.reduce((sum, element) => sum + element)); print("-----------"); nums = [1, 2, 3]; print(nums.join(' - ')); print("-----------"); List<int> list44 = [1, 2, 3, 4, 5]; int result10 = list44.fold(2, (a,element)=>(a+element)); print(result10); int result11 = list44.fold(2, (a,element)=>(a*element)); print(result11); print("-----------"); Iterable generated = new Iterable.generate(4, (count) => "int $count"); print(generated); generated = new Iterable.generate(4); print(generated); print("-----------"); nums = [1, 2, 3]; print('Get Iterable for $nums'); ///返回奇数 Iterable iterable = nums.where((i) { print('Fetched $i'); return i.isOdd; }); print('Start fetching'); iterable.forEach((i) { print("Received $i"); }); print("-----------"); Queue myQueue = new Queue(); print("Default implementation ${myQueue.runtimeType}"); myQueue.add("Sanjib"); myQueue.add(54); myQueue.add("Howrah"); myQueue.add("[email protected]"); for(var allTheValues in myQueue){ print(allTheValues); } print("----------"); print("We are removing the first element ${myQueue.elementAt(0)}."); myQueue.removeFirst(); for(var allTheValues in myQueue){ print(allTheValues); } print("----------"); print("We are removing the last element ${myQueue. elementAt(2 )}."); myQueue.removeLast(); for(var allTheValues in myQueue){ print(allTheValues); } print("-----------"); var withoutArgument = CallableClassWithoutArgument(); var withArgument = CallableClassWithArgument(); withoutArgument(); print(withArgument("John Smith")); print(withArgument.call("Calling John Smith")); print("-----------"); var John = Person(); John.name = "John Smith"; String name = John.name; String msgAndName = John("Hi John how are you?", name); print(msgAndName); print("-----------"); Future<String> checkingNewsApp() { Future<String> delayingTenSeconds = Future.delayed(Duration(seconds: 10), (){ return "The latest headlines are displayed here after 10 seconds."; }); return delayingTenSeconds; } void displayNews() { Future<String> displayingNewsHeadlines = checkingNewsApp(); displayingNewsHeadlines.then((displayString){ print("Displaying news headlines here: $displayingNewsHeadlines"); }); } print("The main UI thread is starting on here."); print("Now it will take 10 seconds to display news headlines."); displayNews(); print("The main UI thread ends."); print("-----------"); Future checkVersion() async { var version = await checkVersion(); // Do something with version try { return version; } catch (e) { return e; } } print(checkVersion()); } class CallableClassWithoutArgument { String output = "Callable class"; void call() { print(output); } } class CallableClassWithArgument { call(String name) => "$name"; } class Person{ String name; String call(String message, [name]){ return "This message: '$message', has been passed to the person $name."; } }
|
请发表评论