…this chapter, you’ll learn about strings and the way Dart represents text and characters using Unicode. You’ll also learn about concatenation and interpolation…
Flutter & Dart
Chapter in Dart Apprentice: Fundamentals
Nullability
Nov 2 2022 · Chapter
Here are some example values that non-nullable types could contain: int: 3, 1, 7, 4, 5 double: 3.14159265, 0.001, 100.5 bool: true, false String: 'a', 'hello', 'Would you like fries with that?' User: ray, vicki, anonymous These are all acceptable ways to set the values: int myInt = 1; double…
Flutter & Dart
Chapter in Dart Apprentice: Fundamentals
Maps
Nov 2 2022 · Chapter
…value. You can create an empty map variable using Map and specifying the type for both the key and value: final Map<String, int> emptyMap = {}; In this example, String is the type for the key, and int is the type for the value. A slightly shorter…
Flutter & Dart
Chapter in Dart Apprentice: Fundamentals
Functions
Nov 2 2022 · Chapter
Dart Function In Dart, a function consists of a return type, a name, a parameter list in parentheses and a body enclosed in braces. String compliment (int number) { } '$number is a very nice number.'; return Return value Return type Parameter type Function name Parameter name Here is a summary…
Flutter & Dart
Chapter in Dart Apprentice: Fundamentals
Classes
Nov 2 2022 · Chapter
…this book, you’ve used built-in types such as int, String and bool. You’ve also seen one way to make custom types using enum. In this chapter, you’ll learn a more flexible way to create types by using classes. Note: Because there’s quite…
Flutter & Dart
Chapter in Dart Apprentice: Fundamentals
Lists
Nov 2 2022 · Chapter
…called a list literal. Write the following line in main: var desserts = ['cookies', 'cupcakes', 'donuts', 'pie']; Because all the elements in this list are strings, Dart infers this to be a list of String types. You can reassign desserts (but why would one ever want to reassign desserts?) with…
Flutter & Dart
Chapter in Dart Apprentice: Fundamentals
Constructors
Nov 2 2022 · Chapter
…class you wrote in Chapter 8, “Classes”. Here’s the code you had at the end of that chapter: class User { int id = 0; String name = ''; String toJson() { return '{"id":$id,"name":"$name"}'; } @override String toString() { return 'User(id: $id, name: $name)'; } } Copy that to your project below the main…
Flutter & Dart
Chapter in Dart Apprentice: Fundamentals
Control Flow
Nov 2 2022 · Chapter
…learn how to make decisions in your programs. Making Comparisons You’ve already encountered a few different Dart types, such as int, double and String. Each of those types is a data structure that’s designed to hold a particular type of data. The int type is for integers while…
Flutter & Dart
Chapter in Dart Apprentice: Fundamentals
Types & Operations
Nov 2 2022 · Chapter
…plan to use some data. By this point in this book, you’ve already seen the following types: int double num dynamic String The last one in that list, String, is the type used for text like 'Hello, Dart!'. Just as you don’t brush your teeth with ice cream…
Flutter & Dart
Chapter in Dart Apprentice: Fundamentals
Sets
Nov 2 2022 · Chapter
…someSet = {}; The generic syntax with int in angle brackets tells Dart the set allows only integers. You could just as easily make the type String or bool or double, though. The following form is shorter but identical in result: final someSet = <int>{}; The curly braces are the same…
Flutter & Dart
Chapter in Dart Apprentice: Fundamentals
Static Members
Nov 2 2022 · Chapter
…chapter with the fromJson factory constructor. Here’s the fromJson factory constructor from the User class in Chapter 9, “Constructors”: factory User.fromJson(Map<String, Object> json) { final userId = json['id'] as int; final userName = json['name'] as String; return User(id: userId, name: userName); } And here…
Flutter & Dart
Chapter in Dart Apprentice: Fundamentals
Iterables
Nov 2 2022 · Chapter
…type annotation as Iterable and then assigning the variable a list value. Replace the myIterable line you wrote earlier with the following: Iterable<String> myIterable = ['red', 'blue', 'green']; The actual implementation is a list, which you know because of the square brackets. But by explicitly writing Iterable…
Flutter & Dart
Chapter in Dart Apprentice: Fundamentals
Hello, Dart!
Nov 2 2022 · Chapter
…directory, and you’ll see it contains the following code: import 'package:hello_dart/hello_dart.dart' as hello_dart; void main(List<String> arguments) { print('Hello world: ${hello_dart.calculate()}!'); } You don’t need to know how all of that works yet, but here are a few notes: The line beginning with…
Flutter & Dart
Chapter in Dart Apprentice: Fundamentals
Conclusion
Nov 2 2022 · Chapter
Beyond the Basics, will build on this foundation to move you to the intermediate level. Here are some topics that you’ll learn: Advanced string manipulation using regular expressions. Functions as inputs and outputs of other functions. Object-oriented programming concepts like inheritance, abstraction and interfaces. Asynchronous programming with futures…
Flutter & Dart
Chapter in Dart Apprentice: Fundamentals
Expressions, Variables & Constants
Nov 2 2022 · Chapter
…myNumber = 'ten'; // No, no, no. The num type can be either an int or a double, so the first two assignments work. However, the string value 'ten' is of a different type, so the compiler complains. Now, if you like living dangerously, you can throw safety to the wind…
Flutter & Dart
Chapter in Dart Apprentice: Fundamentals
Introduction
Nov 2 2022 · Chapter
…upper-beginner level. The second book, Dart Apprentice: Beyond the Basics, will build on the concepts you learn here and introduce new topics like string manipulation, anonymous functions, inheritance, interfaces, generics, error handling and asynchronous programming. If you complete that book, you can consider yourself a solid intermediate-level programmer…