Showing posts with label UI. Show all posts
Showing posts with label UI. Show all posts

Thursday, April 25, 2024

Compress Image With Show File Size & Resolution in Flutter

April 25, 2024 0

 Compress Image With Show File Size & Resolution 


1.Multiple File Image Compress with file Size



import 'dart:io';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';
import 'package:imagecompressorandresizer/utils/color.dart';

class CompressPage extends StatefulWidget {
const CompressPage({super.key});

@override
State<CompressPage> createState() => _CompressPageState();
}

class _CompressPageState extends State<CompressPage> {
final ImagePicker imagePicker=ImagePicker();
List<XFile> imageFileList=[];
List<String> imageSizes=[];
int currentPageIndex=0;

// Multiple Image Picker
void selectImage()async{
final List<XFile>? selectedImages=await imagePicker.pickMultiImage();
if(selectedImages!.isNotEmpty){
imageFileList.addAll(selectedImages);

for(var file in selectedImages){
File image=File(file.path);
int sizeInBytes=image.lengthSync();
double sizeInKB=sizeInBytes/1024;
String sizeText;
if(sizeInKB >1024){
double sizeInMB=sizeInKB/1024;
sizeText="${sizeInMB.toStringAsFixed(2)} MB";
}else{
sizeText="${sizeInKB.toStringAsFixed(2)} KB";
}
imageSizes.add(sizeText);
}
}
setState(() {
});
}

@override
Widget build(BuildContext context) {
final size=MediaQuery.of(context).size;
return Scaffold(
appBar: AppBar(
title: Text("Compress Image"),
backgroundColor: backgroundColor,
),

body:SafeArea(
child: Column(
children: [
SizedBox(height: 10,),
Container(
height: size.height / 3,
color: Colors.green,
child: PageView.builder(
itemCount: imageFileList.length,
onPageChanged: (int index) {
setState(() {
currentPageIndex = index;
});
},
itemBuilder: (BuildContext context, int index) {
return Image.file(
File(imageFileList[index].path,),
fit: BoxFit.cover,
);
}
),
),
imageFileList !.isNotEmpty ? Container(
padding: const EdgeInsets.symmetric(vertical: 10,horizontal: 10),
color: Colors.yellow,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text("Selected", style: TextStyle(fontSize: 16),),
Text("${imageFileList.length} images", style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold),),
],
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [

Text("Size", style: TextStyle(fontSize: 16),),
Text("${imageSizes.isNotEmpty && currentPageIndex < imageSizes.length ? imageSizes[currentPageIndex] : ''}", style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold),)
],
),
],
),
): SizedBox(),
],
),
),
);
}
}

2.Image Compress with file Size & resolution

import 'dart:io';
import 'dart:ui' as ui;

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';
import 'package:imagecompressorandresizer/utils/color.dart';

class CompressPage extends StatefulWidget {
const CompressPage({super.key});

@override
State<CompressPage> createState() => _CompressPageState();
}

class _CompressPageState extends State<CompressPage> {
final ImagePicker imagePicker = ImagePicker();
List<XFile> imageFileList = [];
List<String> imageSizes = [];
List<String> imageResolutions = [];
int currentPageIndex = 0;

// Multiple Image Picker
void selectImage() async {
final List<XFile>? selectedImages = await imagePicker.pickMultiImage();
if (selectedImages!.isNotEmpty) {
imageFileList.addAll(selectedImages);

for (var file in selectedImages) {
File image = File(file.path);
int sizeInBytes = image.lengthSync();
double sizeInKB = sizeInBytes / 1024;
String sizeText;
if (sizeInKB > 1024) {
double sizeInMB = sizeInKB / 1024;
sizeText = "${sizeInMB.toStringAsFixed(2)} MB";
} else {
sizeText = "${sizeInKB.toStringAsFixed(2)} KB";
}
imageSizes.add(sizeText);

// Fetching image resolution
ui.Image resolvedImage =
await decodeImageFromList(await image.readAsBytes());
imageResolutions.add('${resolvedImage.width}x${resolvedImage.height}');
}
}
setState(() {});
}

@override
void initState() {
super.initState();
imageSizes = [];
imageResolutions = [];
}

@override
Widget build(BuildContext context) {
final size = MediaQuery.of(context).size;
return Scaffold(
appBar: AppBar(
title: Text("Compress Image"),
backgroundColor: backgroundColor,
),

body: SafeArea(
child: Column(
children: [
SizedBox(
height: 10,
),
Container(
height: size.height / 3,
color: Colors.green,
child: PageView.builder(
itemCount: imageFileList.length,
onPageChanged: (int index) {
setState(() {
currentPageIndex = index;
});
},
itemBuilder: (BuildContext context, int index) {
return Image.file(
File(
imageFileList[index].path,
),
fit: BoxFit.cover,
);
}),
),
imageFileList!.isNotEmpty
? Container(
padding: const EdgeInsets.symmetric(
vertical: 10, horizontal: 10),
color: Colors.yellow,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"Selected",
style: TextStyle(fontSize: 16),
),
Text(
"${imageFileList.length} images",
style: TextStyle(
fontSize: 16, fontWeight: FontWeight.bold),
),
],
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"Size",
style: TextStyle(fontSize: 16),
),
Text(
"${imageSizes.isNotEmpty && currentPageIndex < imageSizes.length ? imageSizes[currentPageIndex] : ''}",
style: TextStyle(
fontSize: 16, fontWeight: FontWeight.bold),
)
],
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"Resolution",
style: TextStyle(fontSize: 16),
),
Text(
"${imageResolutions.isNotEmpty && currentPageIndex < imageResolutions.length ? imageResolutions[currentPageIndex] : ''}",
style: TextStyle(
fontSize: 16, fontWeight: FontWeight.bold),
),
],
),
],
),
)
: SizedBox(),
SizedBox(
width: size.width,
child: ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: backgroundColor,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.zero)),
onPressed: selectImage,
child: Text(
"Select Image",
style: TextStyle(fontSize: 18, color: Colors.white),
))),
],
),
),
);
}
}

3.


ClipPath With CustomClipper in Flutter

April 25, 2024 0

 ClipPath With CustomClipper in Flutter

 1 . Use Here

ClipPath(
clipper: ClipsClipper(),
child: Container(
height: size.height / 2,
color: Colors.red,
),
),

 1 . Use Here with Border

Stack(
children: [
Opacity(
opacity: 0.5,
child: ClipPath(
clipper: ClipsClipper(),
child: Container(
height: size.height / 2,
color: Colors.red,
),
),
),
ClipPath(
clipper: ClipsClipper(),
child: Container(
height: size.height / 2.05,
color: Colors.red,
),
),
],
),


2 . Custom Clipper Class




import 'package:flutter/material.dart';

class ClipsClipper extends CustomClipper<Path>{
@override
Path getClip(Size size){
Path path=Path();

// path.lineTo(0,size.height);
// // path.quadraticBezierTo(0, 0, 50, 600);
// path.lineTo(size.width, size.height);
//
// path.lineTo(size.width, 0);
//
// // path.quadraticBezierTo(size.width, 0, 0, 0);

path.lineTo(0, size.height);
var firstStart= Offset(size.width/5, size.height);
var firstEnd=Offset(size.width/2.25, size.height-40.0);
path.quadraticBezierTo(firstStart.dx, firstStart.dy, firstEnd.dx, firstEnd.dy);

var secondStart=Offset(size.width-(size.width/3.24),size.height-80);
var secondEnd=Offset(size.width, size.height-10);
path.quadraticBezierTo(secondStart.dx, secondStart.dy, secondEnd.dx, secondEnd.dy);
path.lineTo(size.width, 0);

return path;
}
@override
bool shouldReclip(CustomClipper<Path> oldClipper) => true;
}

Saturday, April 13, 2024

Glass Morphism in Flutter

April 13, 2024 0

 Glass Morphism in Flutter



Process:-

                Container(

                    ClipRRect(

                        BackdropFilter(

                            filter : ImageFilter.blur()

                            child : Container(

                                gradient  & BorderRadius & child: Text("Create)    



import 'dart:ui';

import 'package:flutter/material.dart';

class GlassMorphism extends StatefulWidget {
const GlassMorphism({super.key});

@override
State<GlassMorphism> createState() => _GlassMorphismState();
}

class _GlassMorphismState extends State<GlassMorphism> {
@override
Widget build(BuildContext context) {
return Scaffold(
// appBar: AppBar(
// title: Text("Glass Morphism"),
// ),
backgroundColor: Colors.red,
body: Container(
alignment: Alignment.center,
// decoration: BoxDecoration(
// image: DecorationImage(
// image: NetworkImage("http://surevih.in/public/djproduct/131712072512_pexels-mikky-k-625644.jpg"),
// fit: BoxFit.cover
// )
// ),
child: ClipRRect(
borderRadius: BorderRadius.circular(25),
child: BackdropFilter(
filter: ImageFilter.blur(sigmaX: 15, sigmaY: 15),
child: Container(
height: 300,
width: 300,
decoration: BoxDecoration(
// gredient
gradient: LinearGradient(
colors: [Colors.white60, Colors.white10],
begin: Alignment.topLeft,
end: Alignment.bottomCenter
),
// Border
borderRadius: BorderRadius.circular(25),
border: Border.all(width: 2,color: Colors.white30),
// Box Shadow

),
child: Center(
child: Text("Glass",
style: TextStyle(fontSize: 80,color: Colors.black54),),
),

),
),
),
)
);
}
}

Featured post

Compress Image With Show File Size & Resolution in Flutter

 Compress Image With Show File Size & Resolution  1.Multiple File Image Compress with file Size import 'dart:io' ; import 'p...

LightBlog