main.dart 4.1 KB
Newer Older
1 2 3 4 5 6 7 8
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

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

void main() {
9 10 11 12 13 14
  // enableFlutterDriverExtension() will disable keyboard,
  // which is required for flutter_driver tests
  // But breaks the XCUITests
  if (const bool.fromEnvironment('ENABLE_DRIVER_EXTENSION')) {
    enableFlutterDriverExtension();
  }
15
  runApp(const MyApp());
16 17 18 19
}

/// The main app entrance of the test
class MyApp extends StatelessWidget {
20
  const MyApp({super.key});
21

22 23 24 25 26 27 28 29 30 31 32 33
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

34
/// A page with several buttons in the center.
35 36 37
///
/// On press the button, a page with platform view should be pushed into the scene.
class MyHomePage extends StatefulWidget {
38
  const MyHomePage({super.key, this.title});
39
  final String? title;
40 41

  @override
42
  State<MyHomePage> createState() => _MyHomePageState();
43 44 45 46 47 48 49
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
50
        title: Text(widget.title ?? ''),
51 52
      ),
      body: Column(children: <Widget>[
53
        TextButton(
54 55 56 57 58
          key: const ValueKey<String>('platform_view_button'),
          child: const Text('show platform view'),
          onPressed: () {
            Navigator.push(
              context,
59 60
              MaterialPageRoute<MergeThreadTestPage>(
                  builder: (BuildContext context) => const MergeThreadTestPage()),
61 62 63 64
            );
          },
        ),
        // Push this button to perform an animation, which ensure the threads are unmerged after the animation.
65
        ElevatedButton(
66 67 68 69
          key: const ValueKey<String>('unmerge_button'),
          child: const Text('Tap to unmerge threads'),
          onPressed: () {},
        ),
70 71 72 73 74 75 76 77 78 79 80
        TextButton(
          key: const ValueKey<String>('platform_view_focus_test'),
          child: const Text('platform view focus test'),
          onPressed: () {
            Navigator.push(
              context,
              MaterialPageRoute<FocusTestPage>(
                  builder: (BuildContext context) => const FocusTestPage()),
            );
          },
        ),
81 82 83 84 85
      ]),
    );
  }
}

86 87 88
/// A page to test thread merge for platform view.
class MergeThreadTestPage extends StatelessWidget {
  const MergeThreadTestPage({super.key});
89 90

  static Key button = const ValueKey<String>('plus_button');
91 92 93 94 95

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
96
        title: const Text('Platform View Thread Merge Tests'),
97 98 99
      ),
      body: Column(
        children: <Widget>[
100 101
          const Expanded(
            child: SizedBox(
102
              width: 300,
103
              child: UiKitView(viewType: 'platform_view'),
104
            ),
105
          ),
106
          ElevatedButton(
107 108 109
            key: button,
            child: const Text('button'),
            onPressed: (){},
110
          ),
111 112 113 114 115
        ],
      ),
    );
  }
}
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156

/// A page to test platform view focus.
class FocusTestPage extends StatefulWidget {
  const FocusTestPage({super.key});

  @override
  State<FocusTestPage> createState() => _FocusTestPageState();
}

class _FocusTestPageState extends State<FocusTestPage> {

  late TextEditingController _controller;

  @override
  void initState() {
    super.initState();
    _controller = TextEditingController();
    _controller.text = 'Flutter Text Field';
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Platform View Focus Tests'),
      ),
      body: Column(
        children: <Widget>[
          const SizedBox(
            width: 300,
            height: 50,
            child: UiKitView(viewType: 'platform_text_field'),
          ),
          TextField(
            controller: _controller,
          ),
        ],
      ),
    );
  }
}