'flutter : The screen freezes when I try to output the iOS built-in dictionary with UIReferenceLibraryViewController

I am making an English word learning app with flutter. I am using the built-in dictionary of iOS. It is a basic application that the built-in dictionary is displayed when the user presses the "answer confirmation button". I can basically do what I want to do, but I found a bug yesterday.

When I pressed the answer confirmation button for the word "buffalo", the screen froze. The screen itself is displayed instead of being killed, but no further operations are accepted. It's the first time I've tested over 500 words. The other words are working fine.

The method channel is used to call the built-in dictionary.

//AppDelegate.swift
import UIKit
import Flutter

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {

    var ref: UIReferenceLibraryViewController = UIReferenceLibraryViewController(term:"")

  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {
    GeneratedPluginRegistrant.register(with: self)

    let controller: FlutterViewController = window?.rootViewController as! FlutterViewController
    let methodChannel = FlutterMethodChannel(name: "hello_ios", binaryMessenger: controller.binaryMessenger)

    methodChannel.setMethodCallHandler({
      (call: FlutterMethodCall, result: FlutterResult) -> Void in

      if call.method == "searchDictionary" {
          print(call.arguments)

          self.searchDictionary(result:result,controller:controller,queryWord:call.arguments as! String)


        //result("Hello from iOddddddddddddS")
      } else {
        result(FlutterMethodNotImplemented)
      }

    })






    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }


    func searchDictionary(result: FlutterResult, controller: FlutterViewController, queryWord: String){
        print("416\(UIReferenceLibraryViewController.dictionaryHasDefinition(forTerm:queryWord))")
            //let ref: UIReferenceLibraryViewController = UIReferenceLibraryViewController(term: queryWord)

        ref = UIReferenceLibraryViewController(term:queryWord)
        if(UIReferenceLibraryViewController.dictionaryHasDefinition(forTerm:queryWord)){
            controller.present(ref, animated: true, completion: nil)
        }
    }

}

I wrote the above code thinking that it should be conditional branching by "UIReferenceLibraryViewController.dictionaryHasDefinition", but it seems that it is not a solution because true is returned even at the time of "buffalo".


Since it works normally with other words, it seems that the caller is not the cause, but the following is the caller.

onPressed: () async {                                                                                                            
  ClipboardData? data = await Clipboard.getData(Clipboard.kTextPlain);                                                                                                                                                                                                                  
  await HomePage._channel.invokeMethod('searchDictionary', 
    editingTargetTextCtrl.text != '' ? editingTargetTextCtrl.text : data == null ? '' : data.text,);                                                                                                         
},

There are almost no error messages, so I can't get any clues. Is there anything?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source