text_editing_main.dart 3.12 KB
Newer Older
1 2 3 4 5 6
// 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';

7
void main() => runApp(const MyApp());
8 9

class MyApp extends StatelessWidget {
10
  const MyApp({Key? key}) : super(key: key);
11

12 13 14 15 16 17 18 19 20 21 22
  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      key: Key('mainapp'),
      title: 'Integration Test App',
      home: MyHomePage(title: 'Integration Test App'),
    );
  }
}

class MyHomePage extends StatefulWidget {
23
  const MyHomePage({Key? key, this.title}) : super(key: key);
24

25
  final String? title;
26 27

  @override
28
  State<MyHomePage> createState() => _MyHomePageState();
29 30 31 32 33
}

class _MyHomePageState extends State<MyHomePage> {
  String infoText = 'no-enter';

34
  // Controller with no initial value;
35 36 37 38 39 40 41 42 43 44 45 46
  final TextEditingController _emptyController = TextEditingController();

  final TextEditingController _controller =
      TextEditingController(text: 'Text1');

  final TextEditingController _controller2 =
      TextEditingController(text: 'Text2');

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
47
        title: Text(widget.title ?? ''),
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 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 98 99 100 101 102 103 104 105 106 107 108 109 110
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            const Text(
              'Text Editing Test 1',
            ),
            TextFormField(
              key: const Key('empty-input'),
              enabled: true,
              controller: _emptyController,
              decoration: const InputDecoration(
                contentPadding: EdgeInsets.all(10.0),
                labelText: 'Empty Input Field:',
              ),
            ),
            const Text(
              'Text Editing Test 2',
            ),
            TextFormField(
              key: const Key('input'),
              enabled: true,
              controller: _controller,
              decoration: const InputDecoration(
                contentPadding: EdgeInsets.all(10.0),
                labelText: 'Text Input Field:',
              ),
            ),
            const Text(
              'Text Editing Test 3',
            ),
            TextFormField(
              key: const Key('input2'),
              enabled: true,
              controller: _controller2,
              decoration: const InputDecoration(
                contentPadding: EdgeInsets.all(10.0),
                labelText: 'Text Input Field 2:',
              ),
              onFieldSubmitted: (String str) {
                print('event received');
                setState(() => infoText = 'enter pressed');
              },
            ),
            Text(
              infoText,
              key: const Key('text'),
            ),
            const Padding(
              padding: EdgeInsets.all(12.0),
              child: SelectableText(
                'Lorem ipsum dolor sit amet',
                key: Key('selectable'),
                style: TextStyle(fontFamily: 'Roboto', fontSize: 20.0),
              ),
            ),
          ],
        ),
      ),
    );
  }
}