ios - 启动键盘时 Flutter 应用程序卡住

标签 ios google-maps flutter mobile-development

我正在尝试使用 flutter 构建一个使用 Google map 的 IOS 应用程序。但是,当我点击搜索框并打开键盘来搜索位置时,应用程序卡住,我什至无法键入。这是在模拟器中进行的,因为我没有物理 iPhone 来测试它。我是一个 flutter 初学者,无法判断出了什么问题(怀疑我搞砸了)。我对此进行了研究,发现之前版本的 flutter 存在 IOS 键盘滞后的问题,但没有提到应用程序被完全卡住。我评论了 onChanged 认为这与卡住有关。

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;
////                      });
//                        },
                      ),
                    )
                  ],
                ),
              )
            ],
          ),
        ));
  }
}

我确实添加了<key>io.flutter.embedded_views_preview</key> <string>YES</string> 到我的 Info.plist 文件。我发现这似乎在论坛中进行了讨论。任何帮助,将不胜感激。谢谢。

最佳答案

我想我找到了问题所在,因此为了 future 查看者的利益 - 只需尝试重新启动您的 iOS 模拟器即可。我浪费了很多时间试图追踪一些难以捉摸的错误,最终这只是一个模拟器问题......

关于ios - 启动键盘时 Flutter 应用程序卡住,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60695273/

相关文章:

iOS 共享扩展无法从 Chrome 获取共享 URL

ios - 需要 iBeacon locationManager :didEnterRegion to trigger at near physical contact when backgrounded

javascript - Font Awesome 图标作为 Google Maps API V3 中的标记

javascript - 将数据传递给模态( Bootstrap )

android - Flutter 从 1.5 升级到 1.7.4 后 APK 大小翻倍?

gradle - 用VSCode和Flutter构建Appbundle的问题

ios - 我如何使用 websocket 将音频发送到 Microsoft Translator

iphone - 如何在 UITableView 中将 fromIndex 处的 Row 交换为 toIndex?

google-maps - 谷歌地图加载问题

flutter - 由于行 flutter 之间的列而导致像素错误