1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Flutter] i get the error Unhandled Exception: type '_Map<String, dynamic>' is not a subtype...

Discussão em 'Mobile' iniciado por Stack, Outubro 7, 2024 às 12:12.

  1. Stack

    Stack Membro Participativo

    whenever i try uploading a photo in my form using flutter i get this error Unhandled Exception: type '_Map<String, dynamic>' is not a subtype of type 'String'

    am new to flutter so i used an already made project and modified it


    const SizedBox(
    height: 8,
    ),
    Text(
    'Photo',
    style: Theme.of(context)
    .textTheme
    .bodyMedium!
    .copyWith(
    color: Theme.of(context).hintColor,
    letterSpacing: 0.1,
    ),
    ),
    const SizedBox(
    height: 9,
    ),

    photoUrl != null ? Container(
    height: 250,
    width: double.infinity,
    clipBehavior: Clip.antiAliasWithSaveLayer,
    decoration: BoxDecoration(
    borderRadius: BorderRadius.circular(12),
    ),
    child: Image.network(
    photoUrl ?? 'https://imgv3.fotor.com/images/blog-cover-image/part-blurry-image.jpg' ,
    fit: BoxFit.cover,
    )): const Text("Photo not selected yet"),
    const SizedBox(
    height: 10,
    ),
    ElevatedButton(
    style: ElevatedButton.styleFrom(
    backgroundColor: AppColors.tabGrey,
    ),
    onPressed: () async{

    FilePickerResult? result = await FilePicker.platform.pickFiles(
    type: FileType.custom,
    allowedExtensions: ['jpg', 'png', 'gif'],
    );

    String id = uuid.v1();

    if (result != null) {
    File file = File(result.files.single.path!);
    log(file.path);
    String fileName = result.files.single.name;

    Future result2 = storage.createFile(
    bucketId: Credentials.PhotosBucketId,
    fileId: id,
    file: InputFile.fromPath(
    path: file.path,
    ),
    );

    result2.then((response) {
    log("Pic Uploaded");
    photoUrl = 'https://cloud.appwrite.io/v1/storage/buckets/${Credentials.PhotosBucketId}/files/${id}/view?project=${Credentials.ProjectID}';
    setState(() {});
    Dialogs.showSnackbar(context, "Picture updated successfully! Update to save");
    }).catchError((error) {
    print(error.response);
    Dialogs.showSnackbar(context, "${error}");
    });
    } else {
    // User canceled the picker
    Dialogs.showSnackbar(context, "Unable to upload canceled in between");
    }
    },
    child: Text("Upload Image", style: textTheme.titleSmall!.copyWith(color: AppColors.grey),),
    ),
    const SizedBox(
    height: 20,
    ),
    TextFieldInput(
    controller: phoneController,
    title: 'Phone',
    hintText: 'Phone number',
    onChanged: (val) {},
    ),

    opens != ""
    ? Column(
    crossAxisAlignment:
    CrossAxisAlignment.start,
    children: [
    const SizedBox(
    height: 20,
    ),
    Text(
    'Last Updated',
    style: Theme.of(context)
    .textTheme
    .bodyMedium!
    .copyWith(
    color:
    Theme.of(context).hintColor,
    letterSpacing: 0.1,
    ),
    ),
    const SizedBox(
    height: 12,
    ),
    Text(
    "Available: ${opens}",
    style: textTheme.bodyMedium!.copyWith(
    color: Colors.deepPurple[700]),
    ),
    Text(
    "Not Available: ${closes}",
    style: textTheme.bodyMedium!
    .copyWith(color: AppColors.orange),
    ),
    ],
    )
    : const SizedBox(),
    const SizedBox(
    height: 25,
    ),

    const SizedBox(
    height: 20,
    ),
    ElevatedButton(
    onPressed: () async {
    List arr = currentAddress.split(", ");
    print(arr[arr.length - 1]);
    print(arr[arr.length - 2]);
    print(arr[arr.length - 3]);
    if(ShopModel == null){
    print("check your information again");
    }

    else{
    if (myCurrentShop != null) {
    myCurrentShop!.name =
    storeNameController.text;
    myCurrentShop!.lat = lat;
    myCurrentShop!.long = long;
    myCurrentShop!.country = arr[arr.length - 1];
    myCurrentShop!.pincode = arr[arr.length - 2];
    myCurrentShop!.district = arr[arr.length - 3];
    myCurrentShop!.photo = photoUrl;
    myCurrentShop!.address = currentAddress;

    myCurrentShop!.phone = phoneController.text;

    myCurrentShop!.about = aboutController.text;
    myCurrentShop!.opens = opens;
    myCurrentShop!.closes = closes;
    myCurrentShop!.isOpen = isOpen;
    Dialogs.showLoaderDialog(context, "Saving");
    await APIs.instance
    .updateShopInfo(myCurrentShop!)
    .then((value) {
    Navigator.pop(context);
    });
    } else {
    ShopModel newShop = ShopModel(
    name: storeNameController.text,
    lat: lat,
    long: long,
    country: arr[arr.length - 1],
    pincode: arr[arr.length - 2],
    district: arr[arr.length - 3],
    photo:photoUrl,
    address: currentAddress,

    phone: phoneController.text,

    about: aboutController.text,
    opens: opens,
    closes: closes,
    isOpen: isOpen,
    );
    await APIs.instance
    .createShop(currentShop: newShop);}

    }
    },
    child: Text("Update Details"),
    ),
    const SizedBox(
    height: 40,
    ),
    ]),
    ),
    ));
    }


    thanks in advance

    i tried adding attributes to appwrite and givingany permissions but it didnt work and trying to upload a photo more than one time gives this error

    Storage bucket with the requested ID could not be found., code: 404, type: storage_bucket_n

    Continue reading...

Compartilhe esta Página