-
Notifications
You must be signed in to change notification settings - Fork 8
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 #1 from vision-crafters/Abhinav
Abhinav_Upload_Image_Done
- Loading branch information
Showing
9 changed files
with
326 additions
and
4 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -82,6 +82,7 @@ class _SpeechState extends State<Speech> { | |
color: Colors.white, | ||
), | ||
), | ||
|
||
); | ||
} | ||
} |
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,32 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter/widgets.dart'; | ||
|
||
import 'gradient_container.dart'; | ||
|
||
class MyApp2 extends StatelessWidget { | ||
const MyApp2({Key? key}) : super(key: key); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
//i am returning a widget | ||
//that's the reason i had written Widget first. | ||
//i think build i a built-in method which i am overriding according to my | ||
//convenience. | ||
|
||
// return const MaterialApp(home: Scaffold(body: Text('Hello Dad!'))); | ||
// this was before and whatever your seeing below is after adding | ||
//the existing widget into another centre widget to make the hello dad | ||
//to appear in centre of the screen | ||
/*for performing the above thing you need to go and right click | ||
on the Text and select the wrap with centre option */ | ||
|
||
return MaterialApp( | ||
home: Scaffold( | ||
// backgroundColor: Color.fromARGB(255, 131, 127, 89), | ||
// for accessing the above features we need to click on | ||
// ctrl+space bar.for broad variety of arguments | ||
body: GradientContainer(), | ||
), | ||
); | ||
} | ||
} |
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,76 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
import 'styled_text.dart'; | ||
|
||
class GradientContainer extends StatelessWidget { | ||
// {}->for named params | ||
// (a,b)->for positional params. | ||
GradientContainer({super.key}); | ||
// const is kept to unlock the potential | ||
// optimization. | ||
//a key needed to be passed by the child to the | ||
//parent after the creation of the child in the | ||
//constructor. | ||
//so for that. | ||
//initialization work. | ||
// GradientContainer({super.key}) | ||
// for so that sake we give a named argument to the | ||
//constructor named super.key | ||
//this key will be passed to the parent by the child. | ||
// in the form of a named argument. | ||
// const can be added to optimize the runtime performance. | ||
|
||
var startAlignment = Alignment.topLeft; | ||
// in dart variable types are assigned by themselves only | ||
//and the typed will only have all the type of values | ||
//they are assigned for the rest of it's life. | ||
//eg->in this case it's Alignment is the only type of the | ||
//variable it is assigned to.and that variable can only | ||
//store Alignment type of variables. | ||
/*in those cases where i don't know which type of variable | ||
will be stored inside that variable i can add dynamic | ||
,initialize dynamic variables instead.but i might incur | ||
few bugs while dealing with such things. | ||
one more way is that if i know what is the type i want to | ||
store in that variable i can initialize that variable like | ||
that only | ||
Eg->Alignment startAlignment; | ||
but even though like this also we might have errors because | ||
we are not assigning anything to it, | ||
while we are initializing | ||
so in those cases it is storing a null values | ||
to allow our varible to store a null value while | ||
initialzing it is by adding a ? tag after Alignment | ||
(yes the dataType i mean) | ||
Eg->Alignment ? startAlignment; | ||
means it is either the type alignment or null | ||
so it's optional wheather it's set or not. | ||
type inference-->read about it | ||
*/ | ||
var endAlignment = Alignment.bottomRight; | ||
|
||
@override | ||
Widget build(context) { | ||
return Container( | ||
decoration: BoxDecoration( | ||
gradient: LinearGradient( | ||
colors: const [ | ||
Color.fromARGB(255, 255, 255, 255), | ||
Color.fromARGB(255, 178, 18, 18) | ||
], | ||
begin: startAlignment, | ||
end: endAlignment, | ||
// press ctrl+space for suggestions. | ||
), | ||
), | ||
// you cannot add const to the constainer's prefix,hence | ||
// you can't add const to it's parents also | ||
// so i removed const infront of materialApp widget too | ||
// which i was returning. | ||
child: const Center( | ||
child: StyledText(), | ||
), | ||
); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
|
||
class StyledText extends StatelessWidget { | ||
const StyledText({super.key}); | ||
@override | ||
Widget build(context) { | ||
return const Text( | ||
'Hey jude!', | ||
style: TextStyle( | ||
color: Colors.white, | ||
fontSize: 28, | ||
), | ||
); | ||
} | ||
} |
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,181 @@ | ||
import 'dart:io'; | ||
// import 'dart:js_interop'; | ||
import 'package:flutter/widgets.dart'; | ||
import 'package:http/http.dart' as http; | ||
import 'package:flutter/material.dart'; | ||
import 'package:image_picker/image_picker.dart'; | ||
import 'package:modal_progress_hud_nsn/modal_progress_hud_nsn.dart'; | ||
|
||
class UploadImageScreen extends StatefulWidget { | ||
const UploadImageScreen({Key? key}) : super(key: key); | ||
|
||
@override | ||
_UploadImageScreenState createState() => _UploadImageScreenState(); | ||
} | ||
|
||
class _UploadImageScreenState extends State<UploadImageScreen> { | ||
File? imageGal, imageCam; | ||
final _pickerGal = ImagePicker(); | ||
final _pickerCam = ImagePicker(); | ||
bool showSpinner = false; | ||
|
||
Future getImageGL() async { | ||
final pickedFile_Gallery = await _pickerGal.pickImage( | ||
source: ImageSource.gallery, imageQuality: 80); | ||
|
||
if (pickedFile_Gallery != null) { | ||
imageGal = File(pickedFile_Gallery.path); | ||
setState(() {}); | ||
uploadImageFromGallery(); | ||
} else { | ||
print("No image selected"); | ||
} | ||
} | ||
|
||
Future getImageCM() async { | ||
final pickedFile_Camera = await _pickerCam.pickImage( | ||
source: ImageSource.camera, imageQuality: 80); | ||
|
||
if (pickedFile_Camera != null) { | ||
imageCam = File(pickedFile_Camera.path); | ||
setState(() {}); | ||
uploadImageFromCamera(); | ||
} else { | ||
print("No image Captured"); | ||
} | ||
} | ||
|
||
Future<void> uploadImageFromGallery() async { | ||
setState(() { | ||
showSpinner = true; | ||
}); | ||
var stream = new http.ByteStream(imageGal!.openRead()); | ||
stream.cast(); | ||
|
||
var length = await imageGal!.length(); | ||
|
||
//coming soon. | ||
var uri = Uri.parse("https://fakestoreapi.com/products"); | ||
|
||
var request = new http.MultipartRequest('POST', uri); | ||
|
||
request.fields['title'] = "Static title"; | ||
|
||
var multiport = new http.MultipartFile('image', stream, length); | ||
|
||
request.files.add(multiport); | ||
|
||
var response = await request.send(); | ||
|
||
if (response.statusCode == 200) { | ||
setState(() { | ||
showSpinner = false; | ||
}); | ||
|
||
print("image Uploaded"); | ||
} else { | ||
print("failed to upload"); | ||
setState(() { | ||
showSpinner = true; | ||
}); | ||
} | ||
} | ||
|
||
Future<void> uploadImageFromCamera() async { | ||
setState(() { | ||
showSpinner = true; | ||
}); | ||
var stream = new http.ByteStream(imageCam!.openRead()); | ||
stream.cast(); | ||
|
||
var length = await imageCam!.length(); | ||
|
||
//coming soon. | ||
var uri = Uri.parse("https://fakestoreapi.com/products"); | ||
|
||
var request = new http.MultipartRequest('POST', uri); | ||
|
||
request.fields['title'] = "Static title"; | ||
|
||
var multiport = new http.MultipartFile('image', stream, length); | ||
|
||
request.files.add(multiport); | ||
|
||
var response = await request.send(); | ||
|
||
if (response.statusCode == 200) { | ||
setState(() { | ||
showSpinner = false; | ||
}); | ||
|
||
print("image Uploaded"); | ||
} else { | ||
print("failed to upload"); | ||
setState(() { | ||
showSpinner = true; | ||
}); | ||
} | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return ModalProgressHUD( | ||
inAsyncCall: showSpinner, | ||
child: Scaffold( | ||
appBar: AppBar( | ||
title: const Text('Upload Image'), | ||
), | ||
body: Column( | ||
mainAxisAlignment: MainAxisAlignment.center, | ||
crossAxisAlignment: CrossAxisAlignment.center, | ||
children: [ | ||
GestureDetector( | ||
onTap: () { | ||
getImageGL(); | ||
}, | ||
child: Container( | ||
child: imageGal == null | ||
? Center( | ||
child: Text("Pick an image"), | ||
) | ||
: Container( | ||
child: Center( | ||
child: Image.file( | ||
File(imageGal!.path).absolute, | ||
height: 100, | ||
width: 100, | ||
fit: BoxFit.cover, | ||
), | ||
), | ||
), | ||
), | ||
), | ||
GestureDetector( | ||
onTap: () { | ||
getImageCM(); | ||
}, | ||
child: Container( | ||
child: imageCam == null | ||
? Center( | ||
child: Text("Click an image"), | ||
) | ||
: Container( | ||
child: Center( | ||
child: Image.file( | ||
File(imageCam!.path).absolute, | ||
height: 100, | ||
width: 100, | ||
fit: BoxFit.cover, | ||
), | ||
), | ||
), | ||
), | ||
), | ||
SizedBox( | ||
height: 150, | ||
), | ||
], | ||
), | ||
)); | ||
} | ||
} |
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