stepping_project.dart 2.62 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
2 3 4 5 6 7 8 9 10
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'project.dart';

class SteppingProject extends Project {
  @override
  final String pubspec = '''
  name: test
11
  environment:
12
    sdk: '>=2.12.0-0 <3.0.0'
13 14 15 16 17 18 19 20 21 22 23
  dependencies:
    flutter:
      sdk: flutter
  ''';

  @override
  final String main = r'''
  import 'dart:async';

  import 'package:flutter/material.dart';

24
  void main() => runApp(MyApp());
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39

  class MyApp extends StatefulWidget {
    @override
    _MyAppState createState() => _MyAppState();
  }

  class _MyAppState extends State<MyApp> {
    @override
    void initState() {
      doAsyncStuff();
      super.initState();
    }

    Future<void> doAsyncStuff() async {
      print("test"); // BREAKPOINT
40 41 42
      await Future.value(true); // STEP 1 // STEP 2
      await Future.microtask(() => true); // STEP 3 // STEP 4
      await Future.delayed(const Duration(milliseconds: 1)); // STEP 5 // STEP 6
43 44
      print("done!"); // STEP 7
    } // STEP 8
45 46 47

    @override
    Widget build(BuildContext context) {
48
      return MaterialApp(
49
        title: 'Flutter Demo',
50
        home: Container(),
51 52 53 54 55
      );
    }
  }
  ''';

56 57
  Uri get breakpointUri => mainDart;
  int get breakpointLine => lineContaining(main, '// BREAKPOINT');
58 59
  int lineForStep(int i) => lineContaining(main, '// STEP $i');

60
  final int numberOfSteps = 8;
61
}
62 63 64 65 66

class WebSteppingProject extends Project {
  @override
  final String pubspec = '''
  name: test
67 68
  environment:
    sdk: '>=2.10.0 <3.0.0'
69 70 71 72 73 74 75 76 77 78 79
  dependencies:
    flutter:
      sdk: flutter
  ''';

  @override
  final String main = r'''
  import 'dart:async';

  import 'package:flutter/material.dart';

80
  void main() => runApp(MyApp());
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95

  class MyApp extends StatefulWidget {
    @override
    _MyAppState createState() => _MyAppState();
  }

  class _MyAppState extends State<MyApp> {
    @override
    void initState() {
      doAsyncStuff();
      super.initState();
    }

    Future<void> doAsyncStuff() async {
      print("test"); // BREAKPOINT
96 97 98
      await Future.value(true); // STEP 1
      await Future.microtask(() => true); // STEP 2
      await Future.delayed(const Duration(milliseconds: 1));  // STEP 3
99 100 101 102 103
      print("done!"); // STEP 4
    } // STEP 5

    @override
    Widget build(BuildContext context) {
104
      return MaterialApp(
105
        title: 'Flutter Demo',
106
        home: Container(),
107 108 109 110 111 112 113 114 115 116 117
      );
    }
  }
  ''';

  Uri get breakpointUri => mainDart;
  int get breakpointLine => lineContaining(main, '// BREAKPOINT');
  int lineForStep(int i) => lineContaining(main, '// STEP $i');

  final int numberOfSteps = 5;
}