-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from Usta66/master
- Loading branch information
Showing
19 changed files
with
660 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+7.34 MB
github/gifs/circle_avatar_image_and_alphabet/circle_avatar_image_and_alphabet.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
lib/feature/circle_avatar_image_and_alphabet/circle_avatar_image_and_alphabet.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import 'dart:io'; | ||
|
||
import 'package:auto_size_text/auto_size_text.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
import 'package:kartal/kartal.dart'; | ||
|
||
class CircleAvatarImageAndAlphabet extends StatelessWidget { | ||
final Function()? onTap; | ||
final String? imagePath; | ||
final String? text; | ||
final int? color; | ||
final bool isFullText; | ||
final double radius; | ||
|
||
const CircleAvatarImageAndAlphabet({Key? key, this.onTap, required this.radius, this.text, this.imagePath, this.color, this.isFullText = false}) | ||
: super(key: key); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return GestureDetector( | ||
onTap: onTap, | ||
child: Row(mainAxisAlignment: MainAxisAlignment.center, children: [ | ||
CircleAvatar( | ||
backgroundImage: imagePath == null ? null : FileImage(File(imagePath!)), | ||
radius: radius, | ||
child: imagePath == null | ||
? Padding( | ||
padding: context.paddingLow, | ||
child: AutoSizeText( | ||
text != null ? getTextFirsCharter(text!) : " ", | ||
style: Theme.of(context).textTheme.headline3, | ||
textAlign: TextAlign.center, | ||
maxLines: 2, | ||
), | ||
) | ||
: null, | ||
backgroundColor: color != null ? Color(color!) : null), | ||
]), | ||
); | ||
} | ||
|
||
String getTextFirsCharter(String text) { | ||
String value = ""; | ||
var splitTextList = text.split(" "); | ||
|
||
if (isFullText) { | ||
return text.toUpperCase(); | ||
} else { | ||
for (var element in splitTextList) { | ||
if (element.isNotNullOrNoEmpty) { | ||
value = value + element[0]; | ||
} | ||
} | ||
|
||
return value.toUpperCase(); | ||
} | ||
} | ||
} |
78 changes: 78 additions & 0 deletions
78
...rcle_avatar_image_and_alphabet_example/circle_avatar_image_and_alphabet_example_view.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:provider/provider.dart'; | ||
import 'package:ready_to_use_widgets/feature/circle_avatar_image_and_alphabet/circle_avatar_image_and_alphabet.dart'; | ||
import 'package:kartal/kartal.dart'; | ||
import '../../../atomic/text_field/custom_text_field.dart'; | ||
import 'circle_avatar_image_and_alphabet_example_view_model.dart'; | ||
|
||
class CircleAvatarImageAndAlphabetExampleView extends StatelessWidget { | ||
const CircleAvatarImageAndAlphabetExampleView({Key? key, required this.viewModel}) : super(key: key); | ||
|
||
final CircleAvatarImageAndAlphabetExampleViewModel viewModel; | ||
@override | ||
Widget build(BuildContext context) { | ||
return ChangeNotifierProvider( | ||
create: (context) => viewModel, | ||
builder: (context, child) { | ||
return Scaffold( | ||
appBar: AppBar( | ||
centerTitle: true, | ||
title: const Text("Circle Avatar Image And Alphabet"), | ||
), | ||
body: SingleChildScrollView( | ||
child: Padding( | ||
padding: context.paddingMedium, | ||
child: Center( | ||
child: Column( | ||
mainAxisSize: MainAxisSize.min, | ||
children: [ | ||
Row( | ||
mainAxisAlignment: MainAxisAlignment.center, | ||
children: [ | ||
IconButton( | ||
onPressed: () { | ||
viewModel.getImage(false); | ||
}, | ||
icon: const Icon(Icons.add_a_photo_outlined)), | ||
Consumer<CircleAvatarImageAndAlphabetExampleViewModel>( | ||
builder: (context, value, child) { | ||
return CircleAvatarImageAndAlphabet( | ||
color: viewModel.color, | ||
imagePath: viewModel.image == null ? null : viewModel.image!.path, | ||
radius: context.width * 0.2, | ||
text: viewModel.controllerAdi.text + " " + viewModel.controllerSoyadi.text, | ||
onTap: () { | ||
viewModel.selectedColor(context); | ||
}, | ||
); | ||
}, | ||
), | ||
IconButton( | ||
onPressed: () { | ||
viewModel.getImage(true); | ||
}, | ||
icon: const Icon(Icons.file_upload)) | ||
], | ||
), | ||
Padding( | ||
padding: context.verticalPaddingLow, | ||
child: CustomTextField( | ||
controller: viewModel.controllerAdi, | ||
labelText: "Adı", | ||
)), | ||
Padding( | ||
padding: context.verticalPaddingLow, | ||
child: CustomTextField( | ||
controller: viewModel.controllerSoyadi, | ||
labelText: "Soyadi", | ||
)), | ||
], | ||
), | ||
), | ||
), | ||
), | ||
); | ||
}, | ||
); | ||
} | ||
} |
95 changes: 95 additions & 0 deletions
95
...vatar_image_and_alphabet_example/circle_avatar_image_and_alphabet_example_view_model.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import 'dart:io'; | ||
|
||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_colorpicker/flutter_colorpicker.dart'; | ||
import 'package:image_cropper/image_cropper.dart'; | ||
import 'package:image_picker/image_picker.dart'; | ||
|
||
class CircleAvatarImageAndAlphabetExampleViewModel extends ChangeNotifier { | ||
final picker = ImagePicker(); | ||
File? image; | ||
int color = 0xFFFF9000; | ||
|
||
set changeColor(int color) { | ||
color = color; | ||
notifyListeners(); | ||
} | ||
|
||
late TextEditingController controllerAdi, controllerSoyadi; | ||
CircleAvatarImageAndAlphabetExampleViewModel() { | ||
controllerAdi = TextEditingController() | ||
..addListener(() { | ||
notifyListeners(); | ||
}); | ||
|
||
controllerSoyadi = TextEditingController() | ||
..addListener(() { | ||
notifyListeners(); | ||
}); | ||
} | ||
|
||
getImage(bool issourceGallery) async { | ||
final pickedFile = await picker.pickImage(source: issourceGallery ? ImageSource.gallery : ImageSource.camera); | ||
|
||
if (pickedFile != null) { | ||
image = File(pickedFile.path); | ||
|
||
image = await _cropImage(image); | ||
} | ||
|
||
notifyListeners(); | ||
} | ||
|
||
Future<File?>? _cropImage(File? image) async { | ||
if (image != null) { | ||
var croppedFile = await ImageCropper.platform.cropImage(sourcePath: image.path, aspectRatioPresets: [ | ||
CropAspectRatioPreset.square, | ||
CropAspectRatioPreset.ratio3x2, | ||
CropAspectRatioPreset.original, | ||
CropAspectRatioPreset.ratio4x3, | ||
CropAspectRatioPreset.ratio16x9 | ||
], uiSettings: [ | ||
AndroidUiSettings( | ||
toolbarTitle: 'Cropper', | ||
toolbarColor: Colors.deepOrange, | ||
toolbarWidgetColor: Colors.white, | ||
initAspectRatio: CropAspectRatioPreset.original, | ||
lockAspectRatio: false), | ||
IOSUiSettings( | ||
title: 'Cropper', | ||
) | ||
]); | ||
|
||
if (croppedFile != null) { | ||
return File(croppedFile.path); | ||
} else { | ||
return null; | ||
} | ||
} else { | ||
return null; | ||
} | ||
} | ||
|
||
void selectedColor(BuildContext context) { | ||
showDialog( | ||
context: context, | ||
builder: (context) { | ||
return AlertDialog( | ||
content: SingleChildScrollView( | ||
child: MaterialPicker( | ||
pickerColor: Colors.deepOrange, | ||
onColorChanged: (secilenRenk) { | ||
color = secilenRenk.value; | ||
|
||
image = null; | ||
|
||
notifyListeners(); | ||
|
||
Navigator.pop(context); | ||
}, | ||
), | ||
), | ||
); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
|
||
|
||
Bu widget'a image path verdiğiniz zaman verilen image gösterir. | ||
Image path null ise verilen tetx'in baş haflerini veya tamamını | ||
avatarın içine yazdırabilirsiniz. | ||
|
||
[Gif](github/gifs/circle_avatar_image_and_alphabet/circle_avatar_image_and_alphabet.gif) |
Oops, something went wrong.