当我运行纯flutter项目时,当显示键盘时,文本字段可以在其上方移动,并且小部件可以很好地自适应。 但是当我将flutter模块添加到本机项目中时,键盘将显示文本字段。
我不知道如何解决这个问题。
颤动:
class HomeWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'this is a project to test keyboard',
),
Flexible(
fit: FlexFit.tight,
child: CustomScrollView(
slivers: <Widget>[
SliverToBoxAdapter(
child: SizedBox(
width: 100,
height: 160,
child: Container(
color: Colors.blue,
),
),
),
SliverToBoxAdapter(
child: SizedBox(
width: 100,
height: 140,
child: Container(
color: Colors.grey,
),
),
),
SliverToBoxAdapter(
child: SizedBox(
width: 100,
height: 120,
child: Container(
color: Colors.red,
),
),
),
SliverToBoxAdapter(
child: SizedBox(
width: 100,
height: 100,
child: Container(
color: Colors.deepPurple,
),
),
),
SliverToBoxAdapter(
child: TextField(
decoration: InputDecoration(
hintText: 'this is first input text'
),
),
),
SliverToBoxAdapter(
child: Padding(padding: EdgeInsets.only(top: 20),),
),
SliverToBoxAdapter(
child: TextField(
decoration: InputDecoration(
hintText: 'this is second input text'
),
),
),
],
),
),
Container(
color: Colors.grey[400],
padding: EdgeInsets.all(8),
height: 50,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
FlatButton(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(2)
),
color: Colors.black,
textColor: Colors.white,
onPressed: () {
},
child: Text(
'button1'
)
),
FlatButton(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(2)
),
color: Colors.black,
textColor: Colors.white,
onPressed: () {
},
child: Text(
'button2'
)
),
FlatButton(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(2)
),
color: Colors.black,
textColor: Colors.white,
onPressed: () {
},
child: Text(
'button3'
)
)
],
),
)
],
);
}
}
母语:
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setContentView(R.layout.activity_main);
//
// FrameLayout container = findViewById(R.id.container);
FlutterView flutterView = Flutter.createView(this, getLifecycle(), "route");
addContentView(flutterView, new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT));
}
}
这是纯扑项目: https://github.com/longdw/flutter_keyboard
这是本地项目,包含flutter模块: https://github.com/longdw/keyboard_host
答案 0 :(得分:2)
您可以在脚手架中使用该物业
resizeToAvoidBottomPadding: false,
它不会移动内容。
答案 1 :(得分:0)
您可以将身体包裹在SingleChildScrollView中
https://api.flutter.dev/flutter/widgets/SingleChildScrollView-class.html
我做了些小改动,只是在Column中添加了TextFiled。希望它对您有用。
import 'package:flutter/material.dart';
void main() => runApp(new MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: 'NonStopIO',
theme: new ThemeData(
primarySwatch: Colors.red,
),
home: new HomeWidget(),
);
}
}
class HomeWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
// Here we take the value from the MyHomePage object that was created by
// the App.build method, and use it to set our appbar title.
title: Text("hello"),
),
body: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'this is a project to test keyboard',
),
Flexible(
fit: FlexFit.tight,
child: CustomScrollView(
slivers: <Widget>[
SliverToBoxAdapter(
child: SizedBox(
width: 100,
height: 160,
child: Container(
color: Colors.blue,
),
),
),
SliverToBoxAdapter(
child: SizedBox(
width: 100,
height: 140,
child: Container(
color: Colors.grey,
),
),
),
SliverToBoxAdapter(
child: SizedBox(
width: 100,
height: 120,
child: Container(
color: Colors.red,
),
),
),
SliverToBoxAdapter(
child: SizedBox(
width: 100,
height: 100,
child: Container(
color: Colors.deepPurple,
),
),
),
],
),
),
TextField(
decoration: InputDecoration(
hintText: 'this is first input text'
)
),
TextField(
decoration: InputDecoration(
hintText: 'this is lst input text'
)
),
Container(
color: Colors.grey[400],
padding: EdgeInsets.all(8),
height: 50,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
FlatButton(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(2)
),
color: Colors.black,
textColor: Colors.white,
onPressed: () {
},
child: Text(
'button1'
)
),
FlatButton(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(2)
),
color: Colors.black,
textColor: Colors.white,
onPressed: () {
},
child: Text(
'button2'
)
),
FlatButton(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(2)
),
color: Colors.black,
textColor: Colors.white,
onPressed: () {
},
child: Text(
'button3'
)
)
],
),
),
],
)
);
}
}
答案 2 :(得分:0)
我通过移除解决了
<item name="android:windowFullscreen">true</item>
在app/src/main/res/values/styles.xml
不知道它为什么在那里:)