jihanislam007 / flutter_image_picker

0 stars 0 forks source link

Not able to upload image. Please help #1

Open raahul976 opened 3 years ago

raahul976 commented 3 years ago

`import 'dart:io'; import 'package:driver_pilot/date_picker.dart'; import 'package:flutter/gestures.dart'; import 'package:flutter/material.dart'; import '../constants.dart'; import 'package:image_picker/image_picker.dart'; import 'package:url_launcher/url_launcher.dart'; import 'package:driver_pilot/components/components.dart';

class SignUp extends StatefulWidget { const SignUp({Key? key}) : super(key: key);

@override _SignUpState createState() => _SignUpState(); }

class _SignUpState extends State { late XFile _image; final ImagePicker _picker = ImagePicker(); Future getImage() async { XFile? pickedFile = await _picker.pickImage(source: ImageSource.gallery);

setState(() {
  _image = pickedFile!;
});

}

@override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( centerTitle: true, title: Text( 'Sign Up', ), ), body: Center( child: SingleChildScrollView( child: Padding( padding: const EdgeInsets.all(30.0), child: Center( child: Column( children: [ Stack(children: [ Container( margin: EdgeInsets.only(top: 48), height: 60, decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.circular(16.0), ), ), Align( alignment: Alignment.topCenter, child: SizedBox( child: CircleAvatar( radius: 40.0, backgroundColor: Colors.white, child: CircleAvatar( child: Align( alignment: Alignment.bottomRight, child: CircleAvatar( backgroundColor: Colors.white, radius: 14.0, // child: Icon( // Icons.camera_alt, // size: 15.0, // color: Color(0xFF404040), // ), child: IconButton( icon: const Icon(Icons.camera_alt), color: Colors.black, iconSize: 15.0, onPressed: getImage, padding: EdgeInsets.zero, ), ), ), radius: 68.0, backgroundImage: NetworkImage( 'https://comicvine.gamespot.com/a/uploads/scale_medium/12/124259/7538232-three-jokers-1-cvr-fnl-1583776056592.jpg'), ), ), )), ]), // SizedBox( // height: 20.0, // ), BuildFirstName(), SizedBox( height: 20.0, ), BuildLastName(), SizedBox( height: 20.0, ), BuildSignUpPhone(), SizedBox( height: 20.0, ), BirthDate(), SizedBox( height: 20.0, ), Container( child: _image == null ? Text('No image selected') : Image.file(_image), ), LabelForCamUpload( label: 'Civil Id', ), SizedBox( height: 10.0, ), CamUploadWidget(), SizedBox( height: 15.0, ), LabelForCamUpload( label: 'Driving Licence', ), SizedBox( height: 10.0, ), CamUploadWidget(), SizedBox( height: 15.0, ), LabelForCamUpload( label: 'Vehicle Registration', ), SizedBox( height: 10.0, ), CamUploadWidget(), Padding( padding: const EdgeInsets.symmetric( vertical: 30.0, horizontal: 10.0), child: RichText( text: TextSpan( children: [ TextSpan( text: 'By signing up, you\'re agreeing to our ', style: kTermsAndCondTextStyle), TextSpan( text: 'Terms of Service and Privacy Policy.', style: kTermsAndCondTextStyle.copyWith( decoration: TextDecoration.underline, ), recognizer: TapGestureRecognizer() ..onTap = () async { final url = 'https://docs.google.com/gview?embedded=true&url=https://www.urwagon.com/wagon_backendV2/public/policy_terms/WagonPrivacyPolicy.pdf'; if (await canLaunch(url)) { await launch( url, forceSafariVC: false, ); } }, ), ], ), ), ), ElevatedButton( onPressed: () {}, child: Text( 'SIGN UP', style: kButtonTextStyle, ), style: ElevatedButton.styleFrom( primary: kWagonColour, fixedSize: Size(325.0, 40.0), ), ), ], ), ), ), ), ), ); } } `

jihanislam007 commented 3 years ago

I think you may try this code below, there are several ways to solve it. thanks

///////In pubspec.yaml///////////// dependencies: flutter: sdk: flutter image_picker: ^0.6.2 ///////////dart code//////////////// import 'dart:io'; import 'package:flutter/material.dart'; import 'package:image_picker/image_picker.dart';

class HomePage extends StatefulWidget { @override _HomePageState createState() => _HomePageState(); }

class _HomePageState extends State { File? _image; File? imageFile; Future cameraImage() async { var image = await ImagePicker.pickImage(source: ImageSource.camera);

setState(() {
  _image = image;
});

}

Future GalleryImage() async { var image = await ImagePicker.pickImage(source: ImageSource.gallery);

setState(() {
  _image = image;
});

} _getFromGallery() async { PickedFile pickedFile = await ImagePicker().getImage( source: ImageSource.gallery, maxWidth: 1800, maxHeight: 1800, ); if (pickedFile != null) { imageFile = File(pickedFile.path); } }

final picker = ImagePicker();

Future getImage() async { final pickedFile = await picker.getImage(source: ImageSource.gallery);

setState(() {
  if (pickedFile != null) {
    _image = File(pickedFile.path);
  } else {
    print('No image selected.');
  }
});

}

@override Widget build(BuildContext context) {

return Scaffold(
  appBar: AppBar(
    title: Text('Test.com'),
  ),
  body: ListView(
    children: [

      Container(
        height: 400,
        width: double.infinity,
        color: Colors.green,
        child: Flexible(
          child: _image == null
              ? Center(child: Text("There is no Image is selected"))
              : Image.file(_image),
        )
      ),

      Divider(thickness: 2,),
      Row(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          ElevatedButton(
              onPressed: () {
                cameraImage();
              },
              child: const Text('camera')),
          SizedBox(width: 20),
          ElevatedButton(
              onPressed: () {
                //GalleryImage();
                //_getFromGallery();
                getImage();
              },
              child: const Text('gallary'))
        ],
      )
    ],
  ),
);

} }

//////

On Thu, Aug 5, 2021 at 11:55 AM Rahul Suthar @.***> wrote:

`import 'dart:io'; import 'package:driver_pilot/date_picker.dart'; import 'package:flutter/gestures.dart'; import 'package:flutter/material.dart'; import '../constants.dart'; import 'package:image_picker/image_picker.dart'; import 'package:url_launcher/url_launcher.dart'; import 'package:driver_pilot/components/components.dart';

class SignUp extends StatefulWidget { const SignUp({Key? key}) : super(key: key);

@override https://github.com/override _SignUpState createState() => _SignUpState(); }

class _SignUpState extends State { late XFile _image; final ImagePicker _picker = ImagePicker(); Future getImage() async { XFile? pickedFile = await _picker.pickImage(source: ImageSource.gallery);

setState(() { _image = pickedFile!; });

}

@override https://github.com/override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( centerTitle: true, title: Text( 'Sign Up', ), ), body: Center( child: SingleChildScrollView( child: Padding( padding: const EdgeInsets.all(30.0), child: Center( child: Column( children: [ Stack(children: [ Container( margin: EdgeInsets.only(top: 48), height: 60, decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.circular(16.0), ), ), Align( alignment: Alignment.topCenter, child: SizedBox( child: CircleAvatar( radius: 40.0, backgroundColor: Colors.white, child: CircleAvatar( child: Align( alignment: Alignment.bottomRight, child: CircleAvatar( backgroundColor: Colors.white, radius: 14.0, // child: Icon( // Icons.camera_alt, // size: 15.0, // color: Color(0xFF404040), // ), child: IconButton( icon: const Icon(Icons.camera_alt), color: Colors.black, iconSize: 15.0, onPressed: getImage, padding: EdgeInsets.zero, ), ), ), radius: 68.0, backgroundImage: NetworkImage( ' https://comicvine.gamespot.com/a/uploads/scale_medium/12/124259/7538232-three-jokers-1-cvr-fnl-1583776056592.jpg' ), ), ), )), ]), // SizedBox( // height: 20.0, // ), BuildFirstName(), SizedBox( height: 20.0, ), BuildLastName(), SizedBox( height: 20.0, ), BuildSignUpPhone(), SizedBox( height: 20.0, ), BirthDate(), SizedBox( height: 20.0, ), Container( child: _image == null ? Text('No image selected') : Image.file(_image), ), LabelForCamUpload( label: 'Civil Id', ), SizedBox( height: 10.0, ), CamUploadWidget(), SizedBox( height: 15.0, ), LabelForCamUpload( label: 'Driving Licence', ), SizedBox( height: 10.0, ), CamUploadWidget(), SizedBox( height: 15.0, ), LabelForCamUpload( label: 'Vehicle Registration', ), SizedBox( height: 10.0, ), CamUploadWidget(), Padding( padding: const EdgeInsets.symmetric( vertical: 30.0, horizontal: 10.0), child: RichText( text: TextSpan( children: [ TextSpan( text: 'By signing up, you're agreeing to our ', style: kTermsAndCondTextStyle), TextSpan( text: 'Terms of Service and Privacy Policy.', style: kTermsAndCondTextStyle.copyWith( decoration: TextDecoration.underline, ), recognizer: TapGestureRecognizer() ..onTap = () async { final url = ' https://docs.google.com/gview?embedded=true&url=https://www.urwagon.com/wagon_backendV2/public/policy_terms/WagonPrivacyPolicy.pdf '; if (await canLaunch(url)) { await launch( url, forceSafariVC: false, ); } }, ), ], ), ), ), ElevatedButton( onPressed: () {}, child: Text( 'SIGN UP', style: kButtonTextStyle, ), style: ElevatedButton.styleFrom( primary: kWagonColour, fixedSize: Size(325.0, 40.0), ), ), ], ), ), ), ), ), ); } } `

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/jihanislam007/flutter_image_picker/issues/1, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADJBWU7LJATFKIU3PAS6PBLT3IRUDANCNFSM5BSW3EXA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&utm_campaign=notification-email .

-- With Best Regards

MD. Mazaharul Islam Jihan BSc in CSE (UAP), Msc in IT (JU)