我正在尝试制作一个个人资料页面,用户可以在其中上传他们的个人资料图片。我已经完成了所有必需的方法,但弹出此错误:
Unhandled Exception: MissingPluginException(No implementation found for method requestPermissions on channel flutter.baseflow.com/permissions/methods)
当我按下
IconButton
请求许可时,应该会弹出一个选项卡,但在这里什么也没有发生,只是弹出上述错误。
这是我所做的代码:
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", "[email protected]", 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');
}
}
}
谁能告诉我我的编码有什么问题吗?
停止正在运行的应用程序,转到终端 > flutter clean > 然后再次构建应用程序
您好,我也遇到了同样的问题,请问您解决了吗?