簡體   English   中英

當軟鍵盤出現在 Flutter Webview 插件中時,Single Child Scoll View 不會向上滾動屏幕

[英]Single Child Scoll View doesn't scroll up screens when soft keyboard appears in Flutter Webview Plugin

這是我的 main.dart

class _MyHomePageState extends State {

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      resizeToAvoidBottomInset: true,
      body: SingleChildScrollView(
        child: SizedBox(
          height: MediaQuery.of(context).size.height,
          width: MediaQuery.of(context).size.width,
          child: const WebviewController(),
        ),
      ),
    );
  }

有誰知道這個答案嗎???

請..告訴我你的解決方案......

當 android 中出現軟鍵盤時,我使用單子滾動視圖來滾動我的屏幕。

也使用 Adjust Resizing 但不起作用。

IOS設備沒有問題但是只有在android設備...

附言。 如果你需要,我也會附上 webview_controller.dart..

我也無法僅使用 SingleChildScrollView 使其可滾動,但我找到了解決方法。 當鍵盤打開並相應地修改我的小部件時,我保留了一個標志。 這是例子。

class _MyHomePageState extends State {
bool _keyboardOpen = false;

@override
  void initState() {
    super.initState();
    FocusManager.instance.primaryFocus?.unfocus();
  }


  @override
  Widget build(BuildContext context) {
    _keyboardOpen = MediaQuery.of(context).viewInsets.bottom == 0;
    return Scaffold(
      resizeToAvoidBottomInset: true,
      body: SingleChildScrollView(
        child: SizedBox(
          height: MediaQuery.of(context).size.height,
          width: MediaQuery.of(context).size.width,
          child: Visibility(
          visible: _keyboardOpen,
          child: const SizedBox(
            height: 10,
          ),
        ),
        ),
      ),
    );
  }

在這里,您可以在鍵盤打開時制作不可見的 sizedBox,您也可以在鍵盤出現時減小文本的大小,如下所示。

Text('your text', textAlign: TextAlign.center, 
    style: TextStyle(fontSize: (_keyboardOpen)? 22 : 9, fontWeight: 
           FontWeight.w500)
    ),

讓我知道這是否有幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM