skip to Main Content

enter image description here

Hi, I want to ask. Why does this error happen? Can anyone help me.
Error code The argument type ‘BuildContext’ can’t be assigned to the parameter type ‘String’.

Code:

   Widget recentFileButton(
            BuildContext context,
            String fileName,
            String fileURL,
            String thumbnailImageName,
            String fileFrom,
            String timestamp,
            String documentID,
            String fileNotes) =>
        Container(
          margin: const EdgeInsets.only(bottom: 10),
          child: Row(
            mainAxisAlignment: MainAxisAlignment.start,
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              getPreview(fileURL, fileNotes),
              const SizedBox(width: 10),
              Expanded(
                child: InkWell(
                  onTap: () async {
                    bool _isEmwatch = false;
                    if (fileNotes == "referral letter") {
                      var uri = Uri.parse(fileURL);
                      var uuid = uri.queryParameters['uuid'];
                      var result = await DocumentRepository()
                          .doctorGetPatientReferralByUID(uuid!);
                      if (result.responseMap.clinicUID ==
                          "") {
                        _isEmwatch = true;
                      }
                      if (result.responseMap.clinicUID ==
                          "") {
                        _isEmwatch = true;
                      }
    
                      // generate and preview
                      var doc = await generateDocument(PdfPageFormat.standard,
                          result.responseMap, '', _isEmwatch);
    
                      Navigator.push(
                        context,
                        MaterialPageRoute(
                            builder: (context) => PdfPreviewPage(pdfDoc: doc)),
                      );
                    } else {
                      openDocument(context, fileURL);
                    }
                  },
                   ),
                    ],
                  ),
                ),
              ),
              const SizedBox(width: 10),
              Align(
                alignment: Alignment.topRight,
                child: IconButton(
                  icon: const Icon(
                    Icons.more_vert,
                    color: Color(0xFF021522),
                  ),
                  onPressed: () => showFileActionBottomSheet(
                      context, fileName, fileURL, documentID, fileNotes),
                ),
              )
            ],
          ),
        );

I am not sure how to solve this problem. Please guide me and anyone willing to help me to solve this problem. Thank you.

3

Answers


  1. Your method openDocument expects a String, and you pass BuildContext to it.

    Login or Signup to reply.
  2. The error basically mean that the openDocument is asking for String whereas you’re passing BuildContext to it.

    As per it’s documentation you can call openDocument like below

    openDocument(filePath: fileURL);
    

    https://pub.dev/packages/open_document

    Login or Signup to reply.
  3. In Addition to above answer you can check the parameters of the method if move your mouse curser to the method if you’re using VsCode and install,
    flutter and dart extensions.
    This work with all methods,

    1. The one you wrote.
    2. Built-in method.
    3. Package method.

    Also, work on classes,
    there is another way which is (ctrl+left mouse click) on the name of (method, class,etc).

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search