Filters

Hide filters
Platform
Content Type
Difficulty

All Tutorials · 15 Results

Contained in: Dart Apprentice: Beyond the Basics strings
Flutter & Dart

Chapter in Dart Apprentice: Beyond the Basics

String Manipulation

…this chapter, you'll go beyond a basic understanding of strings and learn how to modify them to your needs. This includes basic tasks like capitalization, adding or removing whitespace, splitting and joining, and replacing text in a string. You'll also learn to validate strings and extract text using…
Flutter & Dart

Chapter in Dart Apprentice: Beyond the Basics

Generics

Generics refers to generalizing specific types like `String`, `bool` or `int` so you can handle them all the same way. This chapter will teach not only how to use generic types but also how to create new generic classes and collections…
Flutter & Dart

Chapter in Dart Apprentice: Beyond the Basics

Error Handling

…than runtime errors because they’re obvious and immediate. Format Exception Another way to crash your app is to try and decode a “JSON” string that isn’t actually in JSON format. Replace the contents of your project file with the following code: import 'dart:convert'; void main() { const malformedJson…
Flutter & Dart

Chapter in Dart Apprentice: Beyond the Basics

Futures

…focus. Add the following code below the main function: class Todo { Todo({ required this.userId, required this.id, required this.title, required this.completed, }); factory Todo.fromJson(Map<String, dynamic> jsonMap) { return Todo( userId: jsonMap['userId'] as int, id: jsonMap['id'] as int, title: jsonMap['title'] as String, completed: jsonMap['completed'] as bool…
Flutter & Dart

Chapter in Dart Apprentice: Beyond the Basics

Anonymous Functions

…without names. In fact, they’re simply values. Just as 2 is an int value, 3.14 is a double value, 'Hello world' is a String value and false is a bool value, an anonymous function is a Function value. You can assign anonymous functions to variables and pass them around…
Flutter & Dart

Chapter in Dart Apprentice: Beyond the Basics

Enhanced Enums

…provide a value besides 0, 1 or 2. This requires you to handle error cases with default. Sometimes people used similar logic but with strings instead of integers. For example, if (lightColor == 'green'). With that method, it was easy to accidentally misspell values, such as writing geen instead of green…
Flutter & Dart

Chapter in Dart Apprentice: Beyond the Basics

Extension Methods

…extension when importing it in another library. Have a look at a few of the following examples to see how extension methods work. String Extension Example Did you ever make secret codes when you were a kid, like a=1, b=2, c=3, and so on? For this example…
Flutter & Dart

Chapter in Dart Apprentice: Beyond the Basics

Isolates

…some synchronous code that puts a heavy load on the CPU. Add the following code as a top-level function to your project: String playHideAndSeekTheLongVersion() { var counting = 0; for (var i = 1; i <= 10000000000; i++) { counting = i; } return '$counting! Ready or not, here I come!'; } Counting to 10 billion…
Flutter & Dart

Chapter in Dart Apprentice: Beyond the Basics

Inheritance

Creating Similar Classes Next, create two classes named Person and Student. Here’s Person: class Person { Person(this.givenName, this.surname); String givenName; String surname; String get fullName => '$givenName $surname'; @override String toString() => fullName; } And this is Student: class Student { Student(this.givenName, this.surname); String givenName; String surname; var grades…
Flutter & Dart

Chapter in Dart Apprentice: Beyond the Basics

Streams

Latin words were taken from the writings of the Roman statesman and philosopher Cicero but modified to become essentially meaningless. Reading as a String Now that you’ve created the text file, replace your Dart code with the following: import 'dart:io'; Future<void> main() async { final file…
Flutter & Dart

Chapter in Dart Apprentice: Beyond the Basics

Interfaces

…current temperature in some city. Since those are the requirements, your Dart interface class would look like this: abstract class DataRepository { double? fetchTemperature(String city); } Note that repository is a common term to call an interface that hides the details of how data is stored and retrieved. Also, the reason…
Flutter & Dart

Chapter in Dart Apprentice: Beyond the Basics

Conclusion

…this point, you can consider yourself a solid intermediate-level developer in the Dart programming language. You understand the principles of object-oriented programming, string manipulation, generics, error handling and asynchronous programming. If you go on to develop Flutter apps or build backend servers in Dart, you shouldn’t have…
Flutter & Dart

Chapter in Dart Apprentice: Beyond the Basics

Abstract Classes

…fringes of how taxonomists make their decisions, create the following Animal class: abstract class Animal { bool isAlive = true; void eat(); void move(); @override String toString() { return "I'm a $runtimeType"; } } Here are a few important points about that code: The way you define an abstract class in Dart…
Flutter & Dart

Chapter in Dart Apprentice: Beyond the Basics

Mixins

Here’s the code you wrote for Platypus back in Chapter 3, “Inheritance”: abstract class Animal { bool isAlive = true; void eat(); void move(); @override String toString() { return "I'm a $runtimeType"; } } class Platypus extends Animal { @override void eat() { print('Munch munch'); } @override void move() { print('Glide glide'); } void layEggs() { print…
Flutter & Dart

Chapter in Dart Apprentice: Beyond the Basics

Introduction

Apprentice: Beyond the Basics, the book you have here, builds on the concepts you learned in Dart Apprentice: Fundamentals and introduces new topics like string manipulation, anonymous functions, inheritance, interfaces, generics, error handling and asynchronous programming. If you complete this book, you can consider yourself a solid intermediate-level programmer…