Added Profile picture

dev
suresh 1 year ago
parent 0ca9c88914
commit d1314c4fb0

@ -9,6 +9,7 @@ import 'package:watermanagement/login.dart';
import 'package:watermanagement/settings.dart'; import 'package:watermanagement/settings.dart';
import 'package:image_picker/image_picker.dart'; import 'package:image_picker/image_picker.dart';
import 'package:watermanagement/tankersview.dart'; import 'package:watermanagement/tankersview.dart';
import 'dart:convert';
import 'dart:io'; import 'dart:io';
import 'package:watermanagement/updateprofile.dart'; import 'package:watermanagement/updateprofile.dart';
import 'booking_requests.dart'; import 'booking_requests.dart';
@ -94,13 +95,15 @@ class _DashboardState extends State<Dashboard> {
final image = await _picker.pickImage(source: ImageSource.gallery); final image = await _picker.pickImage(source: ImageSource.gallery);
if (image == null) return; if (image == null) return;
final imageTemp = File(image.path); final imageTemp = File(image.path);
AppSettings.preLoaderDialog(context);
var res = await AppSettings.uploadImageHTTPNew(image);
print(jsonDecode(res));
Navigator.of(context, rootNavigator: true).pop();
setState(() { setState(() {
AppSettings.updatedImage = imageTemp; AppSettings.profilePictureUrl = jsonDecode(res)['picture'];
}); });
uploadProfileApi(image.path); AppSettings.saveData('profile', jsonDecode(res)['picture'], 'STRING');
AppSettings.saveProfile(image.path);
} on PlatformException catch (e) { } on PlatformException catch (e) {
print('Failed to pick image: $e'); print('Failed to pick image: $e');
} }
@ -111,13 +114,14 @@ class _DashboardState extends State<Dashboard> {
final image = await _picker.pickImage(source: ImageSource.camera); final image = await _picker.pickImage(source: ImageSource.camera);
if (image == null) return; if (image == null) return;
final imageTemp = File(image.path); final imageTemp = File(image.path);
AppSettings.preLoaderDialog(context);
var res = await AppSettings.uploadImageHTTPNew(image);
print(jsonDecode(res));
Navigator.of(context, rootNavigator: true).pop();
setState(() { setState(() {
AppSettings.updatedImage = imageTemp; AppSettings.profilePictureUrl = jsonDecode(res)['picture'];
}); });
AppSettings.saveData('profile', jsonDecode(res)['picture'], 'STRING');
uploadProfileApi(image.path);
AppSettings.saveProfile(image.path);
} on PlatformException catch (e) { } on PlatformException catch (e) {
print('Failed to pick image: $e'); print('Failed to pick image: $e');
} }
@ -428,15 +432,26 @@ class _DashboardState extends State<Dashboard> {
children: [ children: [
Expanded(child: GestureDetector( Expanded(
child: GestureDetector(
child: Container( child: Container(
width: MediaQuery.of(context).size.width * .20, width: (MediaQuery.of(context).size.width > 600)
height: MediaQuery.of(context).size.height * .15, ? MediaQuery.of(context).size.width * .30
: MediaQuery.of(context).size.width * .60, // Adjusted width for tablet
height: (MediaQuery.of(context).size.width > 600)
? MediaQuery.of(context).size.height * .25
: MediaQuery.of(context).size.height * .50, // Adjusted height for tablet
decoration: BoxDecoration( decoration: BoxDecoration(
shape: BoxShape.circle, shape: BoxShape.rectangle,
border: Border.all(width: 2, color: Colors.blueGrey),
image: DecorationImage( image: DecorationImage(
image: (AppSettings.updatedImage != null) ? FileImage(AppSettings.updatedImage!) as ImageProvider : AssetImage("images/profile_pic.png"), // picked file image: (AppSettings.profilePictureUrl != '' &&
fit: BoxFit.cover)), AppSettings.profilePictureUrl != 'null')
? NetworkImage(AppSettings.profilePictureUrl) as ImageProvider
: AssetImage(" images/profile_pic.png"), // picked file
fit: BoxFit.fitWidth,
),
),
), ),
onTap: () { onTap: () {
showModalBottomSheet<void>( showModalBottomSheet<void>(
@ -446,7 +461,8 @@ class _DashboardState extends State<Dashboard> {
height: 200, height: 200,
child: Center( child: Center(
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment:
MainAxisAlignment.center,
children: <Widget>[ children: <Widget>[
GestureDetector( GestureDetector(
child: Icon( child: Icon(
@ -460,8 +476,10 @@ class _DashboardState extends State<Dashboard> {
}, },
), ),
SizedBox( SizedBox(
width: width: MediaQuery.of(context)
MediaQuery.of(context).size.width * .20, .size
.width *
.20,
), ),
GestureDetector( GestureDetector(
child: Icon( child: Icon(
@ -480,7 +498,10 @@ class _DashboardState extends State<Dashboard> {
); );
}); });
}, },
),), ),
),
Text( Text(
AppSettings.suppliername, AppSettings.suppliername,

@ -124,6 +124,13 @@ class AppSettings {
static String acceptRequestUrl = host +"friend-request/accept"; static String acceptRequestUrl = host +"friend-request/accept";
static String rejectRequestUrl = host +"friend-request/reject"; static String rejectRequestUrl = host +"friend-request/reject";
static String profilePicUrl = host + 'supplier/profile-picture'; static String profilePicUrl = host + 'supplier/profile-picture';
static String uploadPicUrl = host + 'uploads';
static String profilePictureUrl = '';
static File? updatedImage; static File? updatedImage;
static String image=''; static String image='';
@ -226,6 +233,25 @@ class AppSettings {
return false; return false;
} }
static Future<String> uploadImageHTTPNew(file) async {
var request = http.MultipartRequest('POST', Uri.parse(uploadPicUrl + '/' + supplierId));
request.files.add(await http.MultipartFile.fromPath('picture', file.path));
var res = await request.send();
var response = await http.Response.fromStream(res);
return response.body;
}
/*Apis Starts here*/ /*Apis Starts here*/
static Future<bool> login(payload) async { static Future<bool> login(payload) async {

@ -5,6 +5,7 @@ import 'package:flutter/services.dart';
import 'package:watermanagement/dashboard.dart'; import 'package:watermanagement/dashboard.dart';
import 'package:watermanagement/settings.dart'; import 'package:watermanagement/settings.dart';
import 'package:image_picker/image_picker.dart'; import 'package:image_picker/image_picker.dart';
import 'dart:convert';
import 'dart:io'; import 'dart:io';
import 'login.dart'; import 'login.dart';
@ -52,17 +53,20 @@ class _UpdateprofileState extends State<UpdateProfile> {
final ImagePicker _picker = ImagePicker(); final ImagePicker _picker = ImagePicker();
Future pickImageFromGallery() async { Future pickImageFromGallery() async {
try { try {
final image = await _picker.pickImage(source: ImageSource.gallery); final image = await _picker.pickImage(source: ImageSource.gallery);
if (image == null) return; if (image == null) return;
final imageTemp = File(image.path); final imageTemp = File(image.path);
AppSettings.preLoaderDialog(context);
var res = await AppSettings.uploadImageHTTPNew(image);
print(jsonDecode(res));
Navigator.of(context, rootNavigator: true).pop();
setState(() { setState(() {
AppSettings.updatedImage = imageTemp; AppSettings.profilePictureUrl = jsonDecode(res)['picture'];
}); });
//uploadProfileApi(AppSettings.updatedImage); AppSettings.saveData('profile', jsonDecode(res)['picture'], 'STRING');
AppSettings.saveProfile(image.path);
} on PlatformException catch (e) { } on PlatformException catch (e) {
print('Failed to pick image: $e'); print('Failed to pick image: $e');
} }
@ -73,10 +77,14 @@ class _UpdateprofileState extends State<UpdateProfile> {
final image = await _picker.pickImage(source: ImageSource.camera); final image = await _picker.pickImage(source: ImageSource.camera);
if (image == null) return; if (image == null) return;
final imageTemp = File(image.path); final imageTemp = File(image.path);
AppSettings.preLoaderDialog(context);
var res = await AppSettings.uploadImageHTTPNew(image);
print(jsonDecode(res));
Navigator.of(context, rootNavigator: true).pop();
setState(() { setState(() {
AppSettings.updatedImage = imageTemp; AppSettings.profilePictureUrl = jsonDecode(res)['picture'];
}); });
AppSettings.saveData('profile', jsonDecode(res)['picture'], 'STRING');
// uploadProfileApi(AppSettings.updatedImage); // uploadProfileApi(AppSettings.updatedImage);
AppSettings.saveProfile(image.path); AppSettings.saveProfile(image.path);
@ -115,15 +123,17 @@ class _UpdateprofileState extends State<UpdateProfile> {
image: AssetImage('images/logo.png'), image: AssetImage('images/logo.png'),
height: MediaQuery.of(context).size.height * .10, height: MediaQuery.of(context).size.height * .10,
)),*/ )),*/
Container(child: GestureDetector( Container(child:
GestureDetector(
child: Container( child: Container(
width: MediaQuery.of(context).size.width * .30, width: MediaQuery.of(context).size.width * .60,
height: MediaQuery.of(context).size.height * .20, height: MediaQuery.of(context).size.height * .15,
decoration: BoxDecoration( decoration: BoxDecoration(
shape: BoxShape.circle, shape: BoxShape.rectangle,
border: Border.all(width: 2, color: Colors.blueGrey),
image: DecorationImage( image: DecorationImage(
image: (AppSettings.updatedImage != null) ? FileImage(AppSettings.updatedImage!) as ImageProvider : AssetImage("images/profile_pic.png"), // picked file image: (AppSettings.profilePictureUrl != ''&& AppSettings.profilePictureUrl != 'null') ? NetworkImage(AppSettings.profilePictureUrl) as ImageProvider : AssetImage("images/mobilebg.png"), // picked file
fit: BoxFit.cover)), fit: BoxFit.fitWidth)),
), ),
onTap: () { onTap: () {
showModalBottomSheet<void>( showModalBottomSheet<void>(
@ -139,7 +149,7 @@ class _UpdateprofileState extends State<UpdateProfile> {
child: Icon( child: Icon(
Icons.camera_alt_outlined, Icons.camera_alt_outlined,
size: 100, size: 100,
color: greyColor, color: primaryColor,
), ),
onTap: () async { onTap: () async {
await takeImageFromCamera(); await takeImageFromCamera();
@ -154,7 +164,7 @@ class _UpdateprofileState extends State<UpdateProfile> {
child: Icon( child: Icon(
Icons.photo, Icons.photo,
size: 100, size: 100,
color: greyColor, color: primaryColor,
), ),
onTap: () async { onTap: () async {
await pickImageFromGallery(); await pickImageFromGallery();

Loading…
Cancel
Save