OpenFlutter / flutter_screenutil

Flutter screen adaptation, font adaptation, get screen information
https://pub.dartlang.org/packages/flutter_screenutil
Apache License 2.0
3.87k stars 493 forks source link

How can I use flutter_screenutil package for my hybrid app? #447

Closed DevMansoor closed 1 year ago

DevMansoor commented 1 year ago

Here is how I've used flutter_screenutil in my project but getting error on when I tap on Textfield. Kindly tell me how to use this package properly.

My error:

No Overlay widget exists above EditableText-[LabeledGlobalKey<EditableTextState>#d3506](controller: TextEditingController#dc3bb(TextEditingValue(text: ┤ghf├, selection: TextSelection.collapsed(offset: 3, affinity: TextAffinity.downstream, isDirectional: false), composing: TextRange(start: 0, end: 3))), focusNode: FocusNode#482e2([PRIMARY FOCUS]), autocorrect: false, debugLabel: ((englishLike titleMedium 2014).merge(blackMountainView titleMedium)).merge(unknown), inherit: false, color: Color(0xff878787), family: EncodeSans_regular, familyFallback: [EncodeSans], size: 16.0, weight: 400, baseline: alphabetic, decoration: TextDecoration.none, textAlign: start, keyboardType: TextInputType(name: TextInputType.text, signed: null, decimal: null), autofillHints: [], dirty, dependencies: [Directionality, MediaQuery, ScrollConfiguration], state: EditableTextState#1d73f(tickers: tracking 1 ticker)). Usually the Navigator created by WidgetsApp provides the overlay. Perhaps your app content was created above the Navigator with the WidgetsApp builder parameter. 'package:flutter/src/widgets/text_selection.dart': Failed assertion: line 610 pos 7: 'overlay != null'

My code :

main.dart

void main() async {
  await ScreenUtil.ensureScreenSize();
  runApp(const MyApp());
}

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      builder: (ctx, child) {
        ScreenUtil.init(ctx);
        return Theme(
            data: ThemeData(
              primarySwatch: Colors.blue,
            ),
            child: const HomeScreen());
      },
    );
  }
}

HomeScreen.dart

class HomeScreen extends StatefulWidget {
  const HomeScreen({Key? key}) : super(key: key);

  @override
  State<HomeScreen> createState() => _HomeScreenState();
}

class _HomeScreenState extends State<HomeScreen> {
  @override
  Widget build(BuildContext context) {
    ScreenUtil.init(context, designSize: const Size(360, 739));
    TextEditingController searchController = TextEditingController();

    return SafeArea(
      child: Scaffold(
        body: Padding(
          padding: EdgeInsets.symmetric(
            horizontal: kPaddingHorizontal,

          ),
          child: Column(
            children: [
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                crossAxisAlignment: CrossAxisAlignment.center,
                children: [
                  Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      Text(
                        "Hello, Welcome",
                        style: kEncodeSansRegular.copyWith(color: kDarkBrown),
                      ),
                      SizedBox(height: 5.h),
                      Text(
                        "Hello, Welcome",
                        style: kEncodeSansBold.copyWith(color: kDarkBrown),
                      ),
                    ],
                  ),
                  CircleAvatar(
                    radius: 23.r,
                    backgroundImage: const AssetImage("assets/images/image5.png"),
                  ),
                ],
              ),
              SizedBox(height: 20.h),
              Row(children: [
                Expanded(
                  child: TextField(
                    style: kEncodeSansRegular.copyWith(color: kDarkGrey),
                    controller: searchController,
                    keyboardType: TextInputType.text,
                    autocorrect: false,
                    decoration: InputDecoration(
                      isDense: true,
                      contentPadding: EdgeInsets.symmetric(horizontal: 10.w),
                      prefixIcon: const Icon(
                        Icons.search,
                        color: kGrey,
                      ),
                      hintText: "Search Clothes...",
                      border: kInputBorder,
                      errorBorder: kInputBorder,
                      disabledBorder: kInputBorder,
                      focusedBorder: kInputBorder,
                      focusedErrorBorder: kInputBorder,
                      enabledBorder: kInputBorder,
                      hintStyle: kEncodeSansRegular.copyWith(color: kDarkGrey),
                    ),
                  ),
                ),
lizhuoyuan commented 1 year ago

I can't tell if it's screenutil's problem

github-actions[bot] commented 1 year ago

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] commented 1 year ago

This issue was closed because it has been inactive for 14 days since being marked as stale.