Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 0 additions & 59 deletions DatabaseHandller/DtHelper.dart

This file was deleted.

16 changes: 0 additions & 16 deletions Model/UserModel.dart

This file was deleted.

49 changes: 0 additions & 49 deletions common/getInfoForm.dart

This file was deleted.

3 changes: 0 additions & 3 deletions common/helper.dart

This file was deleted.

33 changes: 33 additions & 0 deletions components/my_button.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import 'package:flutter/material.dart';

class MyButton extends StatelessWidget {
final Function()? onTap;
final String text;

MyButton({super.key, required this.onTap, required this.text});

@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: onTap,
child: Container(
padding: EdgeInsets.all(15),
margin: EdgeInsets.symmetric(horizontal: 42),
decoration: BoxDecoration(
color: Color.fromARGB(255, 16, 136, 192),
borderRadius: BorderRadius.circular(8),
),
child: Center(
child: Text(
text,
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.w900,
fontSize: 16,
),
),
),
),
);
}
}
153 changes: 153 additions & 0 deletions components/my_login.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
import 'package:flutter/material.dart';
import 'package:myapp/components/my_button.dart';
import 'package:myapp/components/my_register.dart';
import 'package:myapp/components/my_textfield.dart';
import 'package:http/http.dart' as http;
import 'dart:convert';
import 'package:myapp/main.dart';
import 'package:myapp/profile.dart';
import 'package:shared_preferences/shared_preferences.dart';

class MyLogin extends StatefulWidget {
@override
_MyLoginState createState() => _MyLoginState();
}

class _MyLoginState extends State<MyLogin> {
final TextEditingController usernamecontroller = TextEditingController();
final TextEditingController passwordcontroller = TextEditingController();
bool isvalid = true;
bool isLoading = false;
@override
void initState() {
super.initState();
}

Future<void> loginUser() async {
if (usernamecontroller.text.length < 3 ||
passwordcontroller.text.length < 8) {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text('لطفا نام کاربری یا رمز عبور را درست وارد کنید')));
setState(() {
isvalid = false;
});
} else {
setState(() {
isvalid = true;
});
}
if (isvalid) {
setState(() {
isLoading = true;
});
final response = await http.post(
Uri.parse('http://bluequote.freehost.io/login.php'),
body: {
'username': usernamecontroller.text,
'password': passwordcontroller.text,
},
);
setState(() {
isLoading = true;
});
if (response.statusCode == 200) {
final data = jsonDecode(response.body);
SharedPreferences info = await SharedPreferences.getInstance();
if (data['status'] == 'success') {
info.setString('userId', data['userId'].toString());
info.setString('username', usernamecontroller.text);
info.setString('password', passwordcontroller.text);
info.setString('email', data['email']);
setState(() {
isLoading = false;
});
Navigator.pushReplacement(
context,
MaterialPageRoute(builder: (context) => Main()),
);
} else {
setState(() {
isLoading = false;
});
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(' ${data['message']}')),
);
}
} else {
setState(() {
isLoading = false;
});
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Server error: ${response.statusCode}')),
);
}
}
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("ورود"),
),
body: Center(
child: isLoading
? CircularProgressIndicator()
: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Container(
margin: EdgeInsets.only(right: 50, bottom: 8, top: 8),
child: Text(
'نام کاربری',
style: TextStyle(
fontWeight: FontWeight.w900,
fontSize: 15,
color: Colors.blue[200]),
),
),
SizedBox(
width: 420,
height: 50,
child: MyTextField(
controller: usernamecontroller,
hintText: 'ali',
obscureText: false),
),
Container(
margin: EdgeInsets.only(right: 50, bottom: 8, top: 8),
child: Text(
'رمزعبور',
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.w900,
color: Colors.blue[200]),
),
),
SizedBox(
width: 420,
height: 50,
child: MyTextField(
controller: passwordcontroller,
hintText: '123@sd',
obscureText: false),
),
SizedBox(height: 20),
MyButton(onTap: loginUser, text: 'ورود'),
SizedBox(height: 20),
Center(
child: GestureDetector(
onTap: () {
Navigator.of(context).push(
MaterialPageRoute(builder: (ctx) => SignUpText()));
},
child: Text('اکانت ندارم'),
),
),
],
),
),
);
}
}
Loading