我在底片中使用了一个textformfield,当键盘打开时,表离开了安全区域,无论如何我们可以将底片包裹在安全区域中吗?我尝试将底部的孩子包裹到安全区域,但没有奏效。
当键盘关闭时:
代码:
onPressed: () {
showModalBottomSheet(
isScrollControlled: true,
context: context,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(10),
topRight: Radius.circular(10))),
builder: (context) {
return Padding(
padding: EdgeInsets.only(
bottom: MediaQuery.of(context)
.viewInsets
.bottom),
child: Container(
margin: EdgeInsets.only(
top: MediaQuery.of(context)
.viewPadding
.top),
height:
MediaQuery.of(context).size.height *
0.65,
child:
SinglePostScreen(postID: posts.id)),
);
});
}
在底部工作表中显示的屏幕(键盘打开时):
代码:
class SinglePostScreen extends StatefulWidget {
final String postID;
SinglePostScreen({@required this.postID});
@override
_SinglePostScreenState createState() => _SinglePostScreenState();
}
class _SinglePostScreenState extends State<SinglePostScreen> {
final ConstantColors constantColors = ConstantColors();
Future<SinglePost> singlePost;
Future<UserProfileModel> userProfileModel;
TextEditingController commentCont = TextEditingController();
@override
void initState() {
super.initState();
singlePost = SinglePostServices().singlePost(widget.postID);
}
@override
Widget build(BuildContext context) {
return SafeArea(
child: SingleChildScrollView(
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(10), topRight: Radius.circular(10))),
child: Container(
child: Column(
children: [
Divider(
color: Colors.black45,
thickness: 2.5,
indent: 150,
endIndent: 150,
),
Container(
height: MediaQuery.of(context).size.height * 0.55,
child: FutureBuilder<SinglePost>(
future: singlePost,
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return Center(child: CircularProgressIndicator());
}
if (snapshot.data.comments.length == 0) {
return Text(
"no data yet",
style: TextStyle(color: Colors.black),
);
}
if (snapshot.connectionState == ConnectionState.done) {
return Container(
child: ListView.builder(
itemCount: snapshot.data.comments.length,
itemBuilder: (context, index) {
var comments = snapshot.data.comments[index];
return Container(
child: Column(
children: [
FutureBuilder<UserProfileModel>(
future: userProfileModel =
UserProfileServices()
.getUserProfile(
comments.userId),
builder: (context, snapshot) {
if (snapshot.hasData) {
return Provider.of<
SinglePageHelpers>(
context,
listen: false)
.comment(
context,
"https://source.unsplash.com/random",
"${snapshot.data.firstname} ${snapshot.data.lastname}",
timeago.format(comments
.createdAt
.toLocal()),
comments.comment);
} else {
return Center(
child:
CircularProgressIndicator());
}
},
),
],
),
);
}),
);
}
},
),
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Padding(
padding: const EdgeInsets.all(4.0),
child: Container(
width: MediaQuery.of(context).size.width * 0.7,
height: MediaQuery.of(context).size.height * 0.06,
child: TextFormField(
maxLines: 5,
minLines: 1,
cursorHeight: 15,
cursorColor: constantColors.purple,
cursorWidth: 1,
controller: commentCont,
textAlign: TextAlign.left,
style: TextStyle(color: Colors.black),
decoration: InputDecoration(
hintText: "add comment",
contentPadding: EdgeInsets.all(8.0),
hintStyle:
TextStyle(color: Colors.black, height: 1.4),
fillColor: Colors.grey[200],
filled: true,
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
borderSide: BorderSide(
color: Colors.transparent,
)),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
borderSide: BorderSide(
color: Colors.transparent,
))),
),
),
),
RawMaterialButton(
fillColor: constantColors.purple,
constraints: BoxConstraints.tight(Size(75, 35)),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(5)),
onPressed: () {},
child: Text(
"comment",
style: TextStyle(color: Colors.white),
),
)
],
)
],
),
),
),
),
);
}
}