从联系人列表中选择联系人后,联系人选择器导致应用程序崩溃

时间:2020-04-06 09:26:21

标签: flutter android-contacts flutter-dependencies flutter-packages

我正在使用Flutter contact picker 0.0.2。但这给了一些奇怪的错误。当我呼叫 selectContact Future时,它会显示联系人列表,但是,从列表中选择特定联系人后,应用程序崩溃,并且在控制台上显示了以下错误。

我也尝试过在android中添加权限,即使不是必需的,它仍然无法使用。

代码:

class _MobileNumberWidgetState extends State<MobileNumberWidget> {
  final TextEditingController _phoneNumberController = TextEditingController();
  final ContactPicker _contactPicker = new ContactPicker();
  Contact _contact;

  @override
  Widget build(BuildContext context) {
    return AppWidgets.shadowContainerComplete(
            child:Row(
              children: <Widget>[
                Expanded(
                  child: TextField(
                    controller: _phoneNumberController,
                    decoration: AppStyles.textField(hint: "Enter Phone Number", iconData: Icons.phone_iphone),
                  ),
                ),
                IconButton(
                  icon: Icon(Icons.format_list_numbered),
                  onPressed: () async{
                    Contact contact = await _contactPicker.selectContact();
                    setState(() {
                      _contact = contact;
                    });
                  },
                )
              ],
            )
        );
  }
}

控制台:

Launching lib\main.dart on Android SDK built for x86 in debug mode...
Running Gradle task 'assembleDebug'...
√ Built build\app\outputs\apk\debug\app-debug.apk.
Installing build\app\outputs\apk\app.apk...
D/FlutterActivity(17398): Using the launch theme as normal theme.
D/FlutterActivityAndFragmentDelegate(17398): Setting up FlutterEngine.
D/FlutterActivityAndFragmentDelegate(17398): No preferred FlutterEngine was provided. Creating a new FlutterEngine for this FlutterFragment.
D/FlutterActivityAndFragmentDelegate(17398): Attaching FlutterEngine to the Activity that owns this Fragment.
D/FlutterView(17398): Attaching to a FlutterEngine: io.flutter.embedding.engine.FlutterEngine@43c3a74
D/FlutterActivityAndFragmentDelegate(17398): Executing Dart entrypoint: main, and sending initial route: /
Debug service listening on ws://127.0.0.1:28145/jPIcHt_yF9E=/ws
Syncing files to device Android SDK built for x86...
D/EGL_emulation(17398): eglMakeCurrent: 0xe121a6c0: ver 3 1 (tinfo 0xe120f8a0)
D/eglCodecCommon(17398): setVertexArrayObject: set vao to 0 (0) 1 0
D/EGL_emulation(17398): eglMakeCurrent: 0xe121a180: ver 3 1 (tinfo 0xe120fa70)
D/FlutterView(17398): Detaching from a FlutterEngine: io.flutter.embedding.engine.FlutterEngine@43c3a74
D/AndroidRuntime(17398): Shutting down VM
E/AndroidRuntime(17398): FATAL EXCEPTION: main
E/AndroidRuntime(17398): Process: maaz.easyapproach.kashbak, PID: 17398
E/AndroidRuntime(17398): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=2015, result=-1, data=Intent { dat=content://com.android.contacts/data/1 flg=0x1 }} to activity {maaz.easyapproach.kashbak/maaz.easyapproach.kashbak.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.ContentResolver android.app.Activity.getContentResolver()' on a null object reference
E/AndroidRuntime(17398):    at android.app.ActivityThread.deliverResults(ActivityThread.java:4845)
E/AndroidRuntime(17398):    at android.app.ActivityThread.handleSendResult(ActivityThread.java:4886)
E/AndroidRuntime(17398):    at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:51)
E/AndroidRuntime(17398):    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
E/AndroidRuntime(17398):    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
E/AndroidRuntime(17398):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
E/AndroidRuntime(17398):    at android.os.Handler.dispatchMessage(Handler.java:107)
E/AndroidRuntime(17398):    at android.os.Looper.loop(Looper.java:214)
E/AndroidRuntime(17398):    at android.app.ActivityThread.main(ActivityThread.java:7356)
E/AndroidRuntime(17398):    at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(17398):    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
E/AndroidRuntime(17398):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
E/AndroidRuntime(17398): Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.ContentResolver android.app.Activity.getContentResolver()' on a null object reference
E/AndroidRuntime(17398):    at net.goderbauer.flutter.contactpicker.ContactPickerPlugin.onActivityResult(ContactPickerPlugin.java:68)
E/AndroidRuntime(17398):    at io.flutter.embedding.engine.FlutterEnginePluginRegistry$FlutterEngineActivityPluginBinding.onActivityResult(FlutterEnginePluginRegistry.java:634)
E/AndroidRuntime(17398):    at io.flutter.embedding.engine.FlutterEnginePluginRegistry.onActivityResult(FlutterEnginePluginRegistry.java:367)
E/AndroidRuntime(17398):    at io.flutter.embedding.android.FlutterActivityAndFragmentDelegate.onActivityResult(FlutterActivityAndFragmentDelegate.java:546)
E/AndroidRuntime(17398):    at io.flutter.embedding.android.FlutterActivity.onActivityResult(FlutterActivity.java:594)
E/AndroidRuntime(17398):    at android.app.Activity.dispatchActivityResult(Activity.java:8110)
E/AndroidRuntime(17398):    at android.app.ActivityThread.deliverResults(ActivityThread.java:4838)
E/AndroidRuntime(17398):    ... 11 more
I/Process (17398): Sending signal. PID: 17398 SIG: 9
Lost connection to device.

0 个答案:

没有答案