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

[Flutter] Unhandled Exception: MissingPluginException(No implementation found for method...

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

  1. Stack

    Stack Membro Participativo

    I'm trying to make a profile page where user can upload their profile picture. I have done all the required method but this error pops up: Unhandled Exception: MissingPluginException(No implementation found for method requestPermissions on channel flutter.baseflow.com/permissions/methods)

    a tab should pop up when I press on the IconButton asking for permission, but in here nothing happens just the above error pops up.

    This is the code I did:

    import 'dart:io';
    import 'package:firebase_storage/firebase_storage.dart';
    import 'package:image_picker/image_picker.dart';
    import 'package:permission_handler/permission_handler.dart';

    class EditProfilePage extends StatefulWidget {
    @override
    _EditProfilePageState createState() => _EditProfilePageState();
    }

    class _EditProfilePageState extends State<EditProfilePage> {
    bool showPassword = false;
    String imageUrl;

    @override
    Widget build(BuildContext context) {
    return Scaffold(
    appBar: AppBar(
    backgroundColor: Theme.of(context).scaffoldBackgroundColor,
    elevation: 1,
    leading: IconButton(
    icon: Icon(
    Icons.arrow_back,
    color: Colors.orangeAccent,
    ),
    onPressed: () {
    Navigator.pop(context);
    },
    ),
    ),
    body: Container(
    padding: EdgeInsets.only(left: 16, top: 25, right: 16),
    child: GestureDetector(
    onTap: () {
    FocusScope.of(context).unfocus();
    },
    child: ListView(
    children: [
    Text(
    "Edit Profile",
    style: TextStyle(fontSize: 25, fontWeight: FontWeight.w500),
    ),
    SizedBox(
    height: 15,
    ),
    Center(
    child: Stack(
    children: [
    Container(
    child: (imageUrl != null)
    ? Image.network(imageUrl)
    : Image.asset('assets/background.jpg'),
    width: 130,
    height: 130,
    decoration: BoxDecoration(
    border: Border.all(
    width: 4,
    color: Theme.of(context).scaffoldBackgroundColor),
    boxShadow: [
    BoxShadow(
    spreadRadius: 2,
    blurRadius: 10,
    color: Colors.black.withOpacity(0.1),
    offset: Offset(0, 10))
    ],
    shape: BoxShape.circle,
    ),
    ),
    Positioned(
    bottom: 0,
    right: 0,
    child: Container(
    height: 40,
    width: 40,
    decoration: BoxDecoration(
    shape: BoxShape.circle,
    border: Border.all(
    width: 4,
    color: Theme.of(context).scaffoldBackgroundColor,
    ),
    color: Colors.orangeAccent,
    ),
    child: IconButton(
    icon: Icon(Icons.edit),
    color: Colors.white,
    onPressed: () => uploadImage(),
    ),
    )),
    ],
    ),
    ),
    SizedBox(
    height: 35,
    ),
    buildTextField("Full Name", "Yeap Wei Kang", false),
    buildTextField("E-mail", "jonywk1103@gmail.com", false),
    buildTextField("Password", "********", true),
    buildTextField("Location", "Ipoh, Perak", false),
    SizedBox(
    height: 35,
    ),
    Row(
    mainAxisAlignment: MainAxisAlignment.spaceBetween,
    children: [
    OutlineButton(
    padding: EdgeInsets.symmetric(horizontal: 50),
    shape: RoundedRectangleBorder(
    borderRadius: BorderRadius.circular(20)),
    onPressed: () {
    Navigator.pop(context);
    },
    child: Text("CANCEL",
    style: TextStyle(
    fontSize: 14,
    letterSpacing: 2.2,
    color: Colors.black)),
    ),
    RaisedButton(
    onPressed: () {
    Navigator.pop(context);
    },
    color: Colors.orangeAccent,
    padding: EdgeInsets.symmetric(horizontal: 50),
    elevation: 2,
    shape: RoundedRectangleBorder(
    borderRadius: BorderRadius.circular(20)),
    child: Text(
    "SAVE",
    style: TextStyle(
    fontSize: 14,
    letterSpacing: 2.2,
    color: Colors.white),
    ),
    )
    ],
    )
    ],
    ),
    ),
    ),
    );
    }

    Widget buildTextField(
    String labelText, String placeholder, bool isPasswordTextField) {
    return Padding(
    padding: const EdgeInsets.only(bottom: 35.0),
    child: TextField(
    obscureText: isPasswordTextField ? showPassword : false,
    decoration: InputDecoration(
    suffixIcon: isPasswordTextField
    ? IconButton(
    onPressed: () {
    setState(() {
    showPassword = !showPassword;
    });
    },
    icon: Icon(
    Icons.remove_red_eye,
    color: Colors.grey,
    ),
    )
    : null,
    contentPadding: EdgeInsets.only(bottom: 3),
    labelText: labelText,
    floatingLabelBehavior: FloatingLabelBehavior.always,
    hintText: placeholder,
    hintStyle: TextStyle(
    fontSize: 16,
    fontWeight: FontWeight.bold,
    color: Colors.black,
    )),
    ),
    );
    }
    uploadImage() async {
    final _storage = FirebaseStorage.instance;
    final _picker = ImagePicker();
    PickedFile image;


    //Check Permissions
    await Permission.photos.request();

    var permissionStatus = await Permission.photos.status;

    if (permissionStatus.isGranted){
    //Select Image
    image = await _picker.getImage(source: ImageSource.gallery);
    var file = File(image.path);

    if (image != null){
    //Upload to Firebase
    var snapshot = await _storage.ref()
    .child('folderName/imageName')
    .putFile(file);

    var downloadUrl = await snapshot.ref.getDownloadURL();

    setState(() {
    imageUrl = downloadUrl;
    });
    } else {
    print('No Path Received');
    }

    } else {
    print('Grant Permissions and try again');
    }




    }
    }


    Can anyone tell me whats wrong in my coding?

    Continue reading...

Compartilhe esta Página