mukodo cucc
This commit is contained in:
@@ -13,20 +13,22 @@ import 'package:flutter_feather_icons/flutter_feather_icons.dart';
|
||||
import 'package:filcnaplo_mobile_ui/screens/settings/settings_screen.i18n.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
import 'package:image_crop/image_crop.dart';
|
||||
|
||||
class UserMenuProfilePic extends StatelessWidget {
|
||||
const UserMenuProfilePic({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (!Provider.of<PremiumProvider>(context).hasScope(PremiumScopes.nickname)) {
|
||||
if (!Provider.of<PremiumProvider>(context)
|
||||
.hasScope(PremiumScopes.nickname)) {
|
||||
return const SizedBox();
|
||||
}
|
||||
|
||||
return BottomSheetMenuItem(
|
||||
onPressed: () {
|
||||
showDialog(context: context, builder: (context) => const UserProfilePicEditor());
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => const UserProfilePicEditor());
|
||||
},
|
||||
icon: const Icon(FeatherIcons.camera),
|
||||
title: Text("edit_profile_picture".i18n),
|
||||
@@ -44,7 +46,6 @@ class UserProfilePicEditor extends StatefulWidget {
|
||||
class _UserProfilePicEditorState extends State<UserProfilePicEditor> {
|
||||
late final UserProvider user;
|
||||
|
||||
final cropKey = GlobalKey<CropState>();
|
||||
File? _file;
|
||||
File? _sample;
|
||||
File? _lastCropped;
|
||||
@@ -56,16 +57,10 @@ class _UserProfilePicEditorState extends State<UserProfilePicEditor> {
|
||||
if (image == null) return;
|
||||
File imageFile = File(image.path);
|
||||
|
||||
final sample = await ImageCrop.sampleImage(
|
||||
file: imageFile,
|
||||
preferredSize: context.size!.longestSide.ceil(),
|
||||
);
|
||||
|
||||
_sample?.delete();
|
||||
_file?.delete();
|
||||
|
||||
setState(() {
|
||||
_sample = sample;
|
||||
_file = imageFile;
|
||||
});
|
||||
} on PlatformException catch (e) {
|
||||
@@ -73,16 +68,6 @@ class _UserProfilePicEditorState extends State<UserProfilePicEditor> {
|
||||
}
|
||||
}
|
||||
|
||||
Widget cropImageWidget() {
|
||||
return SizedBox(
|
||||
height: 300,
|
||||
child: Crop.file(
|
||||
_sample!,
|
||||
key: cropKey,
|
||||
aspectRatio: 1.0,
|
||||
));
|
||||
}
|
||||
|
||||
Widget openImageWidget() {
|
||||
return InkWell(
|
||||
customBorder: RoundedRectangleBorder(
|
||||
@@ -90,18 +75,22 @@ class _UserProfilePicEditorState extends State<UserProfilePicEditor> {
|
||||
),
|
||||
onTap: () => pickImage(),
|
||||
child: Container(
|
||||
decoration: BoxDecoration(border: Border.all(color: Colors.grey), borderRadius: BorderRadius.circular(14.0)),
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(color: Colors.grey),
|
||||
borderRadius: BorderRadius.circular(14.0)),
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.symmetric(vertical: 32.0, horizontal: 8.0),
|
||||
child: Column(
|
||||
children: [
|
||||
Text(
|
||||
"click_here".i18n,
|
||||
style: const TextStyle(fontSize: 22.0, fontWeight: FontWeight.w600),
|
||||
style:
|
||||
const TextStyle(fontSize: 22.0, fontWeight: FontWeight.w600),
|
||||
),
|
||||
Text(
|
||||
"select_profile_picture".i18n,
|
||||
style: const TextStyle(fontSize: 14.0, fontWeight: FontWeight.w500),
|
||||
style:
|
||||
const TextStyle(fontSize: 14.0, fontWeight: FontWeight.w500),
|
||||
)
|
||||
],
|
||||
),
|
||||
@@ -110,34 +99,13 @@ class _UserProfilePicEditorState extends State<UserProfilePicEditor> {
|
||||
}
|
||||
|
||||
Future<void> _cropImage() async {
|
||||
final scale = cropKey.currentState!.scale;
|
||||
final area = cropKey.currentState!.area;
|
||||
if (area == null || _file == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final sample = await ImageCrop.sampleImage(
|
||||
file: _file!,
|
||||
preferredSize: (2000 / scale).round(),
|
||||
);
|
||||
|
||||
final file = await ImageCrop.cropImage(
|
||||
file: sample,
|
||||
area: area,
|
||||
);
|
||||
|
||||
sample.delete();
|
||||
|
||||
_lastCropped?.delete();
|
||||
_lastCropped = file;
|
||||
|
||||
List<int> imageBytes = await _lastCropped!.readAsBytes();
|
||||
List<int> imageBytes = await _file!.readAsBytes();
|
||||
String base64Image = base64Encode(imageBytes);
|
||||
user.user!.picture = base64Image;
|
||||
Provider.of<DatabaseProvider>(context, listen: false).store.storeUser(user.user!);
|
||||
Provider.of<DatabaseProvider>(context, listen: false)
|
||||
.store
|
||||
.storeUser(user.user!);
|
||||
Provider.of<UserProvider>(context, listen: false).refresh();
|
||||
|
||||
debugPrint('$file');
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -157,25 +125,30 @@ class _UserProfilePicEditorState extends State<UserProfilePicEditor> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AlertDialog(
|
||||
shape: const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(14.0))),
|
||||
shape: const RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.all(Radius.circular(14.0))),
|
||||
contentPadding: const EdgeInsets.only(top: 10.0),
|
||||
title: Text("edit_profile_picture".i18n),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 12.0, horizontal: 24.0),
|
||||
child: _sample == null ? openImageWidget() : cropImageWidget(),
|
||||
padding:
|
||||
const EdgeInsets.symmetric(vertical: 12.0, horizontal: 24.0),
|
||||
child: openImageWidget(),
|
||||
),
|
||||
if (user.user!.picture != "")
|
||||
TextButton(
|
||||
child: Text(
|
||||
"remove_profile_picture".i18n,
|
||||
style: const TextStyle(fontWeight: FontWeight.w500, color: Colors.red),
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.w500, color: Colors.red),
|
||||
),
|
||||
onPressed: () {
|
||||
user.user!.picture = "";
|
||||
Provider.of<DatabaseProvider>(context, listen: false).store.storeUser(user.user!);
|
||||
Provider.of<DatabaseProvider>(context, listen: false)
|
||||
.store
|
||||
.storeUser(user.user!);
|
||||
Provider.of<UserProvider>(context, listen: false).refresh();
|
||||
Navigator.of(context).pop(true);
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user