main.dart 1.73 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 11 12 13 14
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter_driver/driver_extension.dart';

import 'src/system_navigation.dart';
import 'src/test_step.dart';

void main() {
  enableFlutterDriverExtension();
15
  runApp(TestApp());
16 17 18 19
}

class TestApp extends StatefulWidget {
  @override
20
  _TestAppState createState() => _TestAppState();
21 22 23 24 25 26 27 28 29 30 31 32 33 34
}

class _TestAppState extends State<TestApp> {
  static final List<TestStep> steps = <TestStep>[
    () => systemNavigatorPop(),
  ];
  Future<TestStepResult> _result;
  int _step = 0;

  void _executeNextStep() {
    setState(() {
      if (_step < steps.length)
        _result = steps[_step++]();
      else
35
        _result = Future<TestStepResult>.value(TestStepResult.complete);
36 37 38 39 40 41 42
    });
  }

  Widget _buildTestResultWidget(
    BuildContext context,
    AsyncSnapshot<TestStepResult> snapshot,
  ) {
43
    return TestStepResult.fromSnapshot(snapshot).asWidget(context);
44 45 46 47
  }

  @override
  Widget build(BuildContext context) {
48
    return MaterialApp(
49
      title: 'Platform Interaction Test',
50 51
      home: Scaffold(
        appBar: AppBar(
52 53
          title: const Text('Platform Interaction Test'),
        ),
54
        body: Padding(
55
          padding: const EdgeInsets.all(20.0),
56
          child: FutureBuilder<TestStepResult>(
57 58 59 60
            future: _result,
            builder: _buildTestResultWidget,
          ),
        ),
61
        floatingActionButton: FloatingActionButton(
62 63 64 65 66 67 68 69
          key: const ValueKey<String>('step'),
          onPressed: _executeNextStep,
          child: const Icon(Icons.navigate_next),
        ),
      ),
    );
  }
}