Skip to content

Commit

Permalink
imageEditor
Browse files Browse the repository at this point in the history
  • Loading branch information
Hyunjoo Lee authored and Hyunjoo Lee committed Aug 11, 2022
1 parent d6ed0e7 commit ea148d8
Show file tree
Hide file tree
Showing 4 changed files with 170 additions and 27 deletions.
2 changes: 1 addition & 1 deletion android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ android {
applicationId "com.swjungle.nemo_flutter"
// You can update the following values to match your application needs.
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration.
minSdkVersion 20
minSdkVersion 21
targetSdkVersion 32
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
Expand Down
112 changes: 100 additions & 12 deletions lib/screens/mypage/cardeditor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ import '../../models/mypage/user.dart';
import '../sharing/sharing.dart';
import '../../secrets.dart';
import 'package:flutter/services.dart';
import 'package:image_editor_plus/image_editor_plus.dart';
import 'dart:typed_data';
import 'package:path_provider/path_provider.dart';
import 'package:path/path.dart' as path;

const BASE_URL = 'https://storage.googlea'
'pis.com/nemo-bucket/';

Map<String, int> CHANGED = {
'nickname': 0,
Expand Down Expand Up @@ -152,6 +159,7 @@ class _CardEditorState extends State<CardEditor> {
dynamic tagImage3;
var detailTitle;
var detailContent;
var pickedImage;

checkUser() async {
dynamic userInfo = await storage.read(key: 'login');
Expand Down Expand Up @@ -236,13 +244,89 @@ class _CardEditorState extends State<CardEditor> {
// setEverything(user);
}

saveUserImage(File file) {
Future<void> _download(String url) async {
final response = await http.get(Uri.parse(url));

// Get the image name
final imageName = path.basename(url);
// Get the document directory path
final appDir = await getApplicationDocumentsDirectory();

// This is the saved image path
// You can use it to display the saved image later
final localPath = path.join(appDir.path, imageName);

// Downloading
final imageFile = File(localPath);
await imageFile.writeAsBytes(response.bodyBytes);
setState(() {
userImage = file;
CHANGED['userImage'] = 1;
pickedImage = imageFile;
});
}

int editCount = 0;
Future getImage(context) async {
print('getImage 들어옴!!!!!!!!!');
print('CHANGED[\'userImage\'] = ${CHANGED['userImage']}');
Uint8List bytes = Uint8List(0);

if (CHANGED['userImage'] == 0) {
await _download(BASE_URL + userImage.path);
} else {
setState(() {
pickedImage = userImage;
});
}
// var pickedImage =
// await ImagePicker().pickImage(source: ImageSource.gallery);
if (pickedImage != null) {
File imageFile = File(pickedImage.path);
await imageFile
.readAsBytes()
.then((value) => bytes = Uint8List.fromList(value))
.catchError((onError) {
print('Exception error while reading file from path');
});
print(
'pickedImage.path = ${pickedImage.path}!!!!!!!!!!!!!'); //어쩐지 이게 계속 똑같더
// var finalImage = Image.file(imageFile);
// var data = await rootBundle.load(pickedImage.path);
var imageData = bytes.buffer.asUint8List();
var editedImage = await Navigator.push(
context,
MaterialPageRoute(
builder: (context) => ImageEditor(
image: imageData,
),
),
);
// print('editedImage = ${editedImage.path}');
if (editedImage != null) {
Uint8List imageInUnit8List =
editedImage; // store unit8List image here ;
final tempDir = await getTemporaryDirectory();
File file = await File('${tempDir.path}/image$editCount.png').create();
file.writeAsBytesSync(imageInUnit8List);
setState(() {
userImage = file;
CHANGED['userImage'] = 1;
editCount++;
});
print('file.path = ${file.path}');
} else {
print('Edited Image was null~~~~~~~');
}
print('처리 다 끝났달룽~~~~~~~~~~');
}
}

// saveUserImage(File file) {
// setState(() {
// userImage = file;
// CHANGED['userImage'] = 1;
// });
// }

saveTagImage(int num, File picture) {
setState(() {
if (num == 1) {
Expand Down Expand Up @@ -346,7 +430,8 @@ class _CardEditorState extends State<CardEditor> {
tags: tags,
introduction: introduction,
userImage: userImage,
saveUserImage: saveUserImage,
// saveUserImage: saveUserImage,
getImage: getImage,
user: user,
),
Padding(padding: EdgeInsets.fromLTRB(0, 0, 0, 25)),
Expand Down Expand Up @@ -768,13 +853,15 @@ class NameCard extends StatefulWidget {
this.tags,
this.introduction,
this.userImage,
this.saveUserImage,
// this.saveUserImage,
this.getImage,
this.user})
: super(key: key);

var nickname, tags, introduction;
dynamic userImage;
var saveUserImage;
// var saveUserImage;
var getImage;
var user;

@override
Expand Down Expand Up @@ -810,12 +897,13 @@ class _NameState extends State<NameCard> {
decoration: BoxDecoration(color: Color(0xffE6E6FA)),
child: InkWell(
onTap: () async {
var picker = ImagePicker();
var image =
await picker.pickImage(source: ImageSource.gallery);
if (image != null) {
widget.saveUserImage(File(image.path));
}
await widget.getImage(context);
// var picker = ImagePicker();
// var image =
// await picker.pickImage(source: ImageSource.gallery);
// if (image != null) {
// widget.saveUserImage(File(image.path));
// }
},
child: ClipRRect(
borderRadius: BorderRadius.only(
Expand Down
79 changes: 65 additions & 14 deletions lib/screens/mypage/cardgenerator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import 'package:image_picker/image_picker.dart';
import 'package:http/http.dart' as http;
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:flutter/services.dart';
import 'package:image_editor_plus/image_editor_plus.dart';
import 'dart:typed_data';
import 'package:path_provider/path_provider.dart';

import '../sharing/sharing.dart';
import '../../secrets.dart';
Expand Down Expand Up @@ -131,13 +134,57 @@ class _NameCardGeneratorState extends State<NameCardGenerator> {
dynamic tagImage3 = Image.asset('assets/mypage/grey_gallery.png');
var detailTitle = '인삿말을 입력해주세요!';
var detailContent = '더 하고픈 말이 있나요?';

saveUserImage(File file) {
setState(() {
userImage = file;
});
int editCount = 0;

Future getImage(context) async {
Uint8List bytes = Uint8List(0);

var pickedImage =
await ImagePicker().pickImage(source: ImageSource.gallery);
if (pickedImage != null) {
File imageFile = File(pickedImage.path);
await imageFile
.readAsBytes()
.then((value) => bytes = Uint8List.fromList(value))
.catchError((onError) {
print('Exception error while reading file from path');
});
print('pickedImage.path = ${pickedImage.path}!!!!!!!!!!!!!');
// var finalImage = Image.file(imageFile);
// var data = await rootBundle.load(pickedImage.path);
var imageData = bytes.buffer.asUint8List();
var editedImage = await Navigator.push(
context,
MaterialPageRoute(
builder: (context) => ImageEditor(
image: imageData,
),
),
);
// print('editedImage = ${editedImage.path}');
if (editedImage != null) {
Uint8List imageInUnit8List =
editedImage; // store unit8List image here ;
final tempDir = await getTemporaryDirectory();
File file = await File('${tempDir.path}/image$editCount.png').create();
file.writeAsBytesSync(imageInUnit8List);
setState(() {
userImage = file;
editCount++;
});
} else {
print('Edited Image was null~~~~~~~');
}
print('처리 다 끝났달룽~~~~~~~~~~');
}
}

// saveUserImage(File file) {
// setState(() {
// userImage = file;
// });
// }

saveTagImage(int num, File picture) {
setState(() {
if (num == 1) {
Expand Down Expand Up @@ -252,7 +299,8 @@ class _NameCardGeneratorState extends State<NameCardGenerator> {
tags: tags,
introduction: introduction,
userImage: userImage,
saveUserImage: saveUserImage,
getImage: getImage,
// saveUserImage: saveUserImage,
),
Padding(padding: EdgeInsets.fromLTRB(0, 0, 0, 25)),
SizedBox(
Expand Down Expand Up @@ -643,12 +691,14 @@ class NameCard extends StatefulWidget {
this.tags,
this.introduction,
this.userImage,
this.saveUserImage,
// this.saveUserImage,
this.getImage,
}) : super(key: key);

var nickname, tags, introduction;
dynamic userImage;
var saveUserImage;
// var saveUserImage;
var getImage;

@override
State<NameCard> createState() => _NameState();
Expand Down Expand Up @@ -683,12 +733,13 @@ class _NameState extends State<NameCard> {
margin: EdgeInsets.fromLTRB(0, 0, 10, 0),
child: GestureDetector(
onTap: () async {
var picker = ImagePicker();
var image =
await picker.pickImage(source: ImageSource.gallery);
if (image != null) {
widget.saveUserImage(File(image.path));
}
await widget.getImage(context);
// var picker = ImagePicker();
// var image =
// await picker.pickImage(source: ImageSource.gallery);
// if (image != null) {
// widget.saveUserImage(File(image.path));
// }
},
child: ClipRRect(
borderRadius: BorderRadius.only(
Expand Down
4 changes: 4 additions & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ dependencies:
qr_code_scanner: ^1.0.0

badges: ^2.0.3
image_editor_plus:
git:
url: https://github.com/jessy1001/image_editor_plus.git
ref: update1nemos #branch name



Expand Down

0 comments on commit ea148d8

Please sign in to comment.