├── model.dart ├── main.dart ├── addpost.dart ├── home.dart ├── editpost.dart ├── StudentList.dart ├── teacher.dart ├── posts.dart ├── pubspec.yaml ├── student.dart ├── forgot.dart ├── login.dart └── register.dart /model.dart: -------------------------------------------------------------------------------- 1 | class UserModel { 2 | String? email; 3 | String? wrool; 4 | String? uid; 5 | 6 | // receiving data 7 | UserModel({this.uid, this.email, this.wrool}); 8 | factory UserModel.fromMap(map) { 9 | return UserModel( 10 | uid: map['uid'], 11 | email: map['email'], 12 | wrool: map['wrool'], 13 | ); 14 | } 15 | // sending data 16 | Map toMap() { 17 | return { 18 | 'uid': uid, 19 | 'email': email, 20 | 'wrool': wrool, 21 | }; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /main.dart: -------------------------------------------------------------------------------- 1 | import 'package:firebase_core/firebase_core.dart'; 2 | import 'package:flutter/material.dart'; 3 | 4 | import 'register.dart'; 5 | 6 | Future main() async { 7 | WidgetsFlutterBinding.ensureInitialized(); 8 | await Firebase.initializeApp(); 9 | runApp(MyApp()); 10 | } 11 | 12 | class MyApp extends StatefulWidget { 13 | @override 14 | _MyAppState createState() => _MyAppState(); 15 | } 16 | 17 | class _MyAppState extends State { 18 | @override 19 | Widget build(BuildContext context) { 20 | return MaterialApp( 21 | debugShowCheckedModeBanner: false, 22 | theme: ThemeData( 23 | primaryColor: Colors.blue[900], 24 | ), 25 | home: Register(), 26 | ); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /addpost.dart: -------------------------------------------------------------------------------- 1 | import 'posts.dart'; 2 | import 'package:cloud_firestore/cloud_firestore.dart'; 3 | import 'package:flutter/material.dart'; 4 | 5 | import 'main.dart'; 6 | 7 | class addnote extends StatelessWidget { 8 | TextEditingController title = TextEditingController(); 9 | 10 | CollectionReference ref = FirebaseFirestore.instance.collection('posts'); 11 | 12 | @override 13 | Widget build(BuildContext context) { 14 | return Scaffold( 15 | appBar: AppBar( 16 | actions: [ 17 | MaterialButton( 18 | onPressed: () { 19 | ref.add({ 20 | 'title': title.text, 21 | }).whenComplete(() { 22 | Navigator.pushReplacement( 23 | context, MaterialPageRoute(builder: (_) => posts())); 24 | }); 25 | }, 26 | child: Text( 27 | "save", 28 | ), 29 | ), 30 | ], 31 | ), 32 | body: Container( 33 | child: Column( 34 | children: [ 35 | Expanded( 36 | child: Container( 37 | decoration: BoxDecoration(border: Border.all()), 38 | child: TextField( 39 | controller: title, 40 | expands: true, 41 | maxLines: null, 42 | decoration: InputDecoration( 43 | hintText: 'title', 44 | ), 45 | ), 46 | ), 47 | ), 48 | SizedBox( 49 | height: 10, 50 | ), 51 | ], 52 | ), 53 | ), 54 | ); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /home.dart: -------------------------------------------------------------------------------- 1 | import 'package:cloud_firestore/cloud_firestore.dart'; 2 | import 'package:firebase_auth/firebase_auth.dart'; 3 | import 'package:flutter/material.dart'; 4 | 5 | import 'model.dart'; 6 | import 'student.dart'; 7 | import 'teacher.dart'; 8 | 9 | class HomePage extends StatefulWidget { 10 | @override 11 | _HomePageState createState() => _HomePageState(); 12 | } 13 | 14 | class _HomePageState extends State { 15 | _HomePageState(); 16 | @override 17 | Widget build(BuildContext context) { 18 | return contro(); 19 | } 20 | } 21 | 22 | class contro extends StatefulWidget { 23 | contro(); 24 | 25 | @override 26 | _controState createState() => _controState(); 27 | } 28 | 29 | class _controState extends State { 30 | _controState(); 31 | User? user = FirebaseAuth.instance.currentUser; 32 | UserModel loggedInUser = UserModel(); 33 | var rooll; 34 | var emaill; 35 | var id; 36 | @override 37 | void initState() { 38 | super.initState(); 39 | FirebaseFirestore.instance 40 | .collection("users") //.where('uid', isEqualTo: user!.uid) 41 | .doc(user!.uid) 42 | .get() 43 | .then((value) { 44 | this.loggedInUser = UserModel.fromMap(value.data()); 45 | }).whenComplete(() { 46 | CircularProgressIndicator(); 47 | setState(() { 48 | emaill = loggedInUser.email.toString(); 49 | rooll = loggedInUser.wrool.toString(); 50 | id = loggedInUser.uid.toString(); 51 | }); 52 | }); 53 | } 54 | 55 | routing() { 56 | if (rooll == 'Student') { 57 | return Student( 58 | id: id, 59 | ); 60 | } else { 61 | return Teacher( 62 | id: id, 63 | ); 64 | } 65 | } 66 | 67 | @override 68 | Widget build(BuildContext context) { 69 | CircularProgressIndicator(); 70 | return routing(); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /editpost.dart: -------------------------------------------------------------------------------- 1 | import 'posts.dart'; 2 | import 'package:cloud_firestore/cloud_firestore.dart'; 3 | 4 | import 'package:flutter/material.dart'; 5 | 6 | class editnote extends StatefulWidget { 7 | DocumentSnapshot docid; 8 | editnote({required this.docid}); 9 | 10 | @override 11 | _editnoteState createState() => _editnoteState(); 12 | } 13 | 14 | class _editnoteState extends State { 15 | TextEditingController title = TextEditingController(); 16 | 17 | @override 18 | void initState() { 19 | title = TextEditingController(text: widget.docid.get('title')); 20 | super.initState(); 21 | } 22 | 23 | @override 24 | Widget build(BuildContext context) { 25 | return Scaffold( 26 | appBar: AppBar( 27 | actions: [ 28 | MaterialButton( 29 | onPressed: () { 30 | widget.docid.reference.update({ 31 | 'title': title.text, 32 | }).whenComplete(() { 33 | Navigator.pushReplacement( 34 | context, MaterialPageRoute(builder: (_) => posts())); 35 | }); 36 | }, 37 | child: Text("save"), 38 | ), 39 | MaterialButton( 40 | onPressed: () { 41 | widget.docid.reference.delete().whenComplete(() { 42 | Navigator.pushReplacement( 43 | context, MaterialPageRoute(builder: (_) => posts())); 44 | }); 45 | }, 46 | child: Text("delete"), 47 | ), 48 | ], 49 | ), 50 | body: Container( 51 | child: Column( 52 | children: [ 53 | Expanded( 54 | child: Container( 55 | decoration: BoxDecoration(border: Border.all()), 56 | child: TextField( 57 | controller: title, 58 | expands: true, 59 | maxLines: null, 60 | decoration: InputDecoration( 61 | hintText: 'title', 62 | ), 63 | ), 64 | ), 65 | ), 66 | SizedBox( 67 | height: 10, 68 | ), 69 | ], 70 | ), 71 | ), 72 | ); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /StudentList.dart: -------------------------------------------------------------------------------- 1 | import 'package:cloud_firestore/cloud_firestore.dart'; 2 | import 'package:flutter/material.dart'; 3 | 4 | class studentList extends StatefulWidget { 5 | @override 6 | _studentListState createState() => _studentListState(); 7 | } 8 | 9 | class _studentListState extends State { 10 | final Stream _usersStream = FirebaseFirestore.instance 11 | .collection('users') 12 | .where('wrool', isEqualTo: 'Student') 13 | .snapshots(); 14 | @override 15 | Widget build(BuildContext context) { 16 | return Scaffold( 17 | appBar: AppBar( 18 | title: Text('Students'), 19 | ), 20 | body: StreamBuilder( 21 | stream: _usersStream, 22 | builder: (BuildContext context, AsyncSnapshot snapshot) { 23 | if (snapshot.hasError) { 24 | return Text("something is wrong"); 25 | } 26 | if (snapshot.connectionState == ConnectionState.waiting) { 27 | return Center( 28 | child: CircularProgressIndicator(), 29 | ); 30 | } 31 | 32 | return Container( 33 | decoration: BoxDecoration( 34 | borderRadius: BorderRadius.circular(12), 35 | ), 36 | child: ListView.builder( 37 | itemCount: snapshot.data!.docs.length, 38 | itemBuilder: (_, index) { 39 | return GestureDetector( 40 | onTap: () {}, 41 | child: Column( 42 | children: [ 43 | SizedBox( 44 | height: 4, 45 | ), 46 | Padding( 47 | padding: EdgeInsets.only( 48 | left: 3, 49 | right: 3, 50 | ), 51 | child: ListTile( 52 | shape: RoundedRectangleBorder( 53 | borderRadius: BorderRadius.circular(10), 54 | side: BorderSide( 55 | color: Colors.black, 56 | ), 57 | ), 58 | title: Text( 59 | snapshot.data!.docChanges[index].doc['email'], 60 | style: TextStyle( 61 | fontSize: 20, 62 | ), 63 | ), 64 | contentPadding: EdgeInsets.symmetric( 65 | vertical: 12, 66 | horizontal: 16, 67 | ), 68 | ), 69 | ), 70 | ], 71 | ), 72 | ); 73 | }, 74 | ), 75 | ); 76 | }, 77 | ), 78 | ); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /teacher.dart: -------------------------------------------------------------------------------- 1 | import 'StudentList.dart'; 2 | import 'posts.dart'; 3 | import 'package:cloud_firestore/cloud_firestore.dart'; 4 | import 'package:firebase_auth/firebase_auth.dart'; 5 | import 'package:flutter/material.dart'; 6 | import 'login.dart'; 7 | import 'model.dart'; 8 | 9 | class Teacher extends StatefulWidget { 10 | String id; 11 | Teacher({required this.id}); 12 | @override 13 | _TeacherState createState() => _TeacherState(id: id); 14 | } 15 | 16 | class _TeacherState extends State { 17 | String id; 18 | var rooll; 19 | var emaill; 20 | UserModel loggedInUser = UserModel(); 21 | 22 | _TeacherState({required this.id}); 23 | @override 24 | void initState() { 25 | super.initState(); 26 | FirebaseFirestore.instance 27 | .collection("users") //.where('uid', isEqualTo: user!.uid) 28 | .doc(id) 29 | .get() 30 | .then((value) { 31 | this.loggedInUser = UserModel.fromMap(value.data()); 32 | }).whenComplete(() { 33 | CircularProgressIndicator(); 34 | setState(() { 35 | emaill = loggedInUser.email.toString(); 36 | rooll = loggedInUser.wrool.toString(); 37 | id = loggedInUser.uid.toString(); 38 | }); 39 | }); 40 | } 41 | 42 | @override 43 | Widget build(BuildContext context) { 44 | return Scaffold( 45 | appBar: AppBar( 46 | title: Text( 47 | "Teacher", 48 | ), 49 | actions: [ 50 | IconButton( 51 | onPressed: () { 52 | logout(context); 53 | }, 54 | icon: Icon(Icons.logout), 55 | ), 56 | ], 57 | ), 58 | body: Center( 59 | child: Column( 60 | mainAxisAlignment: MainAxisAlignment.center, 61 | crossAxisAlignment: CrossAxisAlignment.center, 62 | children: [ 63 | MaterialButton( 64 | onPressed: () { 65 | Navigator.of(context).push( 66 | MaterialPageRoute( 67 | builder: (context) => studentList(), 68 | ), 69 | ); 70 | }, 71 | child: Text( 72 | "List of Student", 73 | style: TextStyle( 74 | color: Colors.white, 75 | fontSize: 20, 76 | ), 77 | ), 78 | color: Colors.indigo[900], 79 | ), 80 | MaterialButton( 81 | onPressed: () { 82 | Navigator.of(context).push( 83 | MaterialPageRoute( 84 | builder: (context) => posts(), 85 | ), 86 | ); 87 | }, 88 | child: Text( 89 | "Post", 90 | style: TextStyle( 91 | color: Colors.white, 92 | fontSize: 20, 93 | ), 94 | ), 95 | color: Colors.indigo[900], 96 | ), 97 | ], 98 | ), 99 | ), 100 | ); 101 | } 102 | 103 | Future logout(BuildContext context) async { 104 | CircularProgressIndicator(); 105 | await FirebaseAuth.instance.signOut(); 106 | 107 | Navigator.of(context).pushReplacement( 108 | MaterialPageRoute( 109 | builder: (context) => LoginPage(), 110 | ), 111 | ); 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /posts.dart: -------------------------------------------------------------------------------- 1 | import 'package:cloud_firestore/cloud_firestore.dart'; 2 | import 'package:flutter/material.dart'; 3 | 4 | import 'addpost.dart'; 5 | import 'editpost.dart'; 6 | 7 | class posts extends StatefulWidget { 8 | @override 9 | _postsState createState() => _postsState(); 10 | } 11 | 12 | class _postsState extends State { 13 | final Stream _usersStream = 14 | FirebaseFirestore.instance.collection('posts').snapshots(); 15 | @override 16 | Widget build(BuildContext context) { 17 | return Scaffold( 18 | floatingActionButton: FloatingActionButton( 19 | onPressed: () { 20 | Navigator.pushReplacement( 21 | context, MaterialPageRoute(builder: (_) => addnote())); 22 | }, 23 | child: Icon( 24 | Icons.add, 25 | ), 26 | ), 27 | appBar: AppBar( 28 | title: Text('Posts'), 29 | ), 30 | body: StreamBuilder( 31 | stream: _usersStream, 32 | builder: (BuildContext context, AsyncSnapshot snapshot) { 33 | if (snapshot.hasError) { 34 | return Text("something is wrong"); 35 | } 36 | if (snapshot.connectionState == ConnectionState.waiting) { 37 | return Center( 38 | child: CircularProgressIndicator(), 39 | ); 40 | } 41 | 42 | return Container( 43 | decoration: BoxDecoration( 44 | borderRadius: BorderRadius.circular(12), 45 | ), 46 | child: ListView.builder( 47 | itemCount: snapshot.data!.docs.length, 48 | itemBuilder: (_, index) { 49 | return GestureDetector( 50 | onTap: () { 51 | Navigator.pushReplacement( 52 | context, 53 | MaterialPageRoute( 54 | builder: (_) => 55 | editnote(docid: snapshot.data!.docs[index]), 56 | ), 57 | ); 58 | }, 59 | child: Column( 60 | children: [ 61 | SizedBox( 62 | height: 4, 63 | ), 64 | Padding( 65 | padding: EdgeInsets.only( 66 | left: 3, 67 | right: 3, 68 | ), 69 | child: ListTile( 70 | shape: RoundedRectangleBorder( 71 | borderRadius: BorderRadius.circular(10), 72 | side: BorderSide( 73 | color: Colors.black, 74 | ), 75 | ), 76 | title: Text( 77 | snapshot.data!.docChanges[index].doc['title'], 78 | style: TextStyle( 79 | fontSize: 20, 80 | ), 81 | ), 82 | contentPadding: EdgeInsets.symmetric( 83 | vertical: 12, 84 | horizontal: 16, 85 | ), 86 | ), 87 | ), 88 | ], 89 | ), 90 | ); 91 | }, 92 | ), 93 | ); 94 | }, 95 | ), 96 | ); 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: app23 2 | description: A new Flutter project. 3 | 4 | # The following line prevents the package from being accidentally published to 5 | # pub.dev using `flutter pub publish`. This is preferred for private packages. 6 | publish_to: 'none' # Remove this line if you wish to publish to pub.dev 7 | 8 | # The following defines the version and build number for your application. 9 | # A version number is three numbers separated by dots, like 1.2.43 10 | # followed by an optional build number separated by a +. 11 | # Both the version and the builder number may be overridden in flutter 12 | # build by specifying --build-name and --build-number, respectively. 13 | # In Android, build-name is used as versionName while build-number used as versionCode. 14 | # Read more about Android versioning at https://developer.android.com/studio/publish/versioning 15 | # In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion. 16 | # Read more about iOS versioning at 17 | # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html 18 | version: 1.0.0+1 19 | 20 | environment: 21 | sdk: ">=2.15.0 <3.0.0" 22 | 23 | # Dependencies specify other packages that your package needs in order to work. 24 | # To automatically upgrade your package dependencies to the latest versions 25 | # consider running `flutter pub upgrade --major-versions`. Alternatively, 26 | # dependencies can be manually updated by changing the version numbers below to 27 | # the latest version available on pub.dev. To see which dependencies have newer 28 | # versions available, run `flutter pub outdated`. 29 | dependencies: 30 | flutter: 31 | sdk: flutter 32 | 33 | 34 | # The following adds the Cupertino Icons font to your application. 35 | # Use with the CupertinoIcons class for iOS style icons. 36 | cupertino_icons: ^1.0.2 37 | firebase_auth: ^3.3.3 38 | firebase_core: ^1.10.5 39 | cloud_firestore: ^3.1.5 40 | 41 | 42 | dev_dependencies: 43 | flutter_test: 44 | sdk: flutter 45 | 46 | # The "flutter_lints" package below contains a set of recommended lints to 47 | # encourage good coding practices. The lint set provided by the package is 48 | # activated in the `analysis_options.yaml` file located at the root of your 49 | # package. See that file for information about deactivating specific lint 50 | # rules and activating additional ones. 51 | flutter_lints: ^1.0.0 52 | 53 | # For information on the generic Dart part of this file, see the 54 | # following page: https://dart.dev/tools/pub/pubspec 55 | 56 | # The following section is specific to Flutter. 57 | flutter: 58 | 59 | # The following line ensures that the Material Icons font is 60 | # included with your application, so that you can use the icons in 61 | # the material Icons class. 62 | uses-material-design: true 63 | 64 | # To add assets to your application, add an assets section, like this: 65 | # assets: 66 | # - images/a_dot_burr.jpeg 67 | # - images/a_dot_ham.jpeg 68 | 69 | # An image asset can refer to one or more resolution-specific "variants", see 70 | # https://flutter.dev/assets-and-images/#resolution-aware. 71 | 72 | # For details regarding adding assets from package dependencies, see 73 | # https://flutter.dev/assets-and-images/#from-packages 74 | 75 | # To add custom fonts to your application, add a fonts section here, 76 | # in this "flutter" section. Each entry in this list should have a 77 | # "family" key with the font family name, and a "fonts" key with a 78 | # list giving the asset and other descriptors for the font. For 79 | # example: 80 | # fonts: 81 | # - family: Schyler 82 | # fonts: 83 | # - asset: fonts/Schyler-Regular.ttf 84 | # - asset: fonts/Schyler-Italic.ttf 85 | # style: italic 86 | # - family: Trajan Pro 87 | # fonts: 88 | # - asset: fonts/TrajanPro.ttf 89 | # - asset: fonts/TrajanPro_Bold.ttf 90 | # weight: 700 91 | # 92 | # For details regarding fonts from package dependencies, 93 | # see https://flutter.dev/custom-fonts/#from-packages 94 | -------------------------------------------------------------------------------- /student.dart: -------------------------------------------------------------------------------- 1 | import 'package:cloud_firestore/cloud_firestore.dart'; 2 | import 'package:firebase_auth/firebase_auth.dart'; 3 | import 'package:flutter/material.dart'; 4 | 5 | import 'login.dart'; 6 | import 'model.dart'; 7 | 8 | class Student extends StatefulWidget { 9 | String id; 10 | Student({required this.id}); 11 | @override 12 | _StudentState createState() => _StudentState(id: id); 13 | } 14 | 15 | class _StudentState extends State { 16 | String id; 17 | var rooll; 18 | var emaill; 19 | UserModel loggedInUser = UserModel(); 20 | 21 | _StudentState({required this.id}); 22 | @override 23 | void initState() { 24 | super.initState(); 25 | FirebaseFirestore.instance 26 | .collection("users") //.where('uid', isEqualTo: user!.uid) 27 | .doc(id) 28 | .get() 29 | .then((value) { 30 | this.loggedInUser = UserModel.fromMap(value.data()); 31 | }).whenComplete(() { 32 | CircularProgressIndicator(); 33 | setState(() { 34 | emaill = loggedInUser.email.toString(); 35 | rooll = loggedInUser.wrool.toString(); 36 | id = loggedInUser.uid.toString(); 37 | }); 38 | }); 39 | } 40 | 41 | @override 42 | final Stream _usersStream = 43 | FirebaseFirestore.instance.collection('posts').snapshots(); 44 | Widget build(BuildContext context) { 45 | return Scaffold( 46 | appBar: AppBar( 47 | title: Text( 48 | "Student", 49 | ), 50 | actions: [ 51 | IconButton( 52 | onPressed: () { 53 | logout(context); 54 | }, 55 | icon: Icon(Icons.logout), 56 | ), 57 | ], 58 | ), 59 | body: StreamBuilder( 60 | stream: _usersStream, 61 | builder: (BuildContext context, AsyncSnapshot snapshot) { 62 | if (snapshot.hasError) { 63 | return Text("something is wrong"); 64 | } 65 | if (snapshot.connectionState == ConnectionState.waiting) { 66 | return Center( 67 | child: CircularProgressIndicator(), 68 | ); 69 | } 70 | 71 | return Container( 72 | decoration: BoxDecoration( 73 | borderRadius: BorderRadius.circular(12), 74 | ), 75 | child: ListView.builder( 76 | itemCount: snapshot.data!.docs.length, 77 | itemBuilder: (_, index) { 78 | return GestureDetector( 79 | onTap: () {}, 80 | child: Column( 81 | children: [ 82 | SizedBox( 83 | height: 4, 84 | ), 85 | Padding( 86 | padding: EdgeInsets.only( 87 | left: 3, 88 | right: 3, 89 | ), 90 | child: ListTile( 91 | shape: RoundedRectangleBorder( 92 | borderRadius: BorderRadius.circular(10), 93 | side: BorderSide( 94 | color: Colors.black, 95 | ), 96 | ), 97 | title: Text( 98 | snapshot.data!.docChanges[index].doc['title'], 99 | style: TextStyle( 100 | fontSize: 20, 101 | ), 102 | ), 103 | contentPadding: EdgeInsets.symmetric( 104 | vertical: 12, 105 | horizontal: 16, 106 | ), 107 | ), 108 | ), 109 | ], 110 | ), 111 | ); 112 | }, 113 | ), 114 | ); 115 | }, 116 | ), 117 | ); 118 | } 119 | 120 | Future logout(BuildContext context) async { 121 | CircularProgressIndicator(); 122 | await FirebaseAuth.instance.signOut(); 123 | 124 | Navigator.of(context).pushReplacement( 125 | MaterialPageRoute( 126 | builder: (context) => LoginPage(), 127 | ), 128 | ); 129 | } 130 | } 131 | -------------------------------------------------------------------------------- /forgot.dart: -------------------------------------------------------------------------------- 1 | import 'package:firebase_auth/firebase_auth.dart'; 2 | import 'package:flutter/material.dart'; 3 | 4 | import 'login.dart'; 5 | 6 | class Forgotpass extends StatefulWidget { 7 | const Forgotpass({Key? key}) : super(key: key); 8 | 9 | @override 10 | _ForgotpassState createState() => _ForgotpassState(); 11 | } 12 | 13 | class _ForgotpassState extends State { 14 | // bool showProgress = false; 15 | bool visible = false; 16 | final _auth = FirebaseAuth.instance; 17 | final _formkey = GlobalKey(); 18 | final TextEditingController emailController = new TextEditingController(); 19 | @override 20 | Widget build(BuildContext context) { 21 | return Scaffold( 22 | body: SingleChildScrollView( 23 | child: Center( 24 | child: Column( 25 | mainAxisAlignment: MainAxisAlignment.center, 26 | crossAxisAlignment: CrossAxisAlignment.center, 27 | children: [ 28 | Container( 29 | color: Colors.blue[900], 30 | width: MediaQuery.of(context).size.width, 31 | height: MediaQuery.of(context).size.height * 0.70, 32 | child: Center( 33 | child: Container( 34 | margin: EdgeInsets.all(12), 35 | child: Form( 36 | key: _formkey, 37 | child: Column( 38 | mainAxisAlignment: MainAxisAlignment.center, 39 | crossAxisAlignment: CrossAxisAlignment.center, 40 | children: [ 41 | Text( 42 | "Forgot\n" 43 | "Password", 44 | style: TextStyle( 45 | fontWeight: FontWeight.bold, 46 | color: Colors.white, 47 | fontSize: 50, 48 | ), 49 | ), 50 | Text( 51 | "Dont worry...", 52 | style: TextStyle( 53 | fontWeight: FontWeight.bold, 54 | color: Colors.white, 55 | fontSize: 20, 56 | ), 57 | ), 58 | SizedBox( 59 | height: 30, 60 | ), 61 | SizedBox( 62 | height: 10, 63 | ), 64 | TextFormField( 65 | controller: emailController, 66 | decoration: InputDecoration( 67 | filled: true, 68 | fillColor: Colors.white, 69 | hintText: 'Email', 70 | enabled: true, 71 | contentPadding: const EdgeInsets.only( 72 | left: 14.0, bottom: 8.0, top: 8.0), 73 | focusedBorder: OutlineInputBorder( 74 | borderSide: new BorderSide(color: Colors.white), 75 | borderRadius: new BorderRadius.circular(20), 76 | ), 77 | enabledBorder: UnderlineInputBorder( 78 | borderSide: new BorderSide(color: Colors.white), 79 | borderRadius: new BorderRadius.circular(20), 80 | ), 81 | ), 82 | textInputAction: TextInputAction.done, 83 | validator: (value) { 84 | if (value!.length == 0) { 85 | return "Email cannot be empty"; 86 | } 87 | if (!RegExp( 88 | "^[a-zA-Z0-9+_.-]+@[a-zA-Z0-9.-]+.[a-z]") 89 | .hasMatch(value)) { 90 | return ("Please enter a valid email"); 91 | } else { 92 | return null; 93 | } 94 | }, 95 | onSaved: (value) { 96 | // emailController.text = value!; 97 | }, 98 | keyboardType: TextInputType.emailAddress, 99 | ), 100 | SizedBox( 101 | height: 30, 102 | ), 103 | Row( 104 | mainAxisAlignment: MainAxisAlignment.spaceEvenly, 105 | crossAxisAlignment: CrossAxisAlignment.end, 106 | children: [ 107 | MaterialButton( 108 | shape: RoundedRectangleBorder( 109 | borderRadius: BorderRadius.all( 110 | Radius.circular(20.0))), 111 | elevation: 5.0, 112 | height: 40, 113 | onPressed: () { 114 | Navigator.pushReplacement( 115 | context, 116 | MaterialPageRoute( 117 | builder: (context) => LoginPage())); 118 | }, 119 | child: Text( 120 | "Login", 121 | style: TextStyle( 122 | fontSize: 20, 123 | ), 124 | ), 125 | color: Colors.white, 126 | ), 127 | MaterialButton( 128 | shape: RoundedRectangleBorder( 129 | borderRadius: BorderRadius.all( 130 | Radius.circular(20.0))), 131 | elevation: 5.0, 132 | height: 40, 133 | onPressed: () { 134 | Forgotpassss(emailController.text); 135 | setState(() { 136 | visible = true; 137 | }); 138 | }, 139 | child: Text( 140 | "Ok", 141 | style: TextStyle( 142 | fontSize: 20, 143 | ), 144 | ), 145 | color: Colors.white, 146 | ), 147 | ], 148 | ), 149 | SizedBox( 150 | height: 10, 151 | ), 152 | Visibility( 153 | maintainSize: true, 154 | maintainAnimation: true, 155 | maintainState: true, 156 | visible: visible, 157 | child: Container( 158 | child: CircularProgressIndicator( 159 | color: Colors.white, 160 | ))), 161 | ], 162 | ), 163 | ), 164 | ), 165 | ), 166 | ), 167 | Container( 168 | color: Colors.white, 169 | width: MediaQuery.of(context).size.width, 170 | child: Center( 171 | child: Column( 172 | mainAxisAlignment: MainAxisAlignment.center, 173 | crossAxisAlignment: CrossAxisAlignment.center, 174 | children: [ 175 | SizedBox( 176 | height: 10, 177 | ), 178 | SizedBox( 179 | height: 40, 180 | ), 181 | Text( 182 | "Made by", 183 | style: TextStyle( 184 | fontWeight: FontWeight.bold, 185 | fontSize: 20, 186 | ), 187 | ), 188 | SizedBox( 189 | height: 5, 190 | ), 191 | Text( 192 | "WEBFUN", 193 | style: TextStyle( 194 | fontWeight: FontWeight.bold, 195 | fontSize: 30, 196 | color: Colors.yellowAccent[400], 197 | ), 198 | ), 199 | ], 200 | ), 201 | ), 202 | ), 203 | ], 204 | ), 205 | ), 206 | ), 207 | ); 208 | } 209 | 210 | void Forgotpassss(String email) async { 211 | if (_formkey.currentState!.validate()) { 212 | await _auth 213 | .sendPasswordResetEmail(email: email) 214 | .then((uid) => { 215 | Navigator.of(context).pushReplacement( 216 | MaterialPageRoute(builder: (context) => LoginPage())) 217 | }) 218 | .catchError((e) {}); 219 | } 220 | } 221 | } 222 | -------------------------------------------------------------------------------- /login.dart: -------------------------------------------------------------------------------- 1 | import 'package:firebase_auth/firebase_auth.dart'; 2 | import 'package:flutter/material.dart'; 3 | import 'forgot.dart'; 4 | import 'home.dart'; 5 | import 'register.dart'; 6 | 7 | class LoginPage extends StatefulWidget { 8 | @override 9 | _LoginPageState createState() => _LoginPageState(); 10 | } 11 | 12 | class _LoginPageState extends State { 13 | bool _isObscure3 = true; 14 | bool visible = false; 15 | final _formkey = GlobalKey(); 16 | final TextEditingController emailController = new TextEditingController(); 17 | final TextEditingController passwordController = new TextEditingController(); 18 | 19 | final _auth = FirebaseAuth.instance; 20 | @override 21 | Widget build(BuildContext context) { 22 | return Scaffold( 23 | body: SingleChildScrollView( 24 | child: Column( 25 | children: [ 26 | Container( 27 | color: Colors.orangeAccent[700], 28 | width: MediaQuery.of(context).size.width, 29 | height: MediaQuery.of(context).size.height * 0.70, 30 | child: Center( 31 | child: Container( 32 | margin: EdgeInsets.all(12), 33 | child: Form( 34 | key: _formkey, 35 | child: Column( 36 | mainAxisAlignment: MainAxisAlignment.center, 37 | crossAxisAlignment: CrossAxisAlignment.center, 38 | children: [ 39 | SizedBox( 40 | height: 30, 41 | ), 42 | Text( 43 | "Login", 44 | style: TextStyle( 45 | fontWeight: FontWeight.bold, 46 | color: Colors.white, 47 | fontSize: 40, 48 | ), 49 | ), 50 | SizedBox( 51 | height: 20, 52 | ), 53 | TextFormField( 54 | controller: emailController, 55 | decoration: InputDecoration( 56 | filled: true, 57 | fillColor: Colors.white, 58 | hintText: 'Email', 59 | enabled: true, 60 | contentPadding: const EdgeInsets.only( 61 | left: 14.0, bottom: 8.0, top: 8.0), 62 | focusedBorder: OutlineInputBorder( 63 | borderSide: new BorderSide(color: Colors.white), 64 | borderRadius: new BorderRadius.circular(10), 65 | ), 66 | enabledBorder: UnderlineInputBorder( 67 | borderSide: new BorderSide(color: Colors.white), 68 | borderRadius: new BorderRadius.circular(10), 69 | ), 70 | ), 71 | validator: (value) { 72 | if (value!.length == 0) { 73 | return "Email cannot be empty"; 74 | } 75 | if (!RegExp( 76 | "^[a-zA-Z0-9+_.-]+@[a-zA-Z0-9.-]+.[a-z]") 77 | .hasMatch(value)) { 78 | return ("Please enter a valid email"); 79 | } else { 80 | return null; 81 | } 82 | }, 83 | onSaved: (value) { 84 | emailController.text = value!; 85 | }, 86 | keyboardType: TextInputType.emailAddress, 87 | ), 88 | SizedBox( 89 | height: 20, 90 | ), 91 | TextFormField( 92 | controller: passwordController, 93 | obscureText: _isObscure3, 94 | decoration: InputDecoration( 95 | suffixIcon: IconButton( 96 | icon: Icon(_isObscure3 97 | ? Icons.visibility 98 | : Icons.visibility_off), 99 | onPressed: () { 100 | setState(() { 101 | _isObscure3 = !_isObscure3; 102 | }); 103 | }), 104 | filled: true, 105 | fillColor: Colors.white, 106 | hintText: 'Password', 107 | enabled: true, 108 | contentPadding: const EdgeInsets.only( 109 | left: 14.0, bottom: 8.0, top: 15.0), 110 | focusedBorder: OutlineInputBorder( 111 | borderSide: new BorderSide(color: Colors.white), 112 | borderRadius: new BorderRadius.circular(10), 113 | ), 114 | enabledBorder: UnderlineInputBorder( 115 | borderSide: new BorderSide(color: Colors.white), 116 | borderRadius: new BorderRadius.circular(10), 117 | ), 118 | ), 119 | validator: (value) { 120 | RegExp regex = new RegExp(r'^.{6,}$'); 121 | if (value!.isEmpty) { 122 | return "Password cannot be empty"; 123 | } 124 | if (!regex.hasMatch(value)) { 125 | return ("please enter valid password min. 6 character"); 126 | } else { 127 | return null; 128 | } 129 | }, 130 | onSaved: (value) { 131 | passwordController.text = value!; 132 | }, 133 | keyboardType: TextInputType.emailAddress, 134 | ), 135 | RaisedButton( 136 | color: Colors.orange[900], 137 | textColor: Colors.white, 138 | shape: RoundedRectangleBorder( 139 | // side: BorderSide(color: Colors.black, width: 1), 140 | ), 141 | onPressed: () { 142 | Navigator.of(context).pushReplacement( 143 | MaterialPageRoute( 144 | builder: (context) => Forgotpass(), 145 | ), 146 | ); 147 | }, 148 | child: Text( 149 | "Forgot Password ....", 150 | style: TextStyle( 151 | color: Colors.white, 152 | fontSize: 18, 153 | decoration: TextDecoration.underline, 154 | ), 155 | ), 156 | ), 157 | SizedBox( 158 | height: 20, 159 | ), 160 | MaterialButton( 161 | shape: RoundedRectangleBorder( 162 | borderRadius: 163 | BorderRadius.all(Radius.circular(20.0))), 164 | elevation: 5.0, 165 | height: 40, 166 | onPressed: () { 167 | setState(() { 168 | visible = true; 169 | }); 170 | signIn( 171 | emailController.text, passwordController.text); 172 | }, 173 | child: Text( 174 | "Login", 175 | style: TextStyle( 176 | fontSize: 20, 177 | ), 178 | ), 179 | color: Colors.white, 180 | ), 181 | SizedBox( 182 | height: 10, 183 | ), 184 | Visibility( 185 | maintainSize: true, 186 | maintainAnimation: true, 187 | maintainState: true, 188 | visible: visible, 189 | child: Container( 190 | child: CircularProgressIndicator( 191 | color: Colors.white, 192 | ))), 193 | ], 194 | ), 195 | ), 196 | ), 197 | ), 198 | ), 199 | Container( 200 | color: Colors.white, 201 | width: MediaQuery.of(context).size.width, 202 | child: Center( 203 | child: Column( 204 | mainAxisAlignment: MainAxisAlignment.center, 205 | crossAxisAlignment: CrossAxisAlignment.center, 206 | children: [ 207 | SizedBox( 208 | height: 20, 209 | ), 210 | MaterialButton( 211 | shape: RoundedRectangleBorder( 212 | borderRadius: BorderRadius.all( 213 | Radius.circular(20.0), 214 | ), 215 | ), 216 | elevation: 5.0, 217 | height: 40, 218 | onPressed: () { 219 | Navigator.pushReplacement( 220 | context, 221 | MaterialPageRoute( 222 | builder: (context) => Register(), 223 | ), 224 | ); 225 | }, 226 | color: Colors.blue[900], 227 | child: Text( 228 | "Register Now", 229 | style: TextStyle( 230 | color: Colors.white, 231 | fontSize: 20, 232 | ), 233 | ), 234 | ), 235 | SizedBox( 236 | height: 15, 237 | ), 238 | Text( 239 | "Made by", 240 | style: TextStyle( 241 | fontWeight: FontWeight.bold, 242 | fontSize: 40, 243 | ), 244 | ), 245 | SizedBox( 246 | height: 5, 247 | ), 248 | Row( 249 | mainAxisAlignment: MainAxisAlignment.center, 250 | children: [ 251 | Text( 252 | "WEB", 253 | style: TextStyle( 254 | fontWeight: FontWeight.bold, 255 | fontSize: 30, 256 | color: Colors.blue[900], 257 | ), 258 | ), 259 | Text( 260 | "FUN", 261 | style: TextStyle( 262 | fontWeight: FontWeight.bold, 263 | fontSize: 30, 264 | color: Colors.yellowAccent[400], 265 | ), 266 | ), 267 | ], 268 | ), 269 | ], 270 | ), 271 | ), 272 | ), 273 | ], 274 | ), 275 | ), 276 | ); 277 | } 278 | 279 | void signIn(String email, String password) async { 280 | if (_formkey.currentState!.validate()) { 281 | try { 282 | UserCredential userCredential = 283 | await FirebaseAuth.instance.signInWithEmailAndPassword( 284 | email: email, 285 | password: password, 286 | ); 287 | Navigator.pushReplacement( 288 | context, 289 | MaterialPageRoute( 290 | builder: (context) => HomePage(), 291 | ), 292 | ); 293 | } on FirebaseAuthException catch (e) { 294 | if (e.code == 'user-not-found') { 295 | print('No user found for that email.'); 296 | } else if (e.code == 'wrong-password') { 297 | print('Wrong password provided for that user.'); 298 | } 299 | } 300 | } 301 | } 302 | } 303 | -------------------------------------------------------------------------------- /register.dart: -------------------------------------------------------------------------------- 1 | import 'dart:io'; 2 | import 'package:cloud_firestore/cloud_firestore.dart'; 3 | import 'package:firebase_auth/firebase_auth.dart'; 4 | import 'package:flutter/material.dart'; 5 | import 'login.dart'; 6 | import 'model.dart'; 7 | 8 | class Register extends StatefulWidget { 9 | @override 10 | _RegisterState createState() => _RegisterState(); 11 | } 12 | 13 | class _RegisterState extends State { 14 | _RegisterState(); 15 | 16 | bool showProgress = false; 17 | bool visible = false; 18 | 19 | final _formkey = GlobalKey(); 20 | final _auth = FirebaseAuth.instance; 21 | CollectionReference ref = FirebaseFirestore.instance.collection('users'); 22 | final TextEditingController passwordController = new TextEditingController(); 23 | final TextEditingController confirmpassController = 24 | new TextEditingController(); 25 | final TextEditingController name = new TextEditingController(); 26 | final TextEditingController emailController = new TextEditingController(); 27 | final TextEditingController mobile = new TextEditingController(); 28 | bool _isObscure = true; 29 | bool _isObscure2 = true; 30 | File? file; 31 | var options = [ 32 | 'Student', 33 | 'Teacher', 34 | ]; 35 | var _currentItemSelected = "Student"; 36 | var rool = "Student"; 37 | 38 | @override 39 | Widget build(BuildContext context) { 40 | return Scaffold( 41 | backgroundColor: Colors.orange[900], 42 | body: SingleChildScrollView( 43 | child: Column( 44 | children: [ 45 | Container( 46 | color: Colors.orangeAccent[700], 47 | width: MediaQuery.of(context).size.width, 48 | height: MediaQuery.of(context).size.height, 49 | child: SingleChildScrollView( 50 | child: Container( 51 | margin: EdgeInsets.all(12), 52 | child: Form( 53 | key: _formkey, 54 | child: Column( 55 | mainAxisAlignment: MainAxisAlignment.center, 56 | crossAxisAlignment: CrossAxisAlignment.center, 57 | children: [ 58 | SizedBox( 59 | height: 80, 60 | ), 61 | Text( 62 | "Register Now", 63 | style: TextStyle( 64 | fontWeight: FontWeight.bold, 65 | color: Colors.white, 66 | fontSize: 40, 67 | ), 68 | ), 69 | SizedBox( 70 | height: 10, 71 | ), 72 | SizedBox( 73 | height: 50, 74 | ), 75 | TextFormField( 76 | controller: emailController, 77 | decoration: InputDecoration( 78 | filled: true, 79 | fillColor: Colors.white, 80 | hintText: 'Email', 81 | enabled: true, 82 | contentPadding: const EdgeInsets.only( 83 | left: 14.0, bottom: 8.0, top: 8.0), 84 | focusedBorder: OutlineInputBorder( 85 | borderSide: new BorderSide(color: Colors.white), 86 | borderRadius: new BorderRadius.circular(20), 87 | ), 88 | enabledBorder: UnderlineInputBorder( 89 | borderSide: new BorderSide(color: Colors.white), 90 | borderRadius: new BorderRadius.circular(20), 91 | ), 92 | ), 93 | validator: (value) { 94 | if (value!.length == 0) { 95 | return "Email cannot be empty"; 96 | } 97 | if (!RegExp( 98 | "^[a-zA-Z0-9+_.-]+@[a-zA-Z0-9.-]+.[a-z]") 99 | .hasMatch(value)) { 100 | return ("Please enter a valid email"); 101 | } else { 102 | return null; 103 | } 104 | }, 105 | onChanged: (value) {}, 106 | keyboardType: TextInputType.emailAddress, 107 | ), 108 | SizedBox( 109 | height: 20, 110 | ), 111 | TextFormField( 112 | obscureText: _isObscure, 113 | controller: passwordController, 114 | decoration: InputDecoration( 115 | suffixIcon: IconButton( 116 | icon: Icon(_isObscure 117 | ? Icons.visibility_off 118 | : Icons.visibility), 119 | onPressed: () { 120 | setState(() { 121 | _isObscure = !_isObscure; 122 | }); 123 | }), 124 | filled: true, 125 | fillColor: Colors.white, 126 | hintText: 'Password', 127 | enabled: true, 128 | contentPadding: const EdgeInsets.only( 129 | left: 14.0, bottom: 8.0, top: 15.0), 130 | focusedBorder: OutlineInputBorder( 131 | borderSide: new BorderSide(color: Colors.white), 132 | borderRadius: new BorderRadius.circular(20), 133 | ), 134 | enabledBorder: UnderlineInputBorder( 135 | borderSide: new BorderSide(color: Colors.white), 136 | borderRadius: new BorderRadius.circular(20), 137 | ), 138 | ), 139 | validator: (value) { 140 | RegExp regex = new RegExp(r'^.{6,}$'); 141 | if (value!.isEmpty) { 142 | return "Password cannot be empty"; 143 | } 144 | if (!regex.hasMatch(value)) { 145 | return ("please enter valid password min. 6 character"); 146 | } else { 147 | return null; 148 | } 149 | }, 150 | onChanged: (value) {}, 151 | ), 152 | SizedBox( 153 | height: 20, 154 | ), 155 | TextFormField( 156 | obscureText: _isObscure2, 157 | controller: confirmpassController, 158 | decoration: InputDecoration( 159 | suffixIcon: IconButton( 160 | icon: Icon(_isObscure2 161 | ? Icons.visibility_off 162 | : Icons.visibility), 163 | onPressed: () { 164 | setState(() { 165 | _isObscure2 = !_isObscure2; 166 | }); 167 | }), 168 | filled: true, 169 | fillColor: Colors.white, 170 | hintText: 'Confirm Password', 171 | enabled: true, 172 | contentPadding: const EdgeInsets.only( 173 | left: 14.0, bottom: 8.0, top: 15.0), 174 | focusedBorder: OutlineInputBorder( 175 | borderSide: new BorderSide(color: Colors.white), 176 | borderRadius: new BorderRadius.circular(20), 177 | ), 178 | enabledBorder: UnderlineInputBorder( 179 | borderSide: new BorderSide(color: Colors.white), 180 | borderRadius: new BorderRadius.circular(20), 181 | ), 182 | ), 183 | validator: (value) { 184 | if (confirmpassController.text != 185 | passwordController.text) { 186 | return "Password did not match"; 187 | } else { 188 | return null; 189 | } 190 | }, 191 | onChanged: (value) {}, 192 | ), 193 | SizedBox( 194 | height: 20, 195 | ), 196 | Row( 197 | mainAxisAlignment: MainAxisAlignment.center, 198 | children: [ 199 | Text( 200 | "Rool : ", 201 | style: TextStyle( 202 | fontSize: 20, 203 | fontWeight: FontWeight.bold, 204 | color: Colors.white, 205 | ), 206 | ), 207 | DropdownButton( 208 | dropdownColor: Colors.blue[900], 209 | isDense: true, 210 | isExpanded: false, 211 | iconEnabledColor: Colors.white, 212 | focusColor: Colors.white, 213 | items: options.map((String dropDownStringItem) { 214 | return DropdownMenuItem( 215 | value: dropDownStringItem, 216 | child: Text( 217 | dropDownStringItem, 218 | style: TextStyle( 219 | color: Colors.white, 220 | fontWeight: FontWeight.bold, 221 | fontSize: 20, 222 | ), 223 | ), 224 | ); 225 | }).toList(), 226 | onChanged: (newValueSelected) { 227 | setState(() { 228 | _currentItemSelected = newValueSelected!; 229 | rool = newValueSelected; 230 | }); 231 | }, 232 | value: _currentItemSelected, 233 | ), 234 | ], 235 | ), 236 | SizedBox( 237 | height: 20, 238 | ), 239 | Row( 240 | mainAxisAlignment: MainAxisAlignment.spaceEvenly, 241 | crossAxisAlignment: CrossAxisAlignment.end, 242 | children: [ 243 | MaterialButton( 244 | shape: RoundedRectangleBorder( 245 | borderRadius: 246 | BorderRadius.all(Radius.circular(20.0))), 247 | elevation: 5.0, 248 | height: 40, 249 | onPressed: () { 250 | CircularProgressIndicator(); 251 | Navigator.push( 252 | context, 253 | MaterialPageRoute( 254 | builder: (context) => LoginPage(), 255 | ), 256 | ); 257 | }, 258 | child: Text( 259 | "Login", 260 | style: TextStyle( 261 | fontSize: 20, 262 | ), 263 | ), 264 | color: Colors.white, 265 | ), 266 | MaterialButton( 267 | shape: RoundedRectangleBorder( 268 | borderRadius: 269 | BorderRadius.all(Radius.circular(20.0))), 270 | elevation: 5.0, 271 | height: 40, 272 | onPressed: () { 273 | setState(() { 274 | showProgress = true; 275 | }); 276 | signUp(emailController.text, 277 | passwordController.text, rool); 278 | }, 279 | child: Text( 280 | "Register", 281 | style: TextStyle( 282 | fontSize: 20, 283 | ), 284 | ), 285 | color: Colors.white, 286 | ), 287 | ], 288 | ), 289 | SizedBox( 290 | height: 20, 291 | ), 292 | Text( 293 | "WEBFUN", 294 | style: TextStyle( 295 | fontWeight: FontWeight.bold, 296 | fontSize: 30, 297 | color: Colors.yellowAccent[400], 298 | ), 299 | ), 300 | ], 301 | ), 302 | ), 303 | ), 304 | ), 305 | ), 306 | ], 307 | ), 308 | ), 309 | ); 310 | } 311 | 312 | void signUp(String email, String password, String rool) async { 313 | CircularProgressIndicator(); 314 | if (_formkey.currentState!.validate()) { 315 | await _auth 316 | .createUserWithEmailAndPassword(email: email, password: password) 317 | .then((value) => {postDetailsToFirestore(email, rool)}) 318 | .catchError((e) {}); 319 | } 320 | } 321 | 322 | postDetailsToFirestore(String email, String rool) async { 323 | FirebaseFirestore firebaseFirestore = FirebaseFirestore.instance; 324 | User? user = _auth.currentUser; 325 | UserModel userModel = UserModel(); 326 | userModel.email = email; 327 | userModel.uid = user!.uid; 328 | userModel.wrool = rool; 329 | await firebaseFirestore 330 | .collection("users") 331 | .doc(user.uid) 332 | .set(userModel.toMap()); 333 | 334 | Navigator.pushReplacement( 335 | context, MaterialPageRoute(builder: (context) => LoginPage())); 336 | } 337 | } 338 | --------------------------------------------------------------------------------