Skip to content

Commit

Permalink
Merge pull request #1 from RaghvindYadav/user-integration
Browse files Browse the repository at this point in the history
User integration
  • Loading branch information
RaghvindYadav authored Dec 12, 2023
2 parents e4b9d90 + 6b11d19 commit 4f60ee2
Show file tree
Hide file tree
Showing 20 changed files with 998 additions and 25 deletions.
1 change: 1 addition & 0 deletions ios/Flutter/Debug.xcconfig
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"
#include "Generated.xcconfig"
1 change: 1 addition & 0 deletions ios/Flutter/Release.xcconfig
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"
#include "Generated.xcconfig"
44 changes: 44 additions & 0 deletions ios/Podfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Uncomment this line to define a global platform for your project
# platform :ios, '11.0'

# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'

project 'Runner', {
'Debug' => :debug,
'Profile' => :release,
'Release' => :release,
}

def flutter_root
generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__)
unless File.exist?(generated_xcode_build_settings_path)
raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first"
end

File.foreach(generated_xcode_build_settings_path) do |line|
matches = line.match(/FLUTTER_ROOT\=(.*)/)
return matches[1].strip if matches
end
raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get"
end

require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root)

flutter_ios_podfile_setup

target 'Runner' do
use_frameworks!
use_modular_headers!

flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
target 'RunnerTests' do
inherit! :search_paths
end
end

post_install do |installer|
installer.pods_project.targets.each do |target|
flutter_additional_ios_build_settings(target)
end
end
56 changes: 56 additions & 0 deletions lib/controllers/user_controller.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import 'dart:convert';

import 'package:afghan_net/services/app_remote_routes.dart';
import 'package:get/get.dart';
import 'package:get_storage/get_storage.dart';

import '../modal/user.dart';
import '../services/api_provider.dart';

class UserController extends GetxController{
final apiProvider = ApiProvider();
GetStorage sr = GetStorage();
late User user;
late List<User> listUsers;

userLogin({required String email, required String pass}) async{
final data = await apiProvider.post("login",{"email":email,"password":pass});
user = User.fromJson(data);
GetStorage sr = GetStorage();
await sr.write('token',user.token);
await sr.write("user", user);
print(sr.read('user'));
}

Future<String> createUser(Map<String,dynamic> userData)async{
final data = await apiProvider.post('createUser', userData);

print("message ${data['message']}");
return data['message'];
}

User getUser(){
if(sr.read('user') is User){
user = sr.read('user');
}else{
user = User.fromJson(sr.read('user'));
}
return user;
}

deleteUser({required String userId}) async{
final data = await apiProvider.delete("user", {"id":userId});
print(data);

}

Future<List<User>> getAllUsers()async{
// listUsers.clear();
final data = await apiProvider.get(AppRemoteRoutes.allUser);
final List listData = json.decode(jsonEncode(data['data']));
listUsers =
listData.map((x)=>User.fromJson(x)).toList();
return listUsers;
}

}
6 changes: 5 additions & 1 deletion lib/home_page.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import 'package:afghan_net/Afgan_List_UI/internet_bundle/vpn_plans/vpn_all.dart';
import 'package:afghan_net/Afgan_List_UI/status/dialog_box.dart';
import 'package:afghan_net/catagory.dart';
import 'package:afghan_net/controllers/user_controller.dart';
import 'package:afghan_net/order.dart';
import 'package:afghan_net/web/drawer/drawer.dart';
import 'package:afghan_net/widgets/tab_navigate.dart';
import 'package:afghan_net/widgets/text.dart';
import 'package:afghan_net/widgets/transaction.dart';
Expand All @@ -24,6 +26,8 @@ class HomePage extends StatelessWidget {

@override
Widget build(BuildContext context) {
final userController = Get.find<UserController>();
userController.getUser();
return Scaffold(
appBar: AppBar(
title: Row(
Expand Down Expand Up @@ -57,7 +61,7 @@ class HomePage extends StatelessWidget {
),
),
key: _scaffoldKey,
drawer: All_Drawer(),
drawer: All_Drawer_Web(),
body: SingleChildScrollView(
child: Column(children: [
SizedBox(
Expand Down
11 changes: 10 additions & 1 deletion lib/login.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import 'package:afghan_net/controllers/user_controller.dart';
import 'package:afghan_net/home_page.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

class LoginPage extends StatefulWidget {
const LoginPage({super.key});
Expand All @@ -12,6 +15,7 @@ class _LoginPageState extends State<LoginPage> {
late Size mediaSize;
TextEditingController emailController = TextEditingController();
TextEditingController passwordController = TextEditingController();
final userController = Get.put(UserController());
bool rememberUser = false;

@override
Expand Down Expand Up @@ -144,9 +148,14 @@ class _LoginPageState extends State<LoginPage> {

Widget _buildLoginButton() {
return ElevatedButton(
onPressed: () {
onPressed: () async {
debugPrint("Email : ${emailController.text}");
debugPrint("Password : ${passwordController.text}");
await userController.userLogin(email: emailController.text,pass: passwordController.text);
Navigator.pushReplacement(
context,
MaterialPageRoute(builder: (context) => HomePage()),
);
},
style: ElevatedButton.styleFrom(
shape: const StadiumBorder(
Expand Down
22 changes: 12 additions & 10 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import 'package:afghan_net/home_page.dart';
import 'package:afghan_net/login.dart';
import 'package:afghan_net/screens/admin_management.dart';
import 'package:afghan_net/splash.dart';
import 'package:afghan_net/web/HomePageWeb.dart';

Expand Down Expand Up @@ -30,16 +32,16 @@ class MyApp extends StatelessWidget {
}

Widget _buildHomePage(double screenWidth, DeviceType deviceType) {
if (screenWidth < 400 || deviceType == DeviceType.mobile) {
// if (screenWidth < 400 || deviceType == DeviceType.mobile) {
// return Splash();
// } else if (screenWidth < 400) {
// return Splash();
// } else if (screenWidth >= 700 && screenWidth < 1024) {
// return Splash();
// } else if (screenWidth >= 1024 && screenWidth <= 1920) {
// return Splash();
// } else {
return Splash();
} else if (screenWidth < 400) {
return HomePage();
} else if (screenWidth >= 700 && screenWidth < 1024) {
return HomePageWeb();
} else if (screenWidth >= 1024 && screenWidth <= 1920) {
return HomePageWeb();
} else {
return HomePage();
}
// }
}
}
71 changes: 71 additions & 0 deletions lib/modal/user.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
class User {
String id;
String firstName;
String lastName;
String email;
int mobile;
String district;
String province;
String currency;
bool isVerified;
String userType;
bool isDeleted;
DateTime createdAt;
DateTime updatedAt;
int v;
String? token;

User({
required this.id,
required this.firstName,
required this.lastName,
required this.email,
required this.mobile,
required this.district,
required this.province,
required this.currency,
required this.isVerified,
required this.userType,
required this.isDeleted,
required this.createdAt,
required this.updatedAt,
required this.v,
this.token,
});

factory User.fromJson(Map<String, dynamic> json) => User(
id: json["_id"],
firstName: json["firstName"],
lastName: json["lastName"],
email: json["email"],
mobile: json["mobile"],
district: json["district"],
province: json["province"],
currency: json["currency"],
isVerified: json["isVerified"],
userType: json["userType"],
isDeleted: json["isDeleted"],
createdAt: DateTime.parse(json["createdAt"]),
updatedAt: DateTime.parse(json["updatedAt"]),
v: json["__v"],
token: json["token"],
);

Map<String, dynamic> toJson() => {
"_id": id,
"firstName": firstName,
"lastName": lastName,
"email": email,
"mobile": mobile,
"district": district,
"province": province,
"currency": currency,
"isVerified": isVerified,
"userType": userType,
"isDeleted": isDeleted,
"createdAt": createdAt.toIso8601String(),
"updatedAt": updatedAt.toIso8601String(),
"__v": v,
"token": token,
};
}
Loading

0 comments on commit 4f60ee2

Please sign in to comment.