Skip to content

Commit

Permalink
Merge pull request #1 from vision-crafters/Abhinav
Browse files Browse the repository at this point in the history
Abhinav_Upload_Image_Done
  • Loading branch information
Sainath12204 authored Apr 25, 2024
2 parents bc5a4c5 + ac90892 commit 40512b0
Show file tree
Hide file tree
Showing 9 changed files with 326 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Flutter/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.hardware.CAMERA" />
<uses-permission android:name="android.hardware.camera" />
<uses-permission android:name="android.hardware.camera.autofocus" />

<application
android:label="flutterbasics"
android:name="${applicationName}"
Expand Down
1 change: 1 addition & 0 deletions Flutter/lib/Speech_To_Text.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ class _SpeechState extends State<Speech> {
color: Colors.white,
),
),

);
}
}
32 changes: 32 additions & 0 deletions Flutter/lib/camera.dart
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(),
),
);
}
}
76 changes: 76 additions & 0 deletions Flutter/lib/gradient_container.dart
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(),
),
);
}
}
13 changes: 10 additions & 3 deletions Flutter/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ import 'package:flutter_speed_dial/flutter_speed_dial.dart';
import 'package:flutterbasics/DashBoardScreen.dart';
import 'package:flutterbasics/Speech_To_Text.dart';

import 'upload_image.dart';

void main() {
runApp(const MyApp());
}

class MyApp extends StatelessWidget {
const MyApp({super.key});

@override
Widget build(BuildContext context) {
return MaterialApp(
Expand All @@ -35,7 +37,7 @@ class HomePage extends StatelessWidget {
"Vision Crafters",
style: TextStyle(
color: Colors.black, fontSize: 20, fontWeight: FontWeight.bold),
),
), //heading.
actions: [
IconButton(
icon: const Icon(
Expand All @@ -59,7 +61,12 @@ class HomePage extends StatelessWidget {
children: [
SpeedDialChild(
child: const Icon(Icons.camera),
onTap: () {},
onTap: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => const UploadImageScreen()),
);
},
),
SpeedDialChild(
child: const Icon(Icons.video_call),
Expand Down
16 changes: 16 additions & 0 deletions Flutter/lib/styled_text.dart
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,
),
);
}
}
181 changes: 181 additions & 0 deletions Flutter/lib/upload_image.dart
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,
),
],
),
));
}
}
2 changes: 1 addition & 1 deletion Flutter/test/widget_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import 'package:flutterbasics/main.dart';
void main() {
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
// Build our app and trigger a frame.
await tester.pumpWidget(const MyApp());
await tester.pumpWidget(MyApp());

// Verify that our counter starts at 0.
expect(find.text('0'), findsOneWidget);
Expand Down

0 comments on commit 40512b0

Please sign in to comment.