如果在使用TabBarView和TextField时遇到了键盘溢出的问题,可以尝试以下解决方法:
import 'package:flutter/material.dart';
class MyTabBarView extends StatefulWidget {
@override
_MyTabBarViewState createState() => _MyTabBarViewState();
}
class _MyTabBarViewState extends State {
@override
Widget build(BuildContext context) {
return Scaffold(
body: SingleChildScrollView(
child: Column(
children: [
TabBar(
tabs: [
Tab(text: 'Tab 1'),
Tab(text: 'Tab 2'),
],
),
SizedBox(height: 20),
TabBarView(
children: [
TextField(
decoration: InputDecoration(
labelText: 'Input 1',
),
),
TextField(
decoration: InputDecoration(
labelText: 'Input 2',
),
),
],
),
],
),
),
);
}
}
import 'package:flutter/material.dart';
class MyTabBarView extends StatefulWidget {
@override
_MyTabBarViewState createState() => _MyTabBarViewState();
}
class _MyTabBarViewState extends State {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
children: [
TabBar(
tabs: [
Tab(text: 'Tab 1'),
Tab(text: 'Tab 2'),
],
),
SizedBox(height: 20),
Expanded(
child: ListView(
children: [
TextField(
decoration: InputDecoration(
labelText: 'Input 1',
),
),
TextField(
decoration: InputDecoration(
labelText: 'Input 2',
),
),
],
),
),
],
),
);
}
}
使用上述两种方法之一可以解决TabBarView与TextField键盘溢出的问题。根据实际情况选择适合的方法来解决问题。
上一篇:布局问题与粘性元素和媒体查询
下一篇:布局无法向上滚动吗?