diff --git a/DatabaseHandller/DtHelper.dart b/DatabaseHandller/DtHelper.dart deleted file mode 100644 index 8d62083..0000000 --- a/DatabaseHandller/DtHelper.dart +++ /dev/null @@ -1,59 +0,0 @@ -import 'package:app/Model/UserModel.dart'; -import 'package:path_provider/path_provider.dart'; -import 'package:path/path.dart'; -import 'package:sqflite/sqflite.dart'; -import 'package:sqlite_handler/database/database_helper.dart'; -import 'package:sqflite/sqlite_api.dart'; -import 'package:app/DatabaseHandller/DtHelper.dart'; -import 'dart:io' as io; - -class dbhelper { - Database? _db; - static const DB_Name = 'test.db'; - static const int version = 4; - static const String Table_user = 'user'; - static const String userName = 'user_name'; - static const String email = 'email'; - static const String password = 'password'; - dbhelper() { - initDb(); - } - - Future get db async { - _db ??= await initDb(); - return _db!; - } - - initDb() async { - io.Directory documentsDirectory = await getApplicationDocumentsDirectory(); - String path = join(documentsDirectory.path, DB_Name); - var db = await openDatabase(path, version: version, onCreate: _oncreate); - _db = db; - return db; - } - - _oncreate(Database db, int version) async { - await db.execute( - 'CREATE TABLE $Table_user ($userName TEXT PRIMARY KEY, $password TEXT)'); - } - - Future saveData(UserModel user) async { - var dbClient = await db; - int userID = await (await dbClient.insert(Table_user, user.toMap())); - user.user_name = userID.toString(); - - return user; - } - - Future getLoginUser(String username, String uPassword) async { - var dbClient = await db; - var res = await dbClient.rawQuery( - 'SELECT * FROM $Table_user WHERE $userName=? AND $password=?', - [username, uPassword]); - if (res.isNotEmpty) { - return UserModel.fromMap(res.first); - } - - return null; - } -} diff --git a/Model/UserModel.dart b/Model/UserModel.dart deleted file mode 100644 index 8ba7b9d..0000000 --- a/Model/UserModel.dart +++ /dev/null @@ -1,16 +0,0 @@ -class UserModel { - String? user_name; - String? email; - String? password; - UserModel(this.user_name, this.password); - Map toMap() { - var map = {'user_name': user_name, 'password': password}; - return map; - } - - UserModel.fromMap(Map map) { - user_name = map['user_name']; - email = map['email']; - password = map['password']; - } -} diff --git a/common/getInfoForm.dart b/common/getInfoForm.dart deleted file mode 100644 index dce494f..0000000 --- a/common/getInfoForm.dart +++ /dev/null @@ -1,49 +0,0 @@ -import 'package:flutter/material.dart'; - -class getTextFormField extends StatelessWidget { - TextEditingController? controller; - String? hintname; - IconData? iconData; - bool isObscureText; - TextInputType inputType; - getTextFormField( - {this.controller, - this.hintname, - this.iconData, - this.isObscureText = false, - this.inputType = TextInputType.text}); - @override - Widget build(BuildContext context) { - return Container( - padding: EdgeInsets.symmetric(horizontal: 20), - margin: EdgeInsets.only(top: 10), - child: TextFormField( - controller: controller, - obscureText: isObscureText, - keyboardType: inputType, - validator: (value) { - if (value == null || value.isEmpty) { - return "لطفا مقدار $hintname وارد کنید"; - } - return null; - }, - decoration: InputDecoration( - enabledBorder: OutlineInputBorder( - borderRadius: BorderRadius.circular(36), - borderSide: BorderSide(color: Colors.transparent)), - focusedBorder: OutlineInputBorder( - borderRadius: BorderRadius.all( - Radius.circular(30), - ), - borderSide: BorderSide(color: Colors.blue), - ), - prefixIcon: Icon(iconData), - hintText: hintname, - labelText: hintname, - filled: true, - fillColor: Colors.grey[200], - ), - ), - ); - } -} diff --git a/common/helper.dart b/common/helper.dart deleted file mode 100644 index 5b94e55..0000000 --- a/common/helper.dart +++ /dev/null @@ -1,3 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:toast/toast.dart'; -import 'package:app/DatabaseHandller/DtHelper.dart'; diff --git a/components/my_button.dart b/components/my_button.dart new file mode 100644 index 0000000..9b86faa --- /dev/null +++ b/components/my_button.dart @@ -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, + ), + ), + ), + ), + ); + } +} diff --git a/components/my_login.dart b/components/my_login.dart new file mode 100644 index 0000000..9058d47 --- /dev/null +++ b/components/my_login.dart @@ -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 { + final TextEditingController usernamecontroller = TextEditingController(); + final TextEditingController passwordcontroller = TextEditingController(); + bool isvalid = true; + bool isLoading = false; + @override + void initState() { + super.initState(); + } + + Future 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('اکانت ندارم'), + ), + ), + ], + ), + ), + ); + } +} diff --git a/components/my_register.dart b/components/my_register.dart new file mode 100644 index 0000000..488ed0b --- /dev/null +++ b/components/my_register.dart @@ -0,0 +1,228 @@ +import 'dart:math'; +import 'package:flutter/material.dart'; +import 'package:http/http.dart' as http; +import 'package:myapp/components/my_button.dart'; +import 'package:myapp/components/my_login.dart'; +import 'package:myapp/components/my_textfield.dart'; +import 'package:myapp/profile.dart'; +import 'dart:convert'; +import 'package:shared_preferences/shared_preferences.dart'; +import 'package:myapp/main.dart'; +import 'package:email_validator/email_validator.dart'; + +class SignUpText extends StatefulWidget { + @override + _SignUpTextState createState() => _SignUpTextState(); +} + +class _SignUpTextState extends State { + final TextEditingController usernameController = TextEditingController(); + final TextEditingController emailController = TextEditingController(); + final TextEditingController passwordController = TextEditingController(); + final TextEditingController confirmPasswordController = + TextEditingController(); + bool status = true; + bool isLoading = false; + Future registerUser() async { + bool isvalid = EmailValidator.validate(emailController.text); + if (!isvalid) { + ScaffoldMessenger.of(context).showSnackBar( + SnackBar(content: Text('لطفا ایمیل خود را درست وارد کنید'))); + setState(() { + status = false; + }); + } else { + setState(() { + status = true; + }); + } + if (passwordController.text.length < 8) { + ScaffoldMessenger.of(context).showSnackBar(SnackBar( + content: Text('لطفا کلمه عبور را بیشتر از 8 کاراکتر وارد کنید'))); + setState(() { + status = false; + }); + } else { + setState(() { + status = true; + }); + } + checkValue(usernameController.text); + setState(() { + isLoading = true; + }); + if (status && passwordController.text == confirmPasswordController.text) { + final response = await http.post( + Uri.parse('http://bluequote.freehost.io/register.php'), + body: { + 'username': usernameController.text, + 'email': emailController.text, + 'password': passwordController.text, + }, + ); + setState(() { + isLoading = true; + }); + if (response.statusCode == 200) { + final data = jsonDecode(response.body); + if (data['status'] == 'success') { + setState(() { + isLoading = false; + }); + SharedPreferences info = await SharedPreferences.getInstance(); + info.setString('userId', data["Id"].toString()); + info.setString('username', usernameController.text); + info.setString('email', emailController.text); + info.setString('password', passwordController.text); + 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}')), + ); + } + } else { + setState(() { + isLoading = false; + }); + ScaffoldMessenger.of(context).showSnackBar( + SnackBar(content: Text('Passwords do not match')), + ); + } + } + + checkValue(String username) { + if (username.length < 3) { + ScaffoldMessenger.of(context).showSnackBar( + SnackBar(content: Text('لطفا نام کاربری را درست وارد کنید'))); + setState(() { + status = false; + }); + } else { + setState(() { + status = true; + }); + } + } + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: Text("ثبت نام"), + ), + body: SingleChildScrollView( + child: isLoading + ? CircularProgressIndicator() + : Center( + child: 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: emailController, + hintText: 'example@gmail.com', + 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), + ), + 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: confirmPasswordController, + hintText: '123@sd', + obscureText: false), + ), + SizedBox(height: 20), + MyButton( + onTap: registerUser, + text: 'ثبت نام', + ), + SizedBox(height: 20), + Center( + child: GestureDetector( + onTap: () { + Navigator.of(context).push( + MaterialPageRoute(builder: (ctx) => MyLogin())); + }, + child: Text('اکانت دارم'), + ), + ), + ], + ), + ), + ), + ); + } +} diff --git a/components/my_textfield.dart b/components/my_textfield.dart new file mode 100644 index 0000000..537789e --- /dev/null +++ b/components/my_textfield.dart @@ -0,0 +1,40 @@ +import 'package:flutter/material.dart'; + +class MyTextField extends StatelessWidget { + final controller; + final String hintText; + final bool obscureText; + + const MyTextField({ + super.key, + required this.controller, + required this.hintText, + required this.obscureText, + }); + + @override + Widget build(BuildContext context) { + return Padding( + padding: const EdgeInsets.symmetric(horizontal: 40.0), + child: TextField( + style: TextStyle(color: Color.fromARGB(151, 0, 4, 12)), + textAlign: TextAlign.right, + controller: controller, + obscureText: obscureText, + decoration: InputDecoration( + enabledBorder: OutlineInputBorder( + borderRadius: BorderRadius.circular(10.0), + borderSide: BorderSide(color: Colors.blue, width: 2.3)), + focusedBorder: OutlineInputBorder( + borderRadius: BorderRadius.circular(10.0), + borderSide: BorderSide(color: Colors.grey.shade700)), + fillColor: const Color.fromARGB(255, 243, 244, 245), + filled: true, + hintText: hintText, + hintStyle: + TextStyle(color: Colors.grey[500], fontWeight: FontWeight.w900), + ), + ), + ); + } +} diff --git a/dashboard.dart b/dashboard.dart new file mode 100644 index 0000000..646c601 --- /dev/null +++ b/dashboard.dart @@ -0,0 +1,211 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_svg/flutter_svg.dart'; +import 'package:myapp/main.dart'; +import 'package:myapp/myfavorite.dart'; +import 'package:myapp/profile.dart'; + +void dashboard() { + runApp(const MyApp()); +} + +class MyApp extends StatelessWidget { + const MyApp({super.key}); + + Widget build(BuildContext context) { + return MaterialApp( + debugShowCheckedModeBanner: false, + home: Scaffold( + appBar: AppBar( + backgroundColor: Colors.white, + title: Text( + 'داشبورد کاربر', + style: TextStyle( + fontWeight: FontWeight.w900, + fontSize: 21, + color: Colors.blue[200]), + ), + centerTitle: true, + actions: [ + IconButton( + icon: Icon( + Icons.arrow_right_alt, + size: 40, + color: Colors.blue[200], + ), + onPressed: () { + Navigator.of(context).pushReplacement( + MaterialPageRoute(builder: (ctx) => Main())); + }), + ]), + body: Center( + child: Column( + mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Container( + width: 350, + height: 50, + margin: EdgeInsets.only(right: 0, bottom: 8, top: 8), + alignment: Alignment.center, + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(10.0), + border: Border.all( + color: Colors.blue, + style: BorderStyle.solid, + width: 2.5), + ), + child: InkWell( + onTap: () { + Navigator.of(context).pushReplacement( + MaterialPageRoute(builder: (ctx) => profile())); + }, + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Icon( + Icons.keyboard_arrow_left, + size: 24, + color: Colors.blue, + ), + Text( + 'اطلاعات کاربر', + style: TextStyle( + fontWeight: FontWeight.w900, + fontSize: 15, + color: Colors.blue[200]), + ), + Icon( + Icons.person_rounded, + size: 24, + color: Colors.blue, + ), + ], + ), + ), + ), + Container( + width: 350, + height: 50, + margin: EdgeInsets.only(right: 0, bottom: 8, top: 8), + alignment: Alignment.center, + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(10.0), + border: Border.all( + color: Colors.blue, + style: BorderStyle.solid, + width: 2.5), + ), + child: InkWell( + onTap: () { + Navigator.of(context).pushReplacement( + MaterialPageRoute(builder: (ctx) => profile())); + }, + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Icon( + Icons.keyboard_arrow_left, + size: 24, + color: Colors.blue, + ), + Text( + 'تغییر ایمیل', + style: TextStyle( + fontWeight: FontWeight.w900, + fontSize: 15, + color: Colors.blue[200]), + ), + Icon( + Icons.email_rounded, + size: 24, + color: Colors.blue, + ), + ], + ), + ), + ), + Container( + width: 350, + height: 50, + margin: EdgeInsets.only(right: 0, bottom: 8, top: 8), + alignment: Alignment.center, + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(10.0), + border: Border.all( + color: Colors.blue, + style: BorderStyle.solid, + width: 2.5), + ), + child: InkWell( + onTap: () { + Navigator.of(context).pushReplacement( + MaterialPageRoute(builder: (ctx) => profile())); + }, + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Icon( + Icons.keyboard_arrow_left, + size: 24, + color: Colors.blue, + ), + Text( + 'تغییر رمز عبور', + style: TextStyle( + fontWeight: FontWeight.w900, + fontSize: 15, + color: Colors.blue[200]), + ), + Icon( + Icons.key_rounded, + size: 24, + color: Colors.blue, + ), + ], + ), + ), + ), + Container( + width: 350, + height: 50, + margin: EdgeInsets.only(right: 0, bottom: 8, top: 8), + alignment: Alignment.center, + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(10.0), + border: Border.all( + color: Colors.blue, + style: BorderStyle.solid, + width: 2.5), + ), + child: InkWell( + onTap: () { + Navigator.of(context).pushReplacement(MaterialPageRoute( + builder: (ctx) => listfavorite())); + }, + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Icon( + Icons.keyboard_arrow_left, + size: 24, + color: Colors.blue, + ), + Text( + 'متن های مورد علاقه', + style: TextStyle( + fontWeight: FontWeight.w900, + fontSize: 15, + color: Colors.blue[200]), + ), + Icon( + Icons.star_rounded, + size: 24, + color: Colors.blue, + ), + ], + ), + ), + ), + ])))); + } +} diff --git a/lib/DatabaseHandller/DtHelper.dart b/lib/DatabaseHandller/DtHelper.dart deleted file mode 100644 index 8d62083..0000000 --- a/lib/DatabaseHandller/DtHelper.dart +++ /dev/null @@ -1,59 +0,0 @@ -import 'package:app/Model/UserModel.dart'; -import 'package:path_provider/path_provider.dart'; -import 'package:path/path.dart'; -import 'package:sqflite/sqflite.dart'; -import 'package:sqlite_handler/database/database_helper.dart'; -import 'package:sqflite/sqlite_api.dart'; -import 'package:app/DatabaseHandller/DtHelper.dart'; -import 'dart:io' as io; - -class dbhelper { - Database? _db; - static const DB_Name = 'test.db'; - static const int version = 4; - static const String Table_user = 'user'; - static const String userName = 'user_name'; - static const String email = 'email'; - static const String password = 'password'; - dbhelper() { - initDb(); - } - - Future get db async { - _db ??= await initDb(); - return _db!; - } - - initDb() async { - io.Directory documentsDirectory = await getApplicationDocumentsDirectory(); - String path = join(documentsDirectory.path, DB_Name); - var db = await openDatabase(path, version: version, onCreate: _oncreate); - _db = db; - return db; - } - - _oncreate(Database db, int version) async { - await db.execute( - 'CREATE TABLE $Table_user ($userName TEXT PRIMARY KEY, $password TEXT)'); - } - - Future saveData(UserModel user) async { - var dbClient = await db; - int userID = await (await dbClient.insert(Table_user, user.toMap())); - user.user_name = userID.toString(); - - return user; - } - - Future getLoginUser(String username, String uPassword) async { - var dbClient = await db; - var res = await dbClient.rawQuery( - 'SELECT * FROM $Table_user WHERE $userName=? AND $password=?', - [username, uPassword]); - if (res.isNotEmpty) { - return UserModel.fromMap(res.first); - } - - return null; - } -} diff --git a/lib/Model/UserModel.dart b/lib/Model/UserModel.dart deleted file mode 100644 index 8ba7b9d..0000000 --- a/lib/Model/UserModel.dart +++ /dev/null @@ -1,16 +0,0 @@ -class UserModel { - String? user_name; - String? email; - String? password; - UserModel(this.user_name, this.password); - Map toMap() { - var map = {'user_name': user_name, 'password': password}; - return map; - } - - UserModel.fromMap(Map map) { - user_name = map['user_name']; - email = map['email']; - password = map['password']; - } -} diff --git a/lib/color.dart b/lib/color.dart deleted file mode 100644 index a4f01d8..0000000 --- a/lib/color.dart +++ /dev/null @@ -1,3 +0,0 @@ -import 'package:flutter/material.dart'; - -Color mco = Color(0xFF6750A4); diff --git a/lib/common/getInfoForm.dart b/lib/common/getInfoForm.dart deleted file mode 100644 index dce494f..0000000 --- a/lib/common/getInfoForm.dart +++ /dev/null @@ -1,49 +0,0 @@ -import 'package:flutter/material.dart'; - -class getTextFormField extends StatelessWidget { - TextEditingController? controller; - String? hintname; - IconData? iconData; - bool isObscureText; - TextInputType inputType; - getTextFormField( - {this.controller, - this.hintname, - this.iconData, - this.isObscureText = false, - this.inputType = TextInputType.text}); - @override - Widget build(BuildContext context) { - return Container( - padding: EdgeInsets.symmetric(horizontal: 20), - margin: EdgeInsets.only(top: 10), - child: TextFormField( - controller: controller, - obscureText: isObscureText, - keyboardType: inputType, - validator: (value) { - if (value == null || value.isEmpty) { - return "لطفا مقدار $hintname وارد کنید"; - } - return null; - }, - decoration: InputDecoration( - enabledBorder: OutlineInputBorder( - borderRadius: BorderRadius.circular(36), - borderSide: BorderSide(color: Colors.transparent)), - focusedBorder: OutlineInputBorder( - borderRadius: BorderRadius.all( - Radius.circular(30), - ), - borderSide: BorderSide(color: Colors.blue), - ), - prefixIcon: Icon(iconData), - hintText: hintname, - labelText: hintname, - filled: true, - fillColor: Colors.grey[200], - ), - ), - ); - } -} diff --git a/lib/common/helper.dart b/lib/common/helper.dart deleted file mode 100644 index 5b94e55..0000000 --- a/lib/common/helper.dart +++ /dev/null @@ -1,3 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:toast/toast.dart'; -import 'package:app/DatabaseHandller/DtHelper.dart'; diff --git a/lib/core.dart b/lib/core.dart deleted file mode 100644 index 69acf90..0000000 --- a/lib/core.dart +++ /dev/null @@ -1,14 +0,0 @@ -/* -We believe, the class name must be unique. -If there is a conflicting class name in this file, -it means you have to rename it to something more unique. -*/ -export 'package:app/color.dart'; -export 'package:app/common/getInfoForm.dart'; -export 'package:app/common/helper.dart'; -export 'package:app/DatabaseHandller/DtHelper.dart'; -export 'package:app/login.dart'; -export 'package:app/Model/UserModel.dart'; -export 'package:app/navBar.dart'; -export 'package:app/signUp.dart'; -export 'package:app/welocome.dart'; \ No newline at end of file diff --git a/lib/login.dart b/lib/login.dart deleted file mode 100644 index 248d839..0000000 --- a/lib/login.dart +++ /dev/null @@ -1,147 +0,0 @@ -// ignore_for_file: prefer_const_constructors - -import 'package:app/DatabaseHandller/DtHelper.dart'; -import 'package:app/common/getInfoForm.dart'; -import 'package:app/main.dart'; -import 'package:app/welocome.dart'; -import 'package:flutter/material.dart'; -import 'package:app/signUp.dart'; - -class login extends StatefulWidget { - @override - State createState() => _loginState(); -} - -class _loginState extends State { - final _formkey = GlobalKey(); - final _conUsername = TextEditingController(); - final _conPassword = TextEditingController(); - var dbHelper; - @override - void initSate() { - super.initState(); - dbHelper = dbHelper(); - } - - loginvalid() { - String uname = _conUsername.text; - String upassword = _conPassword.text; - - if (uname.isEmpty) { - } else if (upassword.isEmpty) { - } else { - dbhelper dh = dbhelper(); - dh.getLoginUser(uname, upassword).then((userData) { - if (userData != null) { - Navigator.of(context) - .pushReplacement(MaterialPageRoute(builder: (ctx) => welcome())); - } - }).catchError((error) { - print(error); - }); - } - } - - @override - Widget build(BuildContext context) { - return Scaffold( - appBar: AppBar( - title: const Text( - 'ورود', - style: TextStyle(color: Colors.white), - ), - backgroundColor: Colors.blue, - ), - body: SingleChildScrollView( - scrollDirection: Axis.vertical, - child: Container( - child: Center( - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - const SizedBox( - height: 50, - ), - const Text( - 'ورود', - style: TextStyle( - fontWeight: FontWeight.bold, - color: Colors.black, - fontSize: 30, - ), - ), - const SizedBox( - height: 10, - ), - Image.asset( - 'assets/images/1.png', - width: 40, - height: 40, - ), - const SizedBox( - height: 4, - ), - const Text( - 'CodeRunner', - style: TextStyle(color: Colors.black38, fontSize: 25), - ), - getTextFormField( - controller: _conUsername, - iconData: Icons.person, - hintname: 'نام کاربری', - inputType: TextInputType.text, - ), - getTextFormField( - controller: _conPassword, - iconData: Icons.lock, - hintname: 'کلمه عبور', - isObscureText: true, - ), - Container( - margin: EdgeInsets.all(30), - width: double.infinity, - child: ElevatedButton( - style: - ElevatedButton.styleFrom(backgroundColor: Colors.blue), - onPressed: () { - loginvalid(); - }, - child: Text( - 'ورود', - style: TextStyle(color: Colors.white), - )), - ), - Container( - child: Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Text('من اکانت ندارم'), - const SizedBox( - width: 5, - ), - GestureDetector( - onTap: () { - Navigator.of(context).pushReplacement( - MaterialPageRoute(builder: (ctx) => signUp())); - }, - child: Text( - 'ثبت نام', - style: TextStyle(color: Colors.blue), - )), - GestureDetector( - onTap: () { - Navigator.of(context).pushReplacement( - MaterialPageRoute(builder: (ctx) => MyHomePage())); - }, - child: Text('بازگشت به عنوان مهمان'), - ) - ], - ), - ) - ], - ), - )), - ), - ); - } -} diff --git a/lib/main.dart b/lib/main.dart deleted file mode 100644 index 893fb06..0000000 --- a/lib/main.dart +++ /dev/null @@ -1,55 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:app/color.dart'; -import 'package:app/login.dart'; -import 'package:localization/localization.dart'; -import 'package:flutter/services.dart'; -import 'navBar.dart'; - -void main() { - SystemChrome.setSystemUIOverlayStyle( - SystemUiOverlayStyle(statusBarColor: mco)); - - runApp(const MyApp()); -} - -class MyApp extends StatelessWidget { - const MyApp({super.key}); - - @override - Widget build(BuildContext context) { - return MaterialApp( - debugShowCheckedModeBanner: false, - home: login(), - ); - } -} - -class MyHomePage extends StatelessWidget { - @override - Widget build(BuildContext context) { - // TODO: implement build - return Scaffold( - appBar: AppBar( - backgroundColor: mco, - title: Text( - 'انگیزش روزانه', - style: TextStyle(color: Colors.pink.shade400), - ), - centerTitle: true, - ), - drawer: NavBar(), - body: const Center( - child: Text( - 'خواستن توانستن نیست!', - style: TextStyle(fontSize: 40.0), - ), - ), - bottomNavigationBar: BottomNavigationBar( - items: const [ - BottomNavigationBarItem(label: 'خانه', icon: Icon(Icons.home)), - BottomNavigationBarItem(label: 'تنظیمات', icon: Icon(Icons.settings)) - ], - ), - ); - } -} diff --git a/lib/navBar.dart b/lib/navBar.dart deleted file mode 100644 index 8b750a9..0000000 --- a/lib/navBar.dart +++ /dev/null @@ -1,54 +0,0 @@ -import 'dart:io'; -import 'package:app/login.dart'; -import 'package:app/main.dart'; -import 'package:app/signUp.dart'; -import 'package:flutter/material.dart'; - -class NavBar extends StatelessWidget { - const NavBar({super.key}); - - @override - Widget build(BuildContext context) { - return Drawer( - child: ListView( - children: [ - UserAccountsDrawerHeader( - accountName: const Text('نام کاربری'), - accountEmail: const Text('ایمیل شما'), - ), - ListTile( - leading: Icon(Icons.login), - title: const Text('صفحه اصلی'), - onTap: () { - Navigator.of(context).pushReplacement( - MaterialPageRoute(builder: (ctx) => (MyApp()))); - }, - ), - ListTile( - leading: Icon(Icons.login), - title: const Text('ورود'), - onTap: () { - Navigator.of(context).pushReplacement( - MaterialPageRoute(builder: (ctx) => (login()))); - }, - ), - ListTile( - leading: Icon(Icons.outbond), - title: const Text('ثبت نام'), - onTap: () { - Navigator.of(context).pushReplacement( - MaterialPageRoute(builder: (ctx) => (signUp()))); - }, - ), - ListTile( - leading: Icon(Icons.exit_to_app), - title: const Text('خروج'), - onTap: () { - exit(0); - }, - ), - ], - ), - ); - } -} diff --git a/lib/signUp.dart b/lib/signUp.dart deleted file mode 100644 index 18cdebd..0000000 --- a/lib/signUp.dart +++ /dev/null @@ -1,160 +0,0 @@ -import 'package:app/DatabaseHandller/DtHelper.dart'; -import 'package:app/Model/UserModel.dart'; -import 'package:app/common/getInfoForm.dart'; -import 'package:app/login.dart'; -import 'package:app/main.dart'; -import 'package:flutter/material.dart'; -import 'package:toast/toast.dart'; - -class signUp extends StatefulWidget { - @override - State createState() => _signUpState(); -} - -class _signUpState extends State { - final _formkey = GlobalKey(); - final _conUsername = TextEditingController(); - final _conEmail = TextEditingController(); - final _conPassword = TextEditingController(); - final _conRePassword = TextEditingController(); - var dbHelper; - @override - void initSate() { - super.initState(); - dbHelper = dbHelper(); - } - - valid() { - final form = _formkey.currentState; - String uname = _conUsername.text; - String uEmail = _conEmail.text; - String uPassword = _conPassword.text; - String uRePassword = _conRePassword.text; - - if (_formkey.currentState!.validate()) { - if (uPassword != uRePassword) { - } else { - _formkey.currentState!.save(); - - UserModel umodel = UserModel(uname, uPassword); - dbhelper dh = dbhelper(); - dh.saveData(umodel).then((userData) { - if (userData != null) { - print('ثبت نام شدید'); - } - }).catchError((error) { - print(error); - }); - } - } - } - - @override - Widget build(BuildContext context) { - return Scaffold( - appBar: AppBar( - title: const Text( - 'ثبت نام', - style: TextStyle(color: Colors.white), - ), - backgroundColor: Colors.blue, - ), - body: Form( - key: _formkey, - child: SingleChildScrollView( - scrollDirection: Axis.vertical, - child: Container( - child: Center( - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - const SizedBox( - height: 50, - ), - const Text( - 'ثبت نام', - style: TextStyle( - fontWeight: FontWeight.bold, - color: Colors.black, - fontSize: 30, - ), - ), - const SizedBox( - height: 10, - ), - Image.asset( - 'assets/images/1.png', - width: 40, - height: 40, - ), - const SizedBox( - height: 4, - ), - const Text( - 'CodeRunner', - style: TextStyle(color: Colors.black38, fontSize: 25), - ), - getTextFormField( - controller: _conUsername, - hintname: 'نام کاربری', - iconData: Icons.person, - inputType: TextInputType.text), - getTextFormField( - controller: _conEmail, - hintname: 'ایمیل', - iconData: Icons.email, - inputType: TextInputType.emailAddress), - getTextFormField( - controller: _conPassword, - hintname: 'کلمه عبور', - iconData: Icons.lock, - isObscureText: true, - ), - getTextFormField( - controller: _conRePassword, - hintname: 'تکرار کلمه عبور', - iconData: Icons.lock, - isObscureText: true, - ), - Container( - margin: const EdgeInsets.all(30), - width: double.infinity, - child: ElevatedButton( - style: ElevatedButton.styleFrom( - backgroundColor: Colors.blue), - onPressed: () { - valid(); - }, - child: const Text( - 'ورود', - style: TextStyle(color: Colors.white), - )), - ), - Container( - child: Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - const Text('من اکانت دارم'), - const SizedBox( - width: 5, - ), - GestureDetector( - onTap: () { - Navigator.of(context).pushReplacement( - MaterialPageRoute(builder: (ctx) => login())); - }, - child: const Text( - 'ورود', - style: TextStyle(color: Colors.blue, fontSize: 30), - )), - ], - ), - ) - ], - ), - )), - ), - ), - ); - } -} diff --git a/lib/welocome.dart b/lib/welocome.dart deleted file mode 100644 index f563b89..0000000 --- a/lib/welocome.dart +++ /dev/null @@ -1,20 +0,0 @@ -import 'package:flutter/material.dart'; - -class welcome extends StatefulWidget { - @override - State createState() => _welcomeState(); -} - -class _welcomeState extends State { - @override - Widget build(BuildContext context) { - return Scaffold( - appBar: AppBar( - title: Text('خوش اومدی آقا'), - ), - body: Column( - children: [Text('خوش اومدی')], - ), - ); - } -} diff --git a/main.dart b/main.dart new file mode 100644 index 0000000..110a07e --- /dev/null +++ b/main.dart @@ -0,0 +1,309 @@ +import 'package:flutter/material.dart'; +import 'package:google_nav_bar/google_nav_bar.dart'; +import 'package:myapp/components/my_login.dart'; +import 'package:myapp/components/my_register.dart'; +import 'package:myapp/dashboard.dart'; +import 'package:myapp/myfavorite.dart'; +import 'package:myapp/profile.dart'; +import 'package:http/http.dart' as http; +import 'package:shared_preferences/shared_preferences.dart'; +import 'dart:convert'; +import 'package:translator/translator.dart'; +import 'package:share_plus/share_plus.dart'; + +void main() { + runApp(const Main()); +} + +class Main extends StatelessWidget { + const Main({Key? key}) : super(key: key); + + @override + Widget build(BuildContext context) { + return MaterialApp( + debugShowCheckedModeBanner: false, + home: FutureBuilder( + future: checkLoginStatus(), + builder: (context, snapshot) { + if (snapshot.connectionState == ConnectionState.waiting) { + return Scaffold( + body: Center( + child: CircularProgressIndicator(), + ), + ); + } else { + if (snapshot.hasError) { + return Scaffold( + body: Center( + child: Text('Error: ${snapshot.error}'), + ), + ); + } else { + bool isLoggedIn = snapshot.data ?? false; + return isLoggedIn ? MainScreen() : MyLogin(); + } + } + }, + ), + ); + } + + Future checkLoginStatus() async { + SharedPreferences info = await SharedPreferences.getInstance(); + return info.getString('userId') != null; + } +} + +class MainScreen extends StatefulWidget { + @override + _MainScreenState createState() => _MainScreenState(); +} + +class _MainScreenState extends State { + int _selectedIndex = 0; + String text = "Loading..."; + String translateText = ""; + bool isMyFavorite = false; + final GlobalKey _navigatorKey = GlobalKey(); + + @override + void initState() { + super.initState(); + validate(); + validationMyFavorite(); + } + + Future validate() async { + SharedPreferences vld = await SharedPreferences.getInstance(); + String? saveDates = vld.getString('saveDates'); + String? savefarsi = vld.getString('saveTranslate'); + String? saveMessage = vld.getString('saveMessage'); + String today = DateTime.now().toString().split(' ')[0]; + if (saveDates == today && saveMessage != null) { + setState(() { + text = saveMessage; + translateText = savefarsi!; + }); + } else { + showMessage(); + } + } + + Future showMessage() async { + try { + final response = + await http.get(Uri.parse('https://api.quotable.io/random')); + if (response.statusCode == 200) { + final data = jsonDecode(response.body); + final quote = data['content']; + final translator = GoogleTranslator(); + final translation = await translator.translate(quote, to: 'fa'); + + SharedPreferences vld = await SharedPreferences.getInstance(); + String today = DateTime.now().toString().split(' ')[0]; + vld.setString('saveDates', today); + vld.setString('saveMessage', quote); + vld.setString('saveTranslate', translation.text); + + setState(() { + translateText = translation.text; + text = data['content'] + '\n'; + }); + } else { + setState(() { + text = 'Failed to load quote'; + translateText = "خطا در بارگزاری متن"; + }); + } + } catch (error) { + setState(() { + text = 'Error: $error'; + translateText = 'خطا $error'; + }); + } + } + + Future saveFavorite(String text) async { + SharedPreferences fvt = await SharedPreferences.getInstance(); + fvt.setString('myFavorite', text); + fvt.setString('myFavoriteT', translateText); + if (fvt.getString('userId') != null) { + String? userId = fvt.getString('userId'); + final response = await http.post( + Uri.parse('http://bluequote.freehost.io/addFavorite.php'), + body: { + 'userId': userId.toString(), + 'quoteMain': text, + 'quoteTranslate': translateText, + }, + ); + if (response.statusCode == 200) { + final data = jsonDecode(response.body); + if (data['status'] == 'success') { + fvt.setString('id', data['Id'].toString()); + } else { + ScaffoldMessenger.of(context).showSnackBar( + SnackBar(content: Text('Login failed: ${data['message']}')), + ); + } + } else { + ScaffoldMessenger.of(context).showSnackBar( + SnackBar(content: Text('Server error: ${response.statusCode}')), + ); + } + } else { + ScaffoldMessenger.of(context) + .showSnackBar(SnackBar(content: Text('لطفا ورود یا ثبت نام کنید'))); + } + } + + Future deleteFavorite() async { + SharedPreferences fvt = await SharedPreferences.getInstance(); + String? id = fvt.getString('id'); + fvt.remove('myFavorite'); + fvt.remove('myFavoriteT'); + final response = await http.post( + Uri.parse('http://bluequote.freehost.io/removeFavorite.php'), + body: {'quoteId': id.toString()}, + ); + if (response.statusCode == 200) { + final data = jsonDecode(response.body); + if (data["status"] == "success") { + fvt.remove('id'); + } else { + ScaffoldMessenger.of(context).showSnackBar( + SnackBar(content: Text('Login failed: ${data['message']}')), + ); + } + } else { + ScaffoldMessenger.of(context).showSnackBar( + SnackBar(content: Text('Server error: ${response.statusCode}')), + ); + } + } + + Future validationMyFavorite() async { + SharedPreferences vld = await SharedPreferences.getInstance(); + setState(() { + isMyFavorite = vld.getString('myFavorite') != null; + }); + } + + void _onTabSelected(int index) { + setState(() { + _selectedIndex = index; + }); + + if (index == 2) { + _navigatorKey.currentState?.push( + MaterialPageRoute(builder: (context) => MyApp()), + ); + } + } + + void _onPressed() async { + if (isMyFavorite) { + await deleteFavorite(); + } else { + await saveFavorite(text); + Navigator.of(context) + .pushReplacement(MaterialPageRoute(builder: (ctx) => listfavorite())); + } + setState(() { + isMyFavorite = !isMyFavorite; + }); + } + + void _onShare() { + Share.share(text); + } + + void _onMove() { + Navigator.of(context) + .pushReplacement(MaterialPageRoute(builder: (ctx) => MyApp())); + } + + @override + Widget build(BuildContext context) { + return Scaffold( + body: Center( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Expanded( + child: Container( + margin: EdgeInsets.only(bottom: 10, top: 20), + width: 335, + child: Column( + children: [ + Text( + text, + textAlign: TextAlign.center, + style: TextStyle( + color: Colors.red, + fontSize: 20, + ), + ), + Text( + translateText, + textAlign: TextAlign.center, + style: TextStyle( + color: Colors.blue, + fontSize: 20, + ), + ), + ], + ), + decoration: BoxDecoration( + color: Colors.grey[200], + borderRadius: BorderRadius.circular(10.0), + border: Border.all( + color: Colors.blue, + style: BorderStyle.solid, + width: 2.5, + ), + ), + ), + ), + Container( + margin: const EdgeInsets.only(top: 0), + height: 2, + width: 420, + decoration: BoxDecoration( + color: Colors.grey[200], + borderRadius: BorderRadius.circular(10.0), + border: Border.all(color: Colors.blue), + ), + ), + ], + ), + ), + bottomNavigationBar: GNav( + padding: EdgeInsets.all(10), + activeColor: Colors.blue[900], + gap: 10, + color: Colors.blue[400], + tabs: [ + GButton( + icon: Icons.share, + iconSize: 40, + onPressed: _onShare, + ), + GButton( + icon: isMyFavorite ? Icons.favorite : Icons.heart_broken, + iconSize: 40, + onPressed: _onPressed, + ), + GButton( + icon: Icons.person_rounded, + iconSize: 40, + onPressed: _onMove, + ), + ], + selectedIndex: _selectedIndex, + onTabChange: _onTabSelected, + ), + ); + } +} diff --git a/myfavorite.dart b/myfavorite.dart new file mode 100644 index 0000000..0324303 --- /dev/null +++ b/myfavorite.dart @@ -0,0 +1,102 @@ +import 'package:flutter/material.dart'; +import 'package:http/http.dart' as http; +import 'package:myapp/main.dart'; +import 'package:shared_preferences/shared_preferences.dart'; +import 'dart:convert'; +import 'package:flutter/material.dart'; + +void main() {} + +class listfavorite extends StatefulWidget { + @override + State createState() => _listfavoriteState(); +} + +class _listfavoriteState extends State { + List favorites = []; + bool isLoading = true; + @override + void initState() { + super.initState(); + fetchList(); + } + + Future fetchList() async { + SharedPreferences info = await SharedPreferences.getInstance(); + String? id = info.getString('userId'); + if (id != null) { + final response = await http.post( + Uri.parse('http://bluequote.freehost.io/showMyfavorite.php'), + body: {'userId': info.getString('userId')}); + if (response.statusCode == 200) { + final data = jsonDecode(response.body); + if (data['status'] == 'success') { + setState(() { + favorites = List.from(data['quote']); + isLoading = false; + }); + } else { + setState(() { + ScaffoldMessenger.of(context).showSnackBar( + SnackBar(content: Text('عملیات فراخوانی موفقیت آمیز نبود'))); + isLoading = true; + }); + } + } + } + } + + @override + Widget build(BuildContext context) { + final appTitle = "لیست مورد علاقه ها"; + return MaterialApp( + title: appTitle, + home: Scaffold( + appBar: AppBar( + title: Text(appTitle), + leading: IconButton( + onPressed: () { + Navigator.of(context).pushReplacement( + MaterialPageRoute(builder: (ctx) => Main())); + }, + icon: Icon(Icons.arrow_back)), + ), + body: ListView.builder( + itemCount: favorites.length, + itemBuilder: (context, index) { + return Container( + width: 200, + height: 150, + margin: EdgeInsets.only(right: 0, bottom: 8, top: 8), + alignment: Alignment.center, + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(10.0), + border: Border.all( + color: Colors.blue, style: BorderStyle.solid, width: 2.5), + ), + child: InkWell( + onTap: () {}, + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Icon( + Icons.keyboard_arrow_left, + size: 24, + color: Colors.blue, + ), + Text( + '${favorites}', + style: TextStyle( + fontWeight: FontWeight.w900, + fontSize: 15, + color: Colors.blue[200]), + ), + ], + ), + ), + ); + }, + )), + ); + } +} diff --git a/profile.dart b/profile.dart new file mode 100644 index 0000000..e0b4ef6 --- /dev/null +++ b/profile.dart @@ -0,0 +1,291 @@ +import 'package:flutter/material.dart'; +import 'package:myapp/components/my_login.dart'; +import 'package:myapp/components/my_register.dart'; +import 'package:myapp/dashboard.dart'; +import 'package:myapp/main.dart'; +import 'package:myapp/myfavorite.dart'; +import 'components/my_textfield.dart'; +import 'components/my_button.dart'; +import 'package:shared_preferences/shared_preferences.dart'; +import 'package:email_validator/email_validator.dart'; +import 'package:http/http.dart' as http; +import 'dart:convert'; + +void main() { + runApp(profile()); +} + +class profile extends StatelessWidget { + profile({super.key}); + final usernamecontroller = TextEditingController(); + final emailcontroller = TextEditingController(); + final passwordcontroller = TextEditingController(); + bool isLoading = false; + @override + Widget build(BuildContext context) { + return MaterialApp( + debugShowCheckedModeBanner: false, + home: MainScreen(), + ); + } +} + +class MainScreen extends StatefulWidget { + MainScreen({super.key}); + + @override + State createState() => _MainScreenState(); +} + +class _MainScreenState extends State { + @override + void initState() { + super.initState(); + validationInformation(); + } + + final TextEditingController usernamecontroller = TextEditingController(); + final TextEditingController emailcontroller = TextEditingController(); + final TextEditingController passwordcontroller = TextEditingController(); + + String? username = 'unknown'; + String? email = 'unknown'; + String? password = 'unknown'; + String? threeTitr; + + bool isvalid = true; + bool isLoading = false; + Future validationInformation() async { + SharedPreferences info = await SharedPreferences.getInstance(); + setState(() { + username = info.getString('username') ?? 'unknown'; + email = info.getString('email') ?? 'unknown'; + password = info.getString('password') ?? 'unknown'; + usernamecontroller.text = username!; + emailcontroller.text = email!; + passwordcontroller.text = password!; + if (info.getString('username') != null) { + threeTitr = 'خروج'; + } else { + threeTitr = ''; + } + }); + } + + Future updateUser() async { + SharedPreferences info = await SharedPreferences.getInstance(); + String? userId = info.getString('userId'); + var validEmail = EmailValidator.validate(emailcontroller.text); + if (usernamecontroller.text.length < 3 && + passwordcontroller.text.length < 8) { + ScaffoldMessenger.of(context).showSnackBar(SnackBar( + content: Text( + 'لطفا نام کاربری کمتر از 3 کاراکتر و رمز عبور کمتر از 8 کاراکتر نباشد'))); + setState(() { + isvalid = false; + }); + } else { + setState(() { + isvalid = true; + }); + } + if (!validEmail) { + ScaffoldMessenger.of(context).showSnackBar( + SnackBar(content: Text('لطفا ایمیل را درست وارد کنید'))); + setState(() { + isvalid = false; + }); + } else { + setState(() { + isvalid = true; + }); + } + setState(() { + isLoading = true; + }); + + if (isvalid && userId != null) { + SharedPreferences info = await SharedPreferences.getInstance(); + final response = await http.post( + Uri.parse('http://bluequote.freehost.io/updateUser.php'), + headers: { + 'Content-Type': 'application/x-www-form-urlencoded', + }, + body: { + 'userId': info.getString('userId'), + 'username': usernamecontroller.text, + 'email': emailcontroller.text, + 'password': passwordcontroller.text + }); + setState(() { + isLoading = true; + }); + if (response.statusCode == 200) { + final data = jsonDecode(response.body); + if (data['status'] == 'success') { + setState(() { + isLoading = false; + }); + info.setString('username', data['username']); + info.setString('email', data['email']); + info.setString('password', data['password']); + validationInformation(); + } + } else { + setState(() { + isLoading = false; + }); + ScaffoldMessenger.of(context) + .showSnackBar(SnackBar(content: Text('ارتباط با سرور برقرار نشد'))); + } + } else { + setState(() { + isLoading = false; + }); + ScaffoldMessenger.of(context).showSnackBar( + SnackBar(content: Text('لطفا ابتدا ثبت نام یا ورود کنید'))); + } + } + + Future logout() async { + final response = + await http.get(Uri.parse('http://bluequote.freehost.io/logout.php')); + setState(() { + isLoading = true; + }); + if (response.statusCode == 200) { + setState(() { + isLoading = false; + }); + SharedPreferences info = await SharedPreferences.getInstance(); + info.remove('userId'); + info.remove('username'); + info.remove('email'); + info.remove('password'); + usernamecontroller.text = info.getString('username') ?? ''; + emailcontroller.text = info.getString('email') ?? ''; + passwordcontroller.text = info.getString('password') ?? ''; + Navigator.of(context) + .pushReplacement(MaterialPageRoute(builder: (ctx) => MyLogin())); + } + } + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + backgroundColor: Colors.white, + title: Text( + 'پروفایل کاربر', + style: TextStyle( + fontWeight: FontWeight.w900, + fontSize: 21, + color: Colors.blue[200], + ), + ), + centerTitle: true, + actions: [ + IconButton( + icon: Icon( + Icons.arrow_right_alt, + size: 40, + color: Colors.blue[200], + ), + onPressed: () { + Navigator.push( + context, + MaterialPageRoute(builder: (ctx) => MyApp()), + ); + }, + ) + ], + ), + body: isLoading + ? CircularProgressIndicator() + : Center( + child: 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: username!, + obscureText: false, + ), + ), + 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: emailcontroller, + hintText: email!, + obscureText: false, + ), + ), + 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: passwordcontroller, + hintText: password!, + obscureText: true, + ), + ), + Container( + margin: EdgeInsets.only(top: 30, bottom: 30), + height: 10, + ), + SizedBox( + child: MyButton( + onTap: updateUser, + text: 'بروزرسانی', + ), + ), + SizedBox( + height: 10, + ), + Center( + child: TextButton( + onPressed: logout, child: Text(threeTitr!))) + ], + ), + ), + ); + } +} diff --git a/pubspec.yaml b/pubspec.yaml new file mode 100644 index 0000000..5540e34 --- /dev/null +++ b/pubspec.yaml @@ -0,0 +1,99 @@ +name: myapp +description: "A new Flutter project." +# The following line prevents the package from being accidentally published to +# pub.dev using `flutter pub publish`. This is preferred for private packages. +publish_to: 'none' # Remove this line if you wish to publish to pub.dev + +# The following defines the version and build number for your application. +# A version number is three numbers separated by dots, like 1.2.43 +# followed by an optional build number separated by a +. +# Both the version and the builder number may be overridden in flutter +# build by specifying --build-name and --build-number, respectively. +# In Android, build-name is used as versionName while build-number used as versionCode. +# Read more about Android versioning at https://developer.android.com/studio/publish/versioning +# In iOS, build-name is used as CFBundleShortVersionString while build-number is used as CFBundleVersion. +# Read more about iOS versioning at +# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html +# In Windows, build-name is used as the major, minor, and patch parts +# of the product and file versions while build-number is used as the build suffix. +version: 1.0.0+1 + +environment: + sdk: '>=3.2.2 <4.0.0' + +# Dependencies specify other packages that your package needs in order to work. +# To automatically upgrade your package dependencies to the latest versions +# consider running `flutter pub upgrade --major-versions`. Alternatively, +# dependencies can be manually updated by changing the version numbers below to +# the latest version available on pub.dev. To see which dependencies have newer +# versions available, run `flutter pub outdated`. +dependencies: + flutter: + sdk: flutter + + + # The following adds the Cupertino Icons font to your application. + # Use with the CupertinoIcons class for iOS style icons. + cupertino_icons: ^1.0.8 + google_nav_bar: ^5.0.6 + http: ^1.2.0 + shared_preferences: ^2.2.3 + convert: ^3.1.1 + translator: ^1.0.0 + share_plus: ^7.2.2 + email_validator: ^2.1.17 + just_audio: ^0.9.38 + flutter_svg: ^2.0.10+1 + +dev_dependencies: + flutter_test: + sdk: flutter + + # The "flutter_lints" package below contains a set of recommended lints to + # encourage good coding practices. The lint set provided by the package is + # activated in the `analysis_options.yaml` file located at the root of your + # package. See that file for information about deactivating specific lint + # rules and activating additional ones. + flutter_lints: ^2.0.0 + +# For information on the generic Dart part of this file, see the +# following page: https://dart.dev/tools/pub/pubspec + +# The following section is specific to Flutter packages. +flutter: + + # The following line ensures that the Material Icons font is + # included with your application, so that you can use the icons in + # the material Icons class. + uses-material-design: true + + # To add assets to your application, add an assets section, like this: + # assets: + # - images/a_dot_burr.jpeg + # - images/a_dot_ham.jpeg + + # An image asset can refer to one or more resolution-specific "variants", see + # https://flutter.dev/assets-and-images/#resolution-aware + + # For details regarding adding assets from package dependencies, see + # https://flutter.dev/assets-and-images/#from-packages + + # To add custom fonts to your application, add a fonts section here, + # in this "flutter" section. Each entry in this list should have a + # "family" key with the font family name, and a "fonts" key with a + # list giving the asset and other descriptors for the font. For + # example: + # fonts: + # - family: Schyler + # fonts: + # - asset: fonts/Schyler-Regular.ttf + # - asset: fonts/Schyler-Italic.ttf + # style: italic + # - family: Trajan Pro + # fonts: + # - asset: fonts/TrajanPro.ttf + # - asset: fonts/TrajanPro_Bold.ttf + # weight: 700 + # + # For details regarding fonts from package dependencies, + # see https://flutter.dev/custom-fonts/#from-packages