如何解决Flutter:我想在裁剪后将图像从相机或图库保存到下一页,这是我的代码
我想将图像保存到下一页,但在裁剪图像后会打开下一页但图像未保存,这是我的代码,它打开相机拍摄图片或打开图库,但裁剪后仅拍摄到下一页我应该怎么做才能将裁剪的图像保存到下一页。我尝试了一种方法,但它在 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),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,child: Column(
children: [
IconButton(icon: Icon(Icons.upload_outlined,onPressed: ()
{ getImage(ImageSource.gallery); }
),Text("Upload",style: TextStyle(
color: Colors.white,)
],backgroundColor: Colors.blue,body: Column(
mainAxisAlignment: MainAxisAlignment.end,children: [
Padding(
padding: const EdgeInsets.fromLTRB(0,90,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,radius: 150,Opacity(
opacity:0.7,child: CircleAvatar(
backgroundColor: Colors.blue,radius: 180,IconButton(
iconSize: 80,icon: Icon(Icons.camera_alt,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",);
}
}
(_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),);
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。