I want to save the image to the next page but after cropping the image it opens the next page but the image is not saved, here is my code it opens the camera take the pic or open gallery but after cropping it only take to the next page what should I do to save the cropped image to next page.I tried a method but it returns the image on UIpage.
import 'package:flutter/material.dart';
import 'package:fyp/ui.dart';
import 'package:fyp/Analyze.dart';
void main() {
runApp(MaterialApp(home: MyApp()));
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Ui(),
),
);
}
}
import 'package:flutter/material.dart';
import 'package:fyp/Analyze.dart';
import 'dart:io';
import 'package:image_picker/image_picker.dart';
import 'package:image_cropper/image_cropper.dart';
class Ui extends StatefulWidget {
@override
_UiState createState() => _UiState();
}
class _UiState extends State<Ui> {
String path;
File _selectedFile;
bool _inProcess1 = false;
@override
void initState() {
super.initState();
}
getImage(ImageSource source) async {
this.setState((){
_inProcess1 = true;
});
File image = await ImagePicker.pickImage(source: source);
if(image != null){
File cropped = await ImageCropper.cropImage(
sourcePath: image.path,
aspectRatio: CropAspectRatio(
ratioX: 1, ratioY: 1),
compressQuality: 100,
maxWidth: 700,
maxHeight: 700,
compressFormat: ImageCompressFormat.jpg,
androidUiSettings: AndroidUiSettings(
toolbarColor: Colors.deepOrange,
toolbarTitle: "RPS Cropper",
statusBarColor: Colors.deepOrange.shade900,
backgroundColor: Colors.white,
)
);
this.setState((){
_selectedFile = cropped;
return Analyze();
_inProcess1 = false;
});
} else {
this.setState((){
_inProcess1 = false;
});
}
}
@override
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold(
appBar: AppBar(
elevation: 0,
toolbarHeight: 100,
leading:Padding(
padding: const EdgeInsets.fromLTRB(15, 20, 0, 0),
child: Column(
children: [
IconButton(icon: Icon(Icons.info_outlined, color: Colors.white,
size: 30,),
onPressed: ()=>null,),
Text(" Help",style: TextStyle(
color: Colors.white,
fontSize: 16,
), ),
],
),
),
actions: [
Padding(
padding: const EdgeInsets.fromLTRB(0, 20, 20, 0),
child: Column(
children: [
IconButton(icon: Icon(Icons.upload_outlined, color: Colors.white,
size: 30,),
onPressed: ()
{ getImage(ImageSource.gallery); }
),
Text("Upload",style: TextStyle(
color: Colors.white,
fontSize: 16,
), ),
],
),
)
],
),
backgroundColor: Colors.blue,
body: Column(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Padding(
padding: const EdgeInsets.fromLTRB(0, 90, 0, 60),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Stack(
alignment: Alignment.center,
children: [
Opacity(
opacity:0.6,
child: CircleAvatar( // use to create circle
backgroundColor: Colors.white,
radius: 80,
),
),
Opacity(
opacity:0.5,
child: CircleAvatar(
backgroundColor: Colors.white,
radius: 120,
),
),
Opacity(
opacity:0.3,
child: CircleAvatar(
backgroundColor: Colors.white,
radius: 150,
),
),
Opacity(
opacity:0.7,
child: CircleAvatar(
backgroundColor: Colors.blue,
radius: 180,
),
),
IconButton(
iconSize: 80,
icon: Icon(Icons.camera_alt, color: Colors.white,),
onPressed: () {
getImage(ImageSource.camera);
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => Analyze(
),
),
);
},
),
],
),
],
),
),
Text("Tap to scan", style: TextStyle(
color: Colors.white,
fontSize: 20,
),),
SizedBox(
height: 20,
width: 150,
child: Divider(
color: Colors.white,
thickness: 3,
),
),
],
),
),
);
}
}
import 'package:flutter/material.dart';
import 'dart:io';
class Analyze extends StatefulWidget {
@override
_AnalyzeState createState() => _AnalyzeState();
}
class _AnalyzeState extends State<Analyze> {
File _selectedFile;
bool _inProcess = false;
@override
Widget build(BuildContext context) {
Widget getImageWidget(File selectedFile) {
if (_selectedFile != null) {
return Image.file(
_selectedFile,
width: 250,
height: 250,
fit: BoxFit.cover,
);
} else {
return Image.asset(
"assets/placeholder.jpg",
width: 250,
height: 250,
fit: BoxFit.cover,
);
}
}
(_inProcess)
? Container(
color: Colors.white,
height: MediaQuery.of(context).size.height * 0.95,
child: Center(
child: CircularProgressIndicator(),
),
)
: Center();
return SafeArea(
child: Scaffold(
body: Column(
children: [
getImageWidget(_selectedFile),
],
),
),
);
}