test_input.dart 4.07 KB
Newer Older
Yacumima's avatar
dev  
Yacumima committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 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 42 43 44 45 46 47 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 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
import 'package:flutter/material.dart';

class TestPage extends StatefulWidget {
  TestPage({Key key, this.title = "Input Test"}) : super(key: key);

  final String title;

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

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

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

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: SafeArea(
          bottom: false,
          child: ListView(
        children: <Widget>[
          Container(
            child: Text(
              'You have pushed the button this many times:',
            ),
            margin: const EdgeInsets.all(8.0),
            alignment: Alignment.center,
          ),
          Container(
            child: Text(
              '$_counter',
              style: Theme.of(context).textTheme.display1,
            ),
            margin: const EdgeInsets.all(8.0),
            alignment: Alignment.center,
          ),
          Container(
            child: TextField(
              minLines: 2,
              maxLines: 10,
            ),
            padding: const EdgeInsets.all(8.0),
          ),
          TestTextField(),
          Container(
            child: Container(
              color: Colors.red,
              width: double.infinity,
              height: 128.0,
            ),
            padding: const EdgeInsets.all(8.0),
          ),
          Container(
            child: Container(
              color: Colors.orange,
              width: double.infinity,
              height: 128.0,
            ),
            padding: const EdgeInsets.all(8.0),
          ),
          Container(
            child: Container(
              color: Colors.green,
              width: double.infinity,
              height: 128.0,
            ),
            padding: const EdgeInsets.all(8.0),
          ),
          Container(
            child: Container(
              color: Colors.blue,
              width: double.infinity,
              height: 128.0,
            ),
            padding: const EdgeInsets.all(8.0),
          ),
          Container(
            child: Container(
              color: Colors.yellow,
              width: double.infinity,
              height: 128.0,
            ),
            padding: const EdgeInsets.all(8.0),
          ),
          Container(
            child: TextField(
              minLines: 2,
              maxLines: 10,
            ),
            padding: const EdgeInsets.all(8.0),
          ),
          TestTextField(),
        ],
      )),
      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;
  PersistentBottomSheetController _controller;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    _node = FocusNode();
    _node.addListener(() {
      if (_node.hasFocus) {
        print('showBottomSheet');
        _controller = Scaffold.of(context)
justin's avatar
justin committed
137
            .showBottomSheet<dynamic>((BuildContext ctx) => Container(
Yacumima's avatar
dev  
Yacumima committed
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
                  width: double.infinity,
                  height: 36.0,
                  color: Colors.deepPurple,
                ));
      } 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),
    );
  }
}