Flutter App freezes when keyboard is launched

Viewed 1449

I'm trying to build an IOS application with flutter that uses Google maps. However when I tap the search box and open the keyboard to search for a place the application freezes and I can't even type. This is in a simulator as I don't have a physical iPhone to test it with. I am a flutter beginner and can't tell what is going wrong(suspecting I messed something up). I have researched on this and found that a previous version of flutter had an issue with the IOS keyboard lagging but there was no mention of the application being completely frozen. I commented out onChanged thinking it had something to do with the freeze.

class HomePage extends StatefulWidget {
  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  Completer<GoogleMapController> _controller = Completer();

  static const LatLng _center = const LatLng(45.521563, -122.677433);

  String searchValue = "";
  String _mapStyle;

  @override
  void initState() {
    super.initState();

    rootBundle.loadString('assets/map_style.txt').then((string) {
      _mapStyle = string;
    });
  }

  @override
  Widget build(BuildContext context) {
    return CupertinoPageScaffold(
        navigationBar: CupertinoNavigationBar(
          backgroundColor: GlobalAppConstants.appMainColor,
        ),
        child: GestureDetector(
          onTap:() {
            FocusScope.of(context).requestFocus(new FocusNode());
          },
          child: Stack(
            children: <Widget>[
              Container(
                child: GoogleMap(
                  initialCameraPosition:
                      CameraPosition(target: _center, zoom: 1.0),
                  mapType: MapType.normal,
                  onMapCreated: (GoogleMapController controller) {
                    controller.setMapStyle(_mapStyle);
                    _controller.complete(controller);
                  },
                ),
              ),
              Container(
                color: Color.fromRGBO(255, 255, 255, 0.7),
              ),
              Align(
                alignment: Alignment(0.0, -0.5),
                child: Column(
                  children: <Widget>[
                    Text(
                      'My Text',
                      style:
                          TextStyle(fontSize: 30, fontWeight: FontWeight.bold),
                    ),
                    Container(
                      padding: EdgeInsetsDirectional.only(top: 20.0),
                    ),
                    Text(
                      'Search Country',
                      style: TextStyle(
                          color: GlobalAppConstants.appMainColor,
                          fontWeight: FontWeight.bold),
                    ),
                    Container(
                      width: 140.0,
                      padding: EdgeInsetsDirectional.only(top: 0.0),
                      child: Divider(
                        thickness: 7.0,
                        color: GlobalAppConstants.appMainColor,
                      ),
                    ),
                    Container(
                      padding: EdgeInsetsDirectional.only(
                          start: 10.0, end: 10.0, top: 10.0),
                      height: 50,
                      child: CupertinoTextField(
                        placeholder: 'Search Country',
                        padding: EdgeInsets.symmetric(
                            horizontal: 10.0, vertical: 0.4),
                        prefix: Container(
                          padding: EdgeInsetsDirectional.only(start: 10.0),
                          child: Icon(
                            CupertinoIcons.search,
                            color: CupertinoColors.black,
                            size: 22.0,
                          ),
                        ),
                        decoration: BoxDecoration(
                          color: CupertinoColors.white,
                          boxShadow: [
                            BoxShadow(
                              color: CupertinoColors.black,
                            )
                          ],
                        ),
//                        onChanged: (String value) {
////                      setState(() {
////                        searchValue = value;
////                      });
//                        },
                      ),
                    )
                  ],
                ),
              )
            ],
          ),
        ));
  }
}

I did add <key>io.flutter.embedded_views_preview</key> <string>YES</string> to my Info.plist file. Which seemed to be of discussion in the forums that I found. Any help would be appreciated. Thanks.

2 Answers

I think I found what the issue was, so for the benefit of future viewers - simply try to restart your iOS simulator. I wasted so many hours trying to chase some elusive bug and eventually it was just a simulator issue...

Not sure how I fixed this. Ran flutter clean a bunch of times. And changed and unchanged the ios version in the Podfile. Flutter magic I guess. Also deleted all content and settings on the Simulator at some point.

Related