-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.dart
75 lines (70 loc) · 2.64 KB
/
main.dart
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
import 'package:flutter/material.dart';
import 'package:keyboard_hider/keyboard_hider.dart';
// It's an example project, we don't care about const and print, it makes
// the code harder to reason about for beginners.
//
// ignore_for_file: prefer_const_constructors, avoid_print
void main() => runApp(const ExampleWidget());
const title = 'keyboard_hider_example';
class ExampleWidget extends StatelessWidget {
const ExampleWidget({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
const p = EdgeInsets.fromLTRB(16, 8, 16, 8);
return MaterialApp(
title: title,
debugShowCheckedModeBanner: false,
theme: ThemeData(primarySwatch: Colors.indigo),
home: Scaffold(
appBar: AppBar(
// The app bar is outside of the keyboard hider widget, so if you
// tap on the app bar title, the keyboard will not be hidden.
title: const Text(title),
actions: [
// Make sure that the context can access a FocusScope.
// If the keyboard is not hidden, try wrapping it in a builder
// to get a context that is able to unfocus the current focus scope
// node.
Builder(
builder: (context) => IconButton(
onPressed: () => unfocus(context),
icon: const Icon(Icons.keyboard),
),
)
],
),
body: KeyboardHider(
child: ListView(
children: [
// If the keyboard is open, you can tap on this text to get
// rid of the keyboard.
Text('This is a simple text'),
// hideTextInput works slightly differently than the unfocus.
// It will hide the keyboard, but it will not unfocus the
// focus scope node, so the text field will stay highlighted.
ElevatedButton(
onPressed: hideTextInput,
child: Text('Hide text input'),
),
TextField(
decoration: InputDecoration(
border: OutlineInputBorder(),
hintText: 'First text field',
),
onChanged: (s) => print('first changed $s'),
),
TextField(
decoration: InputDecoration(
border: OutlineInputBorder(),
hintText: 'Second text field',
),
onChanged: (s) => print('second changed $s'),
),
Text('More text. ' * 20),
].map((e) => Padding(padding: p, child: e)).toList(),
),
),
),
);
}
}