Skip to content

on 3.10.0 use flutter screenutil, when I open keyboard ,bottomsheet not build, and keyboard Obscure bottomsheet #477

Closed
@kevin-lemon

Description

@kevin-lemon

can try this code with flutter 3.10.0 and flutter_screenutil: 5.8.1

import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  MyApp({super.key});
  @override
  Widget build(BuildContext context) {
    return ScreenUtilInit(
        designSize: const Size(375, 812),
        builder: (context, child) {
          return const MaterialApp(
            home: HomePage(),
          );
        });
  }
}

class HomePage extends StatelessWidget {
  const HomePage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Flutter Tutorial'),
      ),
      body: Column(
        children: [
          Center(
            child: ElevatedButton(
              onPressed: () {
                showModalBottomSheet(
                  context: context,
                  builder: (context){
                    return Padding(
                      padding: EdgeInsets.only(bottom: MediaQuery.of(context).viewInsets.bottom),
                      child: const SizedBox(height: 200, child: TextField()),
                    );
                  },
                );
              },
              child: const Text(
                'showModalBottomSheet',
              ),
            ),
          ),
        ],
      ),
    );
  }

}

image
I test only use flutter screenutil can happend

就是当我用这个插件的时候(5.8.1最新版和5.7.0以前用的都尝试了),在3.7.11版本的flutter,是完全没问题的,但是当我升级flutter到3.10.0时,打开键盘不会触发bottomsheet的build了,导致页面无法移动被遮挡,在3.7.11是触发的,不止是bottomsheet,其他的带输入框页面似乎也有这个问题。

当使用方式二加载时不会有这个问题:
void main() async {
// Add this line
await ScreenUtil.ensureScreenSize();
runApp(MyApp());
}
...
MaterialApp(
...
builder: (ctx, child) {
ScreenUtil.init(ctx);
return Theme(
data: ThemeData(
primarySwatch: Colors.blue,
textTheme: TextTheme(bodyText2: TextStyle(fontSize: 30.sp)),
),
child: HomePage(title: 'FlutterScreenUtil Demo'),
);
},
)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions