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

5 6
// @dart = 2.8

7 8 9 10 11 12
import 'project.dart';

class SteppingProject extends Project {
  @override
  final String pubspec = '''
  name: test
13
  environment:
14
    sdk: '>=2.12.0-0 <3.0.0'
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
  dependencies:
    flutter:
      sdk: flutter
  ''';

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

  import 'package:flutter/material.dart';

  void main() => runApp(new MyApp());

  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
42 43 44 45 46
      await new Future.value(true); // STEP 1 // STEP 2
      await new Future.microtask(() => true); // STEP 3 // STEP 4
      await new Future.delayed(const Duration(milliseconds: 1)); // STEP 5 // STEP 6
      print("done!"); // STEP 7
    } // STEP 8
47 48 49 50 51 52 53 54 55 56 57

    @override
    Widget build(BuildContext context) {
      return new MaterialApp(
        title: 'Flutter Demo',
        home: new Container(),
      );
    }
  }
  ''';

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

62
  final int numberOfSteps = 8;
63
}
64 65 66 67 68

class WebSteppingProject extends Project {
  @override
  final String pubspec = '''
  name: test
69 70
  environment:
    sdk: '>=2.10.0 <3.0.0'
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
  dependencies:
    flutter:
      sdk: flutter
  ''';

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

  import 'package:flutter/material.dart';

  void main() => runApp(new MyApp());

  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
98 99
      await new Future.value(true); // STEP 1
      await new Future.microtask(() => true); // STEP 2
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
      await new Future.delayed(const Duration(milliseconds: 1));  // STEP 3
      print("done!"); // STEP 4
    } // STEP 5

    @override
    Widget build(BuildContext context) {
      return new MaterialApp(
        title: 'Flutter Demo',
        home: new Container(),
      );
    }
  }
  ''';

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

  final int numberOfSteps = 5;
}