0

I'm facing an issue with Flutter UI. I am using resizeToAvoidBottomInset to resize my UI when the keyboard show, the only problem is that when the keyboard retract the UI lagged.

this is the image before the keyboard shows.

enter image description here

and this is what happens after

enter image description here

5
  • I also face the same issue Commented Aug 31 at 6:44
  • is this ui under scrollableview like listview, singlechildscrollview? Commented Aug 31 at 12:15
  • Can you show the widget tree you are using? Commented Aug 31 at 22:54
  • SingleChildScrollView/Column/ListTile Commented Sep 1 at 7:29
  • Please add minimal code for better understanding. Commented Sep 2 at 1:30

1 Answer 1

0

I could help you better if you posted a code sample of what you did, but try these few steps, and I hope they work!

1 - you should set "resizeToAvoidBottomInset" to "false" for the main scaffold widget.
it will ignore any auto-resize proccesses.
2 - use "KeyboardDismissHandler" as main wrapper for scaffold body.
its a widget that helps manage keyboard dismissal in a more controlled way.
its not built-in so you must use a library named "keyboard_dismiss_handler".
its good for preventing lags and ui issues.
3 - Sometimes using animations make smoother appear/disappear proccess and it removes lags and ui-show issues. not guaranteed but good to check.

for last tip, you could use Custom Keyboard-Aware Widget.
let me show you an example :

class KeyboardAwareView extends StatefulWidget {
  final Widget child;
  
  const KeyboardAwareView({Key? key, required this.child}) : super(key: key);
  
  @override
  _KeyboardAwareViewState createState() => _KeyboardAwareViewState();
}

class _KeyboardAwareViewState extends State<KeyboardAwareView> {
  double _keyboardHeight = 0;
  
  @override
  void initState() {
    super.initState();
    WidgetsBinding.instance.addPostFrameCallback((_) {
      _setupKeyboardListeners();
    });
  }
  
  void _setupKeyboardListeners() {
    // Listen for keyboard changes
  }
  
  @override
  Widget build(BuildContext context) {
    return AnimatedContainer(
      duration: const Duration(milliseconds: 300),
      padding: EdgeInsets.only(bottom: _keyboardHeight),
      child: widget.child,
    );
  }
}

// Use like this:
Scaffold(
  resizeToAvoidBottomInset: false,
  body: KeyboardAwareView(
    child: SingleChildScrollView(
      child: YourContentWidget(),
    ),
  ),
)

// Ardavan Eskandari

Let me know if there was any problem. 💓

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.