Skip to content

Instantly share code, notes, and snippets.

@crazy-diya
Created December 9, 2021 18:12
Show Gist options
  • Save crazy-diya/6e4c6e1c29a7e549f7ffb5c1f5f7832d to your computer and use it in GitHub Desktop.
Save crazy-diya/6e4c6e1c29a7e549f7ffb5c1f5f7832d to your computer and use it in GitHub Desktop.
Flutter API call GET and POST Request usin Dio . Login and Registraion and butiful Loading
class ApiUrl{
final String userApi = "http://ec2-54-191-116-138.us-west-2.compute.amazonaws.com:8080";
}
import 'package:flutter/material.dart';
import 'package:flutter_spinkit/flutter_spinkit.dart';
class Loading extends StatelessWidget {
const Loading({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
double width = MediaQuery.of(context).size.width * 0.35;
return Container(
color: Colors.transparent,
child: Center(
child: SpinKitCircle(
color: Colors.black26,
size: 150,
),
),
);
}
}
import 'package:dio/dio.dart';
import 'package:doctor_app/Constant/api_url.dart';
import 'package:doctor_app/Constant/app_colors.dart';
import 'package:doctor_app/Constant/loading.dart';
import 'package:doctor_app/Constant/user_token.dart';
import 'package:flutter/material.dart';
import 'package:video_player/video_player.dart';
import 'user_model.dart';
class ProfilePage extends StatefulWidget {
const ProfilePage({Key? key}) : super(key: key);
@override
_ProfilePageState createState() => _ProfilePageState();
}
class _ProfilePageState extends State<ProfilePage> {
late VideoPlayerController _controller;
late Future<void> _initializeVideoPlayerFuture;
List<UserDataModel> userDataModel = [];
bool loading = false;
@override
void initState() {
loadProfileData();
_controller = VideoPlayerController.network(
'https://flutter.github.io/assets-for-api-docs/assets/videos/butterfly.mp4',
);
_initializeVideoPlayerFuture = _controller.initialize();
_controller.play();
super.initState();
}
loadProfileData() async {
try {
setState(() {
loading = true;
});
var response = await Dio().get(ApiUrl().userApi + '/user/profile',
options: Options(headers: {"Authorization": UserToken().token}));
if (response.statusCode == 200 && response.data["success"] == true) {
var profileDetails = await response.data["ProfileDetails"];
for (var user in profileDetails) {
UserDataModel model = new UserDataModel(
user["id"],
user["username"],
user["email"],
user["profilepicture"],
user["address"],
user["hospital"],
user["mobilenumber"],
user["specialization"],
user["hash"],
user["salt"]);
userDataModel.add(model);
}
setState(() {
loading = false;
});
}
else if (response.statusCode == 500) {
setState(() {
loading = false;
});
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text("Server Error!. Cant load Your Profile Data!"),
));
}
else{
setState(() {
loading = false;
});
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text("Unknown Error! Please contact admin panel."),
));
}
} catch (e) {
setState(() {
loading = false;
});
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content:
Text("Unknown Error! Please contact admin panel. Error is : $e"),
));
}
}
@override
void dispose() {
_controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
double height = MediaQuery.of(context).size.height;
double width = MediaQuery.of(context).size.width;
return Scaffold(
body: SafeArea(
child: Container(
height: height,
width: width,
color: Colors.white,
child: loading
? Align(alignment: Alignment.center, child: Loading(),)
: Stack(
children: [
Stack(
children: [
Container(
height: height * 0.49,
decoration: BoxDecoration(
color: Colors.blue.shade100,
borderRadius: BorderRadius.only(
bottomRight: Radius.circular(30),
bottomLeft: Radius.circular(30),
),
),
child: Stack(
children: [
GestureDetector(
onTap: () {
setState(() {
if (_controller.value.isPlaying) {
_controller.pause();
}
});
},
child: Container(
decoration: BoxDecoration(
),
height: height * 0.47,
width: double.infinity,
child: FutureBuilder(
future: _initializeVideoPlayerFuture,
builder: (context, snapshot) {
if (snapshot.connectionState ==
ConnectionState.done) {
// If the VideoPlayerController has finished initialization, use
// the data it provides to limit the aspect ratio of the video.
return AspectRatio(
aspectRatio: _controller.value.aspectRatio,
// Use the VideoPlayer widget to display the video.
child: VideoPlayer(_controller),
);
} else {
// If the VideoPlayerController is still initializing, show a
// loading spinner.
return const Center(
child: CircularProgressIndicator(),
);
}
},
),
),
),
Padding(
padding: const EdgeInsets.only(
left: 10, right: 10, top: 10),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
InkWell(
child: Icon(
Icons.arrow_back_outlined,
color: Colors.white,
size: 30,
),
onTap: ()=>Navigator.pop(context),
),
Icon(
Icons.menu,
color: Colors.white,
size: 30,
),
],
),
),
Positioned(
right: 0,
top: 60,
child: Padding(
padding: const EdgeInsets.only(right: 10),
child:
Image.asset('assets/images/png/heart.png')),
),
Positioned(
right: 0,
top: 100,
child: Padding(
padding: const EdgeInsets.only(right: 10),
child: Image.asset(
'assets/images/png/person-add.png',
)),
),
GestureDetector(
onTap: () {
setState(() {
if (_controller.value.isPlaying) {
_controller.pause();
} else {
_controller.play();
}
});
},
child: Center(
child: !_controller.value.isPlaying
? Image.asset(
'assets/images/png/play-circle.png')
: null,
),
),
],
),
),
Positioned(
bottom: 0.0,
child: Container(
alignment: Alignment.center,
width: width,
height: 35,
decoration: BoxDecoration(
color: Color(0xff0563AB),
borderRadius: BorderRadius.circular(100),
),
child: Text(
userDataModel[0].username,
style: TextStyle(
color: AppColors.font_color,
fontSize: 12,
fontWeight: FontWeight.bold),
textAlign: TextAlign.center,
),
),
),
],
),
Positioned(
left: 20,
top: height * 0.43,
child: Container(
width: width * 0.27,
height: width * 0.27,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(100),
image: DecorationImage(
image: AssetImage('assets/images/png/avatar.png'),
fit: BoxFit.fill,
),
border: Border.all(color: Colors.white, width: 5)),
),
),
Positioned(
top: height * 0.50,
right: 10,
child: Column(
mainAxisAlignment: MainAxisAlignment.end,
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Container(
padding:
EdgeInsets.symmetric(horizontal: 35, vertical: 5),
child: Text(
"Follow",
style: TextStyle(
fontSize: 15,
color: Colors.white,
fontWeight: FontWeight.bold),
),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(12),
color: Color(0xff05ABA3),
),
),
SizedBox(
height: 15,
),
Row(
children: [
Row(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Image.asset(
"assets/images/png/collections-bookmark.png",
width: 17,
height: 17,
color: Color(0xff000000).withOpacity(0.9),
),
SizedBox(
width: 3,
),
Text(
"23",
style: TextStyle(
color: Colors.black.withOpacity(0.7),
fontWeight: FontWeight.bold,
fontSize: 8),
)
],
),
SizedBox(
width: 15,
),
Row(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Image.asset(
"assets/images/png/friends.png",
width: 20,
height: 20,
color: Color(0xff000000).withOpacity(0.9),
),
SizedBox(
width: 3,
),
Text(
"23",
style: TextStyle(
color: Colors.black.withOpacity(0.7),
fontWeight: FontWeight.bold,
fontSize: 8),
)
],
),
SizedBox(
width: 15,
),
Row(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Image.asset(
"assets/images/png/heart.png",
width: 17,
height: 17,
color: Color(0xff000000).withOpacity(0.9),
),
SizedBox(
width: 3,
),
Text(
"23",
style: TextStyle(
color: Colors.black.withOpacity(0.7),
fontWeight: FontWeight.bold,
fontSize: 8),
)
],
)
],
),
],
),
),
Positioned(
top: height * 0.59,
child: Container(
padding: EdgeInsets.symmetric(horizontal: 10),
width: width,
// padding: EdgeInsets.symmetric(horizontal: 5),
child: Column(
children: [
Padding(
padding: const EdgeInsets.only(
left: 20, right: 20, bottom: 5),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
"Videos",
style: TextStyle(
fontWeight: FontWeight.bold, fontSize: 14),
),
Text(
"See All",
style: TextStyle(
fontWeight: FontWeight.w400,
color: Colors.black,
fontSize: 12),
),
],
),
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Card(
child: Container(
height: height * 0.18,
width: width * 0.29,
decoration: BoxDecoration(
image: DecorationImage(
image:
AssetImage("assets/images/jpg/doc.jpg"),
fit: BoxFit.fill,
),
borderRadius: BorderRadius.circular(10.0),
),
),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0),
),
),
Card(
child: Container(
height: height * 0.18,
width: width * 0.29,
decoration: BoxDecoration(
image: DecorationImage(
image:
AssetImage("assets/images/jpg/doc.jpg"),
fit: BoxFit.fill,
),
borderRadius: BorderRadius.circular(10.0),
),
),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0),
),
),
Card(
child: Container(
height: height * 0.18,
width: width * 0.29,
decoration: BoxDecoration(
image: DecorationImage(
image:
AssetImage("assets/images/jpg/doc.jpg"),
fit: BoxFit.fill,
),
borderRadius: BorderRadius.circular(10.0),
),
),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0),
),
),
],
),
],
),
),
),
Positioned(
bottom: 34,
child: Container(
padding: EdgeInsets.symmetric(horizontal: 35),
width: width,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Container(
padding: EdgeInsets.symmetric(vertical: 12),
alignment: Alignment.center,
child: Text(
"Message",
style: TextStyle(
fontSize: 14,
color: Colors.white,
fontWeight: FontWeight.w500),
),
decoration: BoxDecoration(
color: Color(0xff05ABA3),
borderRadius: BorderRadius.circular(100),
),
width: width * 0.37,
),
Container(
padding: EdgeInsets.symmetric(vertical: 12),
alignment: Alignment.center,
child: Text(
"Live Consultant",
style: TextStyle(
fontSize: 14,
color: Color(0xff05ABA3),
fontWeight: FontWeight.w500),
),
decoration: BoxDecoration(
// color: Colors.green,
borderRadius: BorderRadius.circular(100),
border:
Border.all(color: Color(0xff05ABA3), width: 1)),
width: width * 0.37,
),
],
),
),
),
Align(
alignment: Alignment.bottomCenter,
child: Container(
padding: EdgeInsets.only(bottom: 5),
width: width * 0.25,
child: Divider(
color: Color(0xff05ABA3),
thickness: 3,
),
),
),
],
),
),
),
);
}
}
import 'package:doctor_app/SignIn/sign_up_2.dart';
import 'package:flutter/material.dart';
import 'package:doctor_app/Constant/app_colors.dart';
// import 'package:flutter_svg/flutter_svg.dart';
class SignUp extends StatefulWidget {
const SignUp({Key? key}) : super(key: key);
@override
_SignUpState createState() => _SignUpState();
}
class _SignUpState extends State<SignUp> {
TextEditingController userName = TextEditingController();
TextEditingController email = TextEditingController();
TextEditingController password = TextEditingController();
var isDoctor;
GlobalKey<FormState>? _formKey;
@override
void initState() {
// TODO: implement initState
super.initState();
_formKey = GlobalKey();
}
@override
Widget build(BuildContext context) {
double width = MediaQuery.of(context).size.width;
double height = MediaQuery.of(context).size.height;
return SafeArea(
child: Scaffold(
resizeToAvoidBottomInset: false,
body: Container(
padding: EdgeInsets.symmetric(
horizontal: width * 0.1, vertical: width * 0.04),
child: SingleChildScrollView(
child: Form(
key: _formKey,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
child: Text(
"DOCTOR",
style: TextStyle(
color: AppColors.Button,
fontSize: width * 0.08,
fontWeight: FontWeight.bold),
),
),
SizedBox(
height: height * 0.06,
),
Container(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text("Sign up",
style: TextStyle(
color: Colors.black.withOpacity(0.7),
fontSize: width * 0.08,
fontWeight: FontWeight.bold)),
// SvgPicture.asset('assets/svg/user_icon.svg', color:Colors.grey,),
],
),
),
SizedBox(
height: height * 0.12,
),
TextFormField(
cursorColor: AppColors.Button,
decoration: InputDecoration(
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.grey.shade400),
),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: AppColors.Button),
),
border: UnderlineInputBorder(),
hintText: 'User name',
hintStyle: TextStyle(color: Colors.grey),
),
controller: userName,
autovalidateMode: AutovalidateMode.onUserInteraction,
validator: (value) {
if (value!.isEmpty) {
return 'Fill the Field!';
} else {
return null;
}
},
),
SizedBox(
height: width * 0.08,
),
TextFormField(
cursorColor: AppColors.Button,
decoration: InputDecoration(
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.grey.shade400),
),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: AppColors.Button),
),
border: UnderlineInputBorder(),
hintText: 'Email',
hintStyle: TextStyle(color: Colors.grey),
),
validator: (value) {
if (value!.isEmpty) {
return 'Fill the Field!';
// return 'Name is required!';
} else if (!RegExp(
r"^([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5})$")
.hasMatch(value)) {
return 'enter valid email';
}
return null;
},
autovalidateMode: AutovalidateMode.onUserInteraction,
controller: email,
),
SizedBox(
height: width * 0.08,
),
TextFormField(
cursorColor: AppColors.Button,
decoration: InputDecoration(
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.grey.shade400),
),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: AppColors.Button),
),
border: UnderlineInputBorder(),
hintText: 'Password',
hintStyle: TextStyle(color: Colors.grey),
),
autovalidateMode: AutovalidateMode.onUserInteraction,
obscureText: true,
validator: (value) {
if (value!.isEmpty) {
return 'Fill the field';
}
if (!RegExp(
r"^(?=.*[A-Z])(?=.*[!@#$&*])(?=.*[0-9])(?=.*[a-z]).{8,}$")
.hasMatch(value)) {
return "Enter valid password!";
}
return null;
},
controller: password,
),
SizedBox(
height: width * 0.08,
),
Text(
"Are you a Doctor",
style: TextStyle(color: Colors.grey),
),
SizedBox(
height: width * 0.04,
),
Row(
children: [
SizedBox(
height: 20,
width: 20,
child: Radio(
value: 1,
groupValue: isDoctor,
onChanged: (value) {
setState(() {
isDoctor = 1;
});
print(isDoctor);
},
activeColor: AppColors.Button,
),
),
SizedBox(
width: 5,
),
Text(
"Yes",
style: TextStyle(color: Colors.grey),
),
],
),
SizedBox(
height: width * 0.04,
),
Row(
children: [
SizedBox(
height: 20,
width: 20,
child: Radio(
value: 0,
groupValue: isDoctor,
onChanged: (value) {
setState(() {
isDoctor = 0;
});
print(isDoctor);
},
activeColor: AppColors.Button,
),
),
SizedBox(
width: 5,
),
Text(
"No",
style: TextStyle(color: Colors.grey),
),
],
),
Center(
child: Column(
children: [
SizedBox(
height: height * 0.1,
),
OutlinedButton(
onPressed: () async {
validateCredential();
},
child: Text(
"Next",
style: TextStyle(
color: AppColors.font_color,
fontSize: width * 0.05,
fontWeight: FontWeight.bold),
),
style: OutlinedButton.styleFrom(
backgroundColor: AppColors.Button,
padding: EdgeInsets.symmetric(
vertical: 10, horizontal: width * 0.2),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20)),
side: BorderSide(
color: AppColors.Button,
width: 2.0,
style: BorderStyle.solid),
),
),
],
),
),
SizedBox(
height: width * 0.04,
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
"Already have an account ?",
style: TextStyle(color: Colors.grey),
),
InkWell(
onTap: () {
Navigator.push(context,
MaterialPageRoute(builder: (context) => SignUp()));
},
child: Text(
'sign in',
style: TextStyle(color: AppColors.Button),
),
)
],
),
SizedBox(
height: height * 0.06,
),
Align(
alignment: Alignment.bottomCenter,
child: Container(
height: 3,
width: width * 0.23,
color: AppColors.Button,
),
),
],
),
),
),
),
));
}
validateCredential() async {
_formKey!.currentState!.save();
if (!_formKey!.currentState!.validate()) {
print("Not Validate!");
} else {
Navigator.of(context).push(MaterialPageRoute(
builder: (context) => SignUpSecond(
username: userName.text,
email: email.text,
password: password.text,
isDoctor: isDoctor,
),
));
}
}
}
import 'package:dio/dio.dart';
import 'package:doctor_app/Constant/api_url.dart';
import 'package:doctor_app/Constant/loading.dart';
import 'package:doctor_app/profile_page.dart';
import 'package:flutter/material.dart';
import 'package:doctor_app/Constant/app_colors.dart';
class SignUpSecond extends StatefulWidget {
final String username;
final String email;
final String password;
final int isDoctor;
const SignUpSecond(
{Key? key,
required this.username,
required this.email,
required this.password,
required this.isDoctor})
: super(key: key);
@override
_SignUpSecondState createState() => _SignUpSecondState();
}
class _SignUpSecondState extends State<SignUpSecond> {
String? dropdownValue;
TextEditingController address = TextEditingController();
TextEditingController hospital = TextEditingController();
TextEditingController mobileNumber = TextEditingController();
String imgUrl = "dfdjfk";
GlobalKey<FormState>? _formKey;
bool loading = false;
@override
void initState() {
// TODO: implement initState
super.initState();
_formKey = GlobalKey();
}
@override
Widget build(BuildContext context) {
double width = MediaQuery.of(context).size.width;
double height = MediaQuery.of(context).size.height;
return SafeArea(
child: Scaffold(
body: Stack(
children: [
Container(
padding: EdgeInsets.symmetric(
horizontal: width * 0.1, vertical: width * 0.04),
child: SingleChildScrollView(
child: Form(
key: _formKey,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
child: Text(
"DOCTOR",
style: TextStyle(
color: AppColors.Button,
fontSize: width * 0.08,
fontWeight: FontWeight.bold),
),
),
SizedBox(
height: height * 0.06,
),
Container(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text("Sign up",
style: TextStyle(
color: Colors.black.withOpacity(0.7),
fontSize: width * 0.08,
fontWeight: FontWeight.bold)),
// SvgPicture.asset('assets/svg/user_icon.svg', color:Colors.grey,),
],
),
),
SizedBox(
height: height * 0.08,
),
Container(
child: Row(
children: [
Container(
width: 80,
height: 80,
decoration: BoxDecoration(
border: Border.all(
width: 1, color: Colors.grey.shade400),
shape: BoxShape.circle,
// image: DecorationImage(
// image: AssetImage(
// "assets/images/png/user.png",
// ),
// fit: BoxFit.cover),
),
),
SizedBox(
width: 20,
),
Text(
"Add profile picture",
style: TextStyle(
color: Colors.grey.shade400,
fontWeight: FontWeight.bold),
)
],
)),
SizedBox(
height: height * 0.07,
),
TextFormField(
cursorColor: AppColors.Button,
decoration: InputDecoration(
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.grey.shade400),
),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: AppColors.Button),
),
border: UnderlineInputBorder(),
hintText: 'Address',
hintStyle: TextStyle(
color: Colors.grey, fontWeight: FontWeight.bold),
),
controller: address,
autovalidateMode: AutovalidateMode.onUserInteraction,
validator: (value) {
if (value!.isEmpty) {
return 'Fill the Field!';
} else {
return null;
}
},
),
SizedBox(
height: width * 0.07,
),
TextFormField(
cursorColor: AppColors.Button,
decoration: InputDecoration(
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.grey.shade400),
),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: AppColors.Button),
),
border: UnderlineInputBorder(),
hintText: 'Hospital',
hintStyle: TextStyle(
color: Colors.grey, fontWeight: FontWeight.bold),
),
controller: hospital,
autovalidateMode: AutovalidateMode.onUserInteraction,
validator: (value) {
if (value!.isEmpty) {
return 'Fill the Field!';
} else {
return null;
}
},
),
SizedBox(
height: width * 0.07,
),
TextFormField(
cursorColor: AppColors.Button,
decoration: InputDecoration(
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.grey.shade400),
),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: AppColors.Button),
),
border: UnderlineInputBorder(),
hintText: 'Mobile number',
hintStyle: TextStyle(
color: Colors.grey, fontWeight: FontWeight.bold),
),
controller: mobileNumber,
keyboardType: TextInputType.phone,
autovalidateMode: AutovalidateMode.onUserInteraction,
validator: (value) {
if (value!.isEmpty) {
return 'Fill the Field!';
} else {
return null;
}
},
),
SizedBox(
height: height * 0.05,
),
Container(
padding: EdgeInsets.symmetric(
horizontal: 12,
),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(12),
border: Border.all(
color: Colors.grey.shade400, width: 2)),
child: DropdownButton<String>(
underline: SizedBox(),
icon: Icon(
Icons.keyboard_arrow_down,
size: 35,
color: Colors.grey.shade400,
),
isExpanded: true,
value: dropdownValue,
items: <String>['Specialization', 'Two', 'Free', 'Four']
.map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(
value,
style: TextStyle(
color: Colors.grey,
fontWeight: FontWeight.bold),
),
);
}).toList(),
onChanged: (String? newValue) {
setState(() {
dropdownValue = newValue!;
});
print(dropdownValue);
},
),
),
SizedBox(
height: height * 0.06,
),
Center(
child: OutlinedButton(
onPressed: () {
validateCredential();
},
child: Text(
"Sign up",
style: TextStyle(
color: AppColors.font_color,
fontSize: width * 0.055,
fontWeight: FontWeight.bold),
),
style: OutlinedButton.styleFrom(
backgroundColor: AppColors.Button,
padding: EdgeInsets.symmetric(
vertical: 10, horizontal: width * 0.2),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20)),
side: BorderSide(
color: AppColors.Button,
width: 2.0,
style: BorderStyle.solid),
),
),
),
SizedBox(
height: width * 0.04,
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
"Already have an account ?",
style: TextStyle(color: Colors.grey),
),
InkWell(
onTap: () {},
child: Text(
'sign in',
style: TextStyle(color: AppColors.Button),
),
)
],
),
SizedBox(
height: height * 0.04,
),
],
),
),
),
),
loading
? Align(
alignment: Alignment.center,
child: Loading(),
)
: SizedBox(),
],
),
));
}
validateCredential() async {
_formKey!.currentState!.save();
if (!_formKey!.currentState!.validate()) {
print("Not Validate!");
} else {
await callRegisterAPI();
}
}
callRegisterAPI() async {
print(widget.username +
"\n" +
widget.password +
"\n" +
widget.email +
"\n" +
imgUrl +
"\n" +
address.text +
"\n" +
hospital.text +
"\n" +
mobileNumber.text +
"\n" +
dropdownValue!);
try {
setState(() {
loading = true;
});
var response = await Dio().post(
/*ApiUrl().userApi+*/ 'http://ec2-54-191-116-138.us-west-2.compute.amazonaws.com:8080/user/register',
data: {
"username": widget.username,
"password": widget.password,
"email": widget.email,
"profilepicture": imgUrl,
"address": address.text,
"hospital": hospital.text,
"mobilenumber": mobileNumber.text,
"specialization": dropdownValue
});
print(response);
if (response.statusCode == 200 && response.data["success"] == true) {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text("Successfully Registered!"),
));
setState(() {
loading = false;
});
Navigator.push(
context, MaterialPageRoute(builder: (context) => ProfilePage()));
} else if (response.data["status"] == "UsernameExists") {
setState(() {
loading = false;
});
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text(response.data["message"]),
));
} else if (response.statusCode == 500) {
setState(() {
loading = false;
});
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text("Server Error!. Cant load Your Profile Data!"),
));
} else {
setState(() {
loading = false;
});
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text("Unknown Error! Please contact admin panel."),
));
}
} catch (e) {
setState(() {
loading = false;
});
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content:
Text("Unknown Error! Please contact admin panel. Error is : $e"),
));
print(e);
}
}
}
class UserToken {
final String token =
"Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOnsiaWQiOjMsInVzZXJuYW1lIjoiZGltIiwiZW1haWwiOiJkaW1AZ21haWwuY29tIiwicHJvZmlsZXBpY3R1cmUiOiJhYmMiLCJhZGRyZXNzIjoiSG9yYW5hIiwiaG9zcGl0YWwiOiJIb3JhbmEiLCJtb2JpbGVudW1iZXIiOiIwNzY4NTUxMDQ1Iiwic3BlY2lhbGl6YXRpb24iOiJTU1MifSwiaWF0IjoxNjM5MDM4OTU1NDY5LCJleHAiOjE2MzkwNDAxNjUwNjl9.lP03QM-1ffE4-Ari9-Jt25xMhGDSAX0Qaje_KljqHRTIQX_Z297J9It-a2QNxX7zZmKqqSeBVE9TBF0UZoVtcq6up3KjBYKsxLLOQnGWpdDzlE8fmoc7qxFoHmwEiEp1UTP8YzVDurUhc_Ec4g1Kbf1bJ44J0GFYUWR2sTVTY5TTEefNShMfAG06vg3pf-q3UlcNwRvFIsELnQvoWJ6ryBuoDUqtCHOQIpEo3GKf0ntSx23G3jkAZLTWDqSl0N6WTLqqvJcK_TzQ69mknSPxIM0UlGooBOlN9Z4i7I3T3ZjfO0Lv-S3KqMXMCuUUcyCowx6SZ5l1tA1kWsIodGWHzc_F9iZX800g0hAEJzsMIVjRJczpjfhZZy2fS8Q_Zc7zvMc-vDX5w2U7raJyB9ib1054ZL4sSeqF0XiqqF-9pYHBJUePJierjgB5yNldzSZMwjlNRUiAzpuZBdgodtGucv2s6B-1jCQzwIn_qgeGoJa2OGngU5ZU-UhVdIuRpioLcuasXITYgbcMRLbu3ANIQRyDOVGMeG-1V85jAACjWrLdEftn6ZXharrMo31Ybd5a1PCvHpABojf5LlzvzPqvRDvtge7amzYogOHwvN1HV6_apvS6ctld1m4JIwOKOtkR1tPrRFe8lXoRSoeb--cmm0IW85oVlZFb2yxfjJebjnk";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment