Programming Flutter


Constructor Syntax

Book gives:

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);
  final String title;

  State<MyHomePage> createState() => _MyHomePageState();


  • “The parameter ‘key’ can’t have a value of ‘null’ because of its type, but the implicit default value is ‘null’. Try adding either an explicit non-‘null’ default value or the ‘required’”
    • Change Key to optional: Key?
    • Add required before this.title

Integration Testing

Dart null safety means you have to use generated code for mocking now.

import 'package:flutter_test/flutter_test.dart';
import 'package:http/http.dart' as http;
import 'package:mockito/annotations.dart';
import 'package:mockito/mockito.dart';
import 'package:xckd_app/main.dart';
import 'dart:io';

@GenerateNiceMocks([MockSpec<http.Client>(), MockSpec<File>()])
import 'unit_test.mocks.dart';

const comics = [/* ... */];

void main() {
  test("get latest comic number", () async {
    var latestComicNumberFile = MockFile();
    var latestComicNumberExists = false;

        .thenAnswer((_) {
      return Future.value(comics[1]);

      await getLatestComicNumber(
        httpClient: mockHttp,
        latestComicNFile: latestComicNumberFile,