Open tziporakk opened 3 years ago
when i upload a picture or take a photo my app closes this is my code:
import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:partners_app/widgets/orange_button.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_screenutil/screenutil_init.dart'; import 'dart:io'; import 'package:image_cropper/image_cropper.dart'; import 'package:image_picker/image_picker.dart'; class EditProfile extends StatefulWidget { EditProfile({Key key}) : super(key: key);
@override _EditProfile createState() => _EditProfile(); }
class _EditProfile extends State { File _pickedImage; @override
Widget build(BuildContext context) { return ScreenUtilInit( builder: () => Scaffold( appBar: AppBar( title:Text("Edit Your Profile"), ), body:ListView( children:[ Center( child: CircleAvatar( radius:80, child: _pickedImage == null?Text("picture"):null, backgroundImage: _pickedImage != null? FileImage(_pickedImage):null, ), ), const SizedBox(height: 100.0), RaisedButton( child: Text("pick Image"), onPressed: (){ _showPickOptionsDialog(context); },
) ], ), ), ); }
_loadPicker(ImageSource source) async { File picked = await ImagePicker.pickImage(source: source); if (picked != null) { setState((){ _pickedImage=picked; }); } Navigator.pop(context); }
_cropImage(File picked) async { File cropped = await ImageCropper.cropImage( androidUiSettings: AndroidUiSettings( statusBarColor: Colors.red, toolbarColor: Colors.red, toolbarTitle: "Crop Image", toolbarWidgetColor: Colors.white, ), sourcePath: picked.path, aspectRatioPresets: [ CropAspectRatioPreset.original, CropAspectRatioPreset.ratio16x9, CropAspectRatioPreset.ratio4x3, ], maxWidth: 800, ); if (cropped != null) { setState(() { _pickedImage = cropped; }); } } void _showPickOptionsDialog(BuildContext context) { showDialog( context: context, builder: (context) => AlertDialog( content: Column( mainAxisSize: MainAxisSize.min, children: [ ListTile( title: Text("Pick from Gallery"), onTap: () { _loadPicker(ImageSource.gallery); }, ), ListTile( title: Text("Take a pictuer"), onTap: () { _loadPicker(ImageSource.camera); }, ) ], ), ), ); } }
when i upload a picture or take a photo my app closes this is my code:
import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:partners_app/widgets/orange_button.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_screenutil/screenutil_init.dart'; import 'dart:io'; import 'package:image_cropper/image_cropper.dart'; import 'package:image_picker/image_picker.dart'; class EditProfile extends StatefulWidget { EditProfile({Key key}) : super(key: key);
@override _EditProfile createState() => _EditProfile(); }
class _EditProfile extends State {
File _pickedImage;
@override
Widget build(BuildContext context) { return ScreenUtilInit( builder: () => Scaffold( appBar: AppBar( title:Text("Edit Your Profile"), ), body:ListView( children:[
Center(
child: CircleAvatar(
radius:80,
child: _pickedImage == null?Text("picture"):null,
backgroundImage:
_pickedImage != null? FileImage(_pickedImage):null,
),
),
const SizedBox(height: 100.0),
RaisedButton(
child: Text("pick Image"),
onPressed: (){
_showPickOptionsDialog(context);
},
_loadPicker(ImageSource source) async { File picked = await ImagePicker.pickImage(source: source); if (picked != null) { setState((){ _pickedImage=picked; }); } Navigator.pop(context); }
_cropImage(File picked) async { File cropped = await ImageCropper.cropImage( androidUiSettings: AndroidUiSettings( statusBarColor: Colors.red, toolbarColor: Colors.red, toolbarTitle: "Crop Image", toolbarWidgetColor: Colors.white, ), sourcePath: picked.path, aspectRatioPresets: [ CropAspectRatioPreset.original, CropAspectRatioPreset.ratio16x9, CropAspectRatioPreset.ratio4x3, ], maxWidth: 800, ); if (cropped != null) { setState(() { _pickedImage = cropped; }); } } void _showPickOptionsDialog(BuildContext context) { showDialog( context: context, builder: (context) => AlertDialog( content: Column( mainAxisSize: MainAxisSize.min, children:[
ListTile(
title: Text("Pick from Gallery"),
onTap: () {
_loadPicker(ImageSource.gallery);
},
),
ListTile(
title: Text("Take a pictuer"),
onTap: () {
_loadPicker(ImageSource.camera);
},
)
],
),
),
);
}
}