Chapter 3

  1. Which is the cross-axis for a GridView scrolling vertically?

    If the main axis is vertical, the cross axis is horizontal.

  2. How do you retrieve a value from SharedPreferences?

    After creating an instance of SharedPreferences, you can call one of its methods, like getInt or getString, passing the key. This will retrieve its value. An example is shown in the following code block:

prefs = await SharedPreferences.getInstance();
int workTime = prefs.getInt(WORKTIME);
  1. Which instruction would you use to retrieve the width of the screen?

    You can use the MediaQuery.of(context).size.width instruction to get the width of the screen.

  2. How do you open another screen on your app?

    You can call the push() method of the Navigator to add a route to the navigation stack. For example:

Navigator.push(
context, MaterialPageRoute(builder: (context) =>SettingsScreen()));
}
  1. Which file contains all the dependencies of your app?

    The pubspec.yaml file contains the dependencies of your app.

  2. What's the difference between a Stream and a Future?

    A Stream is a sequence of results: any number of events can be returned in a Stream, whereas a Future only returns once.

  3. How do you change the value of a TextField?

    You can use a TextEditingController to change the values inside a TextField.

  4. How do you create a new Duration object?

    Duration is a Dart class used to contain a span of time. In order to create a Duration you call its constructor specifying the length of the duration, like in this example:

Duration(seconds: 1)
  1. How can you add a menu button to your apps?

    You can use a PopupMenuButton widget, adding it to the AppBar in the Scaffold, like this:

appBar: AppBar(
title: Text('My Work Timer'),
actions: [
PopupMenuButton<String>(
itemBuilder: (BuildContext context) {
return menuItems.toList(); },
  1. What are the steps to install an external library into your app?

    You add the dependency in the pubspec.yaml file, then you import the library at the top of the file that will use it, and finally, you can use it in your code.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.138.105.215