-
Notifications
You must be signed in to change notification settings - Fork 28.9k
Not planned
Not planned
Copy link
Labels
r: solvedIssue is closed as solvedIssue is closed as solved
Description
"_When I was using flutter 3.0 and above, I found that when the input box is focused, bottomNavigationBar and floatingActionButton will be pushed up by the soft keyboard, even if resizeToAvoidBottomInset: false is set, it is invalid. Such a checkup is not very friendly. Is there any solution please?_" - Google Translate
Hi @shijia2118
I can not reproduce the issue with below sample code. When setting resizeToAvoidBottomInset: false
, the bottomNavigationBar
and floatingActionButton
are not pushed up by the keyboard.
Sample code
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({super.key});
static const String _title = 'Flutter Code Sample';
@override
Widget build(BuildContext context) {
return const MaterialApp(
title: _title,
home: MyStatefulWidget(),
);
}
}
class MyStatefulWidget extends StatefulWidget {
const MyStatefulWidget({super.key});
@override
State<MyStatefulWidget> createState() => _MyStatefulWidgetState();
}
class _MyStatefulWidgetState extends State<MyStatefulWidget> {
int _selectedIndex = 0;
static const TextStyle optionStyle =
TextStyle(fontSize: 30, fontWeight: FontWeight.bold);
static List<Widget> _widgetOptions = <Widget>[
Column(
children: [
Text(
'Index 0: Home',
style: optionStyle,
),
TextField(),
],
),
Text(
'Index 1: Business',
style: optionStyle,
),
Text(
'Index 2: School',
style: optionStyle,
),
];
void _onItemTapped(int index) {
setState(() {
_selectedIndex = index;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
resizeToAvoidBottomInset: false,
appBar: AppBar(
title: const Text('BottomNavigationBar Sample'),
),
body: Center(
child: _widgetOptions.elementAt(_selectedIndex),
),
bottomNavigationBar: BottomNavigationBar(
items: const <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: Icon(Icons.home),
label: 'Home',
),
BottomNavigationBarItem(
icon: Icon(Icons.business),
label: 'Business',
),
BottomNavigationBarItem(
icon: Icon(Icons.school),
label: 'School',
),
],
currentIndex: _selectedIndex,
selectedItemColor: Colors.amber[800],
onTap: _onItemTapped,
),
floatingActionButton: FloatingActionButton(
onPressed: () {
},
child: const Icon(Icons.add),
),
);
}
}
Demo
XRecorder_12092022_132746.mp4
Please provide a completed and minimal reproducible code sample so that we may verify this. Also, please provide the output of flutter doctor -v
as well.
Thank you!
Originally posted by @huycozy in #111334 (comment)
Metadata
Metadata
Assignees
Labels
r: solvedIssue is closed as solvedIssue is closed as solved
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
malgee012 commentedon Feb 9, 2023
I also encountered the problem that
BottomNavigationBar
andFloatingActionButton
are pushed up by the keyboard, but it is caused by nesting an extra layer ofScaffold
. According to the provided example demo, adding an extra layer ofScaffold
will also appear to be pushed up The case where the keyboard is raisedmalgee012 commentedon Feb 9, 2023
malgee012 commentedon Feb 9, 2023
My solution: Reducing nested
Scaffold
solved my problemhuycozy commentedon Feb 9, 2023
Closing the issue as solved by yourself. When you have an issue in the future, please try to provide all or some of the information indicated in the template so that we can address this issue properly.
Issue Template
github-actions commentedon Mar 3, 2023
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -v
and a minimal reproduction of the issue.