I am newer in flutter. I searched this issue in the internet. but, showModalbottomsheet does not move along with keyboard.
I add isScrollControlled : true
in showModalbottomsheet, and padding: MediaQuery.of(context).viewInsets,
is added to TextField. I try to position of padding: MediaQuery.of(context).viewInsets,
to other Widget. but it also doesn't work.
the keyboard cover bottomsheet. help me!!
this is my code.
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
class B20 extends StatefulWidget {
const B20({Key? key, required this.postNo}) : super(key: key);
final String postNo;
@override
B20State createState() => B20State();
}
class B20State extends State<B20> {
Map<String, Object> result = {};
final TextEditingController _textEditingController = TextEditingController();
void _showModalBottomSheet(BuildContext context) {
showModalBottomSheet(
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.vertical(top: Radius.circular(20)),
),
backgroundColor: Colors.transparent,
context: context,
isScrollControlled: true, // add isScrollControlled
builder: (context) => _commentBottomSheetContainer(context));
}
Widget _commentBottomSheetContainer(BuildContext context) {
return Container(
decoration: const BoxDecoration(
color: Color(0xffffffff),
borderRadius: BorderRadius.only(
topLeft: Radius.circular(20),
topRight: Radius.circular(20),
)),
child: Padding(
padding:
EdgeInsets.only(bottom: MediaQuery.of(context).viewInsets.bottom), //add padding
child: TextField(
keyboardType: TextInputType.text,
autofocus: true,
controller: _textEditingController,
maxLines: 10,
minLines: 1,
decoration: InputDecoration(
hintStyle: TextStyle(
fontFamily: 'Noto_Sans_KR',
fontSize: 13.sp,
color: const Color(0xffABACB2),
),
border: InputBorder.none,
focusedBorder: InputBorder.none,
enabledBorder: InputBorder.none,
errorBorder: InputBorder.none,
disabledBorder: InputBorder.none,
hintText: '댓글을 남겨주세요',
contentPadding: EdgeInsets.fromLTRB(15.w, -20.h, 15.w, 0.h),
),
),
));
}
Widget _commentContainer(BuildContext context) {
return InkWell(
onTap: () {
_showModalBottomSheet(context);
},
child: Text(
'댓글을 남겨주세요',
style: TextStyle(
fontFamily: 'Noto_Sans_KR',
fontSize: 13.sp,
color: const Color(0xffABACB2),
),
textAlign: TextAlign.start,
softWrap: false,
),
);
}
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: () {
FocusManager.instance.primaryFocus?.unfocus();
},
child: Container(
color: Colors.white,
child: SafeArea(
child: Scaffold(
backgroundColor: Colors.white,
body: _commentContainer(context),
),
),
),
);
}
}