Open yuyuxingchen opened 4 years ago
import 'package:flutter/material.dart';
import 'package:keyboard_avoider/keyboard_avoider.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
TextEditingController _textEditingController =
TextEditingController(text: '测试输入框被遮盖');
@override
Widget build(BuildContext context) {
return Scaffold(
resizeToAvoidBottomPadding: false,
appBar: AppBar(
title: Text(widget.title),
),
body: KeyboardAvoider(
autoScroll: true,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'You have pushed the button this many times:',
),
Text(
'$_counter',
style: Theme.of(context).textTheme.headline4,
),
Container(
height: 300,
width: 300,
color: Colors.red,
),Container(
height: 300,
width: 300,
color: Colors.red,
),
TextField(
controller: _textEditingController,
)
],
),
),
// ), // This trailing comma makes auto-formatting nicer for build methods.
);
}
}
<application
android:name="io.flutter.app.FlutterApplication"
android:label="fluttertexfied"
android:icon="@mipmap/ic_launcher">
<activity
android:name=".MainActivity"
android:launchMode="singleTop"
android:theme="@style/FullTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<meta-data
android:name="io.flutter.embedding.android.NormalTheme"
android:resource="@style/FullTheme"
/>
<meta-data
android:name="io.flutter.embedding.android.SplashScreenDrawable"
android:resource="@drawable/launch_background"
/>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<meta-data
android:name="flutterEmbedding"
android:value="2" />
</application>
<style name="FullTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowNoTitle">true</item>//无标题
<item name="android:windowActionBar">false</item>//无ActionBar
<item name="android:windowFullscreen">true</item>//全屏即无通知栏
<item name="android:windowContentOverlay">@null</item>//是否有遮盖
<item name="android:windowBackground">@drawable/launch_background</item>
</style>
In the menifest file, set the theme of FlutterActivity to "fullscreen" and "keyboard_ avoid" is not working