-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUploadfile.dart
More file actions
73 lines (71 loc) · 2.58 KB
/
Uploadfile.dart
File metadata and controls
73 lines (71 loc) · 2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import 'dart:io';
import 'dart:async';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';
import 'package:flutter_image_compress/flutter_image_compress.dart';
import 'package:video_compress/video_compress.dart';
class Compress_File extends StatefulWidget {
@override
_Compress_FileState createState() => _Compress_FileState();
}
class _Compress_FileState extends State<Compress_File> {
@override
File file;
final picker=ImagePicker();
Future imageWithCamera() async {
Navigator.pop(context);
final pickedFile = await picker.getImage(source: ImageSource.camera);
}
imageWithGallery()async{
Navigator.pop(context);
final pickedFile = await picker.getImage(source: ImageSource.gallery);
file=File(pickedFile.path);
print(file.lengthSync());
final result = await FlutterImageCompress.compressWithFile(pickedFile.path.toString(),quality: 40);
print(result.length);
}
upload(mcontext){
return showDialog(context: mcontext,builder: (context){
return SimpleDialog(
title: Text("Choose a file",style: TextStyle(fontSize: 25.0,fontWeight: FontWeight.bold),),
children: <Widget>[
SimpleDialogOption(
child: Text("From camera",style: TextStyle(fontSize: 20.0,color: Colors.black),),
onPressed: ()=>imageWithCamera(),
),
SimpleDialogOption(
child: Text("From Gallery",style: TextStyle(color: Colors.black,fontSize: 20.0),),
onPressed: ()=>imageWithGallery(),
),
SimpleDialogOption(
child: Text("Cancel",style: TextStyle(color: Colors.black,fontSize: 20.0,fontWeight: FontWeight.bold),),
onPressed: ()=>Navigator.pop(context),
)
],
);
});
}
buildPage(){
return Container(
color: Colors.black,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Icon(Icons.add_photo_alternate,size: 260.0,color: Colors.grey,),
RaisedButton(
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10.0)) ,
child: Text('Upload file',style: TextStyle(color: Colors.black,fontSize: 26.0),),
color: Colors.green,
highlightColor: Colors.grey,
onPressed:()=>upload(context),
),
],
),
);
}
Widget build(BuildContext context) {
return buildPage();
}
}