mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
[infra_ui][keyboard] Add keyboard demo entrance
This commit is contained in:
parent
4364f59e39
commit
be4f6a8250
@ -5,7 +5,7 @@ abstract class ListItem {}
|
||||
abstract class DemoItem extends ListItem {
|
||||
String buildTitle();
|
||||
|
||||
void handleTap();
|
||||
void handleTap(BuildContext context);
|
||||
}
|
||||
|
||||
class SectionHeaderItem extends ListItem {
|
||||
|
@ -1,11 +1,13 @@
|
||||
import 'package:example/home/demo_item.dart';
|
||||
import 'package:example/keyboard/keyboard_screen.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'demo_item.dart';
|
||||
|
||||
class HomeScreen extends StatelessWidget {
|
||||
const HomeScreen({Key? key}) : super(key: key);
|
||||
|
||||
static List<ListItem> items = [
|
||||
SectionHeaderItem('Widget Demos'),
|
||||
KeyboardItem(),
|
||||
];
|
||||
|
||||
@override
|
||||
@ -30,7 +32,7 @@ class HomeScreen extends StatelessWidget {
|
||||
} else if (item is DemoItem) {
|
||||
return ListTile(
|
||||
title: Text(item.buildTitle()),
|
||||
onTap: item.handleTap,
|
||||
onTap: () => item.handleTap(context),
|
||||
);
|
||||
}
|
||||
return const ListTile(
|
||||
|
@ -0,0 +1,57 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import '../home/demo_item.dart';
|
||||
|
||||
class KeyboardItem extends DemoItem {
|
||||
@override
|
||||
String buildTitle() => 'Keyboard Listener';
|
||||
|
||||
@override
|
||||
void handleTap(BuildContext context) {
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (context) {
|
||||
return const KeyboardScreen();
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class KeyboardScreen extends StatefulWidget {
|
||||
const KeyboardScreen({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
_KeyboardScreenState createState() => _KeyboardScreenState();
|
||||
}
|
||||
|
||||
class _KeyboardScreenState extends State<KeyboardScreen> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Keyboard Visibility Demo'),
|
||||
),
|
||||
body: GestureDetector(
|
||||
onTap: () => _dismissKeyboard(context),
|
||||
behavior: HitTestBehavior.translucent,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 36),
|
||||
child: Center(
|
||||
child: TextField(
|
||||
style: const TextStyle(fontSize: 20),
|
||||
controller: TextEditingController(text: 'Test'),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _dismissKeyboard(BuildContext context) {
|
||||
final currentFocus = FocusScope.of(context);
|
||||
|
||||
if (!currentFocus.hasPrimaryFocus && currentFocus.hasFocus) {
|
||||
FocusManager.instance.primaryFocus?.unfocus();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user