test_input.dart 4.01 KB
Newer Older
Yacumima's avatar
dev  
Yacumima committed
1 2 3
import 'package:flutter/material.dart';

class TestPage extends StatefulWidget {
4 5 6 7
  const TestPage({
    Key key,
    this.title = 'Input Test',
  }) : super(key: key);
Yacumima's avatar
dev  
Yacumima committed
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26

  final String title;

  @override
  _TestPageState createState() => _TestPageState();
}

class _TestPageState extends State<TestPage> {
  int _counter = 0;

  void _incrementCounter() {
    setState(() {
      _counter++;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
27
      appBar: AppBar(title: Text(widget.title)),
Yacumima's avatar
dev  
Yacumima committed
28
      body: SafeArea(
29 30 31 32 33 34 35 36 37
        bottom: false,
        child: ListView(
          children: <Widget>[
            Container(
              child: const Text(
                'You have pushed the button this many times:',
              ),
              margin: const EdgeInsets.all(8.0),
              alignment: Alignment.center,
Yacumima's avatar
dev  
Yacumima committed
38
            ),
39 40 41 42 43 44 45
            Container(
              child: Text(
                '$_counter',
                style: Theme.of(context).textTheme.display1,
              ),
              margin: const EdgeInsets.all(8.0),
              alignment: Alignment.center,
Yacumima's avatar
dev  
Yacumima committed
46
            ),
47 48 49
            Container(
              child: const TextField(minLines: 2, maxLines: 10),
              padding: const EdgeInsets.all(8.0),
Yacumima's avatar
dev  
Yacumima committed
50
            ),
51 52 53 54 55 56 57 58
            TestTextField(),
            Container(
              child: Container(
                color: Colors.red,
                width: double.infinity,
                height: 128.0,
              ),
              padding: const EdgeInsets.all(8.0),
Yacumima's avatar
dev  
Yacumima committed
59
            ),
60 61 62 63 64 65 66
            Container(
              child: Container(
                color: Colors.orange,
                width: double.infinity,
                height: 128.0,
              ),
              padding: const EdgeInsets.all(8.0),
Yacumima's avatar
dev  
Yacumima committed
67
            ),
68 69 70 71 72 73 74
            Container(
              child: Container(
                color: Colors.green,
                width: double.infinity,
                height: 128.0,
              ),
              padding: const EdgeInsets.all(8.0),
Yacumima's avatar
dev  
Yacumima committed
75
            ),
76 77 78 79 80 81 82
            Container(
              child: Container(
                color: Colors.blue,
                width: double.infinity,
                height: 128.0,
              ),
              padding: const EdgeInsets.all(8.0),
Yacumima's avatar
dev  
Yacumima committed
83
            ),
84 85 86 87 88 89 90
            Container(
              child: Container(
                color: Colors.yellow,
                width: double.infinity,
                height: 128.0,
              ),
              padding: const EdgeInsets.all(8.0),
Yacumima's avatar
dev  
Yacumima committed
91
            ),
92 93 94
            Container(
              child: const TextField(minLines: 2, maxLines: 10),
              padding: const EdgeInsets.all(8.0),
Yacumima's avatar
dev  
Yacumima committed
95
            ),
96 97 98 99
            TestTextField(),
          ],
        ),
      ),
Yacumima's avatar
dev  
Yacumima committed
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: Icon(Icons.add),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}

class TestTextField extends StatefulWidget {
  @override
  _TestTextFieldState createState() => _TestTextFieldState();
}

class _TestTextFieldState extends State<TestTextField> {
  FocusNode _node;
116
  PersistentBottomSheetController<dynamic> _controller;
Yacumima's avatar
dev  
Yacumima committed
117 118 119 120 121 122 123 124

  @override
  void initState() {
    super.initState();
    _node = FocusNode();
    _node.addListener(() {
      if (_node.hasFocus) {
        print('showBottomSheet');
125 126 127 128 129 130 131
        _controller = Scaffold.of(context).showBottomSheet<dynamic>(
          (BuildContext ctx) => Container(
            width: double.infinity,
            height: 36.0,
            color: Colors.deepPurple,
          ),
        );
Yacumima's avatar
dev  
Yacumima committed
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
      } else {
        if (_controller != null) {
          //Navigator.of(context).pop();
          print('closeBottomSheet');
          _controller.close();
        }
        _controller = null;
      }
    });
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      child: TextField(
        minLines: 2,
        maxLines: 10,
        focusNode: _node,
      ),
      padding: const EdgeInsets.all(8.0),
    );
  }
}