Last active
April 11, 2023 06:12
-
-
Save Vatsal596/9b2328e29fbb0ada122f4fdc02b1081d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import'package:flutter/material.dart'; | |
import 'main.dart'; | |
class Login extends StatefulWidget { | |
const Login({super.key, required this.title}); | |
final String title; | |
@override | |
State<Login> createState() => _LoginState(); | |
} | |
class _LoginState extends State<Login> { | |
TextEditingController UserName = TextEditingController(); | |
TextEditingController PassWord = TextEditingController(); | |
bool _validateUser = false; | |
bool _validatePass = false; | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text(widget.title), | |
), | |
body: Center( | |
child: Container( | |
width: 500, | |
height: 700, | |
decoration: BoxDecoration( | |
color: Colors.redAccent, | |
boxShadow: [ | |
BoxShadow(color: Colors.black54, spreadRadius: 3), | |
], | |
borderRadius: BorderRadius.circular(10)), | |
child: Column( | |
children: [ | |
SizedBox( | |
height: 80, | |
), | |
SizedBox( | |
height: 20, | |
), | |
Row( | |
children: [ | |
SizedBox( | |
width: 10, | |
), | |
Text( | |
"UserName:- ", | |
style: TextStyle(color: Colors.white, fontSize: 18), | |
), | |
SizedBox( | |
width: 10, | |
), | |
Expanded( | |
child: TextField( | |
controller: UserName, | |
decoration: InputDecoration( | |
errorText: | |
_validateUser ? 'Value Can\'t Be Empty' : null, | |
enabledBorder: const OutlineInputBorder( | |
borderSide: const BorderSide( | |
color: Colors.grey, width: 0.0), | |
), | |
fillColor: Colors.white, | |
border: OutlineInputBorder(), | |
hintText: 'Enter Your Username', | |
hintStyle: TextStyle(color: Colors.white)), | |
style: TextStyle(color: Colors.white), | |
), | |
), | |
SizedBox( | |
width: 20, | |
) | |
], | |
), | |
SizedBox( | |
height: 15, | |
), | |
Row( | |
children: [ | |
SizedBox( | |
width: 10, | |
), | |
Text( | |
"PassWord:- ", | |
style: TextStyle(color: Colors.white, fontSize: 18), | |
), | |
SizedBox( | |
width: 10, | |
), | |
Expanded( | |
child: TextField( | |
controller: PassWord, | |
decoration: InputDecoration( | |
errorText: | |
_validateUser ? 'Value Cant Be Empty' : null, | |
enabledBorder: const OutlineInputBorder( | |
borderSide: const BorderSide( | |
color: Colors.grey, width: 0.0), | |
), | |
fillColor: Colors.white, | |
border: OutlineInputBorder(), | |
hintText: 'Enter Your PassWord', | |
hintStyle: TextStyle(color: Colors.white)), | |
style: TextStyle(color: Colors.white), | |
), | |
), | |
SizedBox( | |
width: 20, | |
) | |
], | |
), | |
SizedBox( | |
height: 30, | |
), | |
ElevatedButton( | |
onPressed: () { | |
setState(() { | |
UserName.text.isEmpty | |
? _validateUser = true | |
: _validateUser = false; | |
PassWord.text.isEmpty | |
? _validatePass = true | |
: _validatePass = false; | |
}); | |
if (UserName.text.isNotEmpty && PassWord.text.isNotEmpty) { | |
showDialog( | |
context: context, | |
builder: (BuildContext context) => AlertDialog( | |
title: const Text('Login'), | |
content: new Column( | |
mainAxisSize: MainAxisSize.min, | |
crossAxisAlignment: CrossAxisAlignment.start, | |
children: <Widget>[ | |
Text("Login Successfully"), | |
], | |
), | |
actions: <Widget>[ | |
new ElevatedButton( | |
onPressed: () { | |
Navigator.of(context).pop(); | |
}, | |
child: const Text('Close'), | |
), | |
], | |
)); | |
} | |
}, | |
child: Text( | |
"Log IN", | |
style: TextStyle( | |
fontWeight: FontWeight.w800, color: Colors.redAccent), | |
), | |
style: ElevatedButton.styleFrom( | |
backgroundColor: Colors.white, | |
fixedSize: const Size(120, 50), | |
shape: RoundedRectangleBorder( | |
borderRadius: BorderRadius.circular(50))), | |
), | |
], | |
), | |
), | |
), | |
floatingActionButton: FloatingActionButton( | |
onPressed: () { | |
Navigator.push( | |
context, | |
MaterialPageRoute(builder: (context) => const DemoClass()), | |
); | |
}, | |
tooltip: 'Next Page', | |
child: const Icon(Icons.navigate_next_rounded), | |
), | |
); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
import 'package:flutter_application_5/SecondPage.dart'; | |
import 'package:flutter_application_5/SharedData.dart'; | |
import 'package:flutter_application_5/login.dart'; | |
import 'package:flutter_application_5/student.dart'; | |
void main() { | |
runApp(MaterialApp( | |
home: Login(title:"Login"), | |
)); | |
} | |
class DemoClass extends StatelessWidget { | |
const DemoClass({super.key}); | |
@override | |
Widget build(BuildContext context) { | |
return DefaultTabController( | |
length: 3, | |
child: Scaffold( | |
appBar: AppBar( | |
backgroundColor: Colors.red, | |
title: Text("TabDemo"), | |
bottom: TabBar(tabs: [ | |
Tab( | |
icon: Icon(Icons.add), | |
text: "Add", | |
), | |
Tab( | |
icon: Icon(Icons.home), | |
text: "Home", | |
), | |
Tab( | |
icon: Icon(Icons.view_agenda_outlined), | |
text: "View", | |
), | |
]), | |
), | |
body: TabBarView(children: [ | |
DemoTabPage1(), | |
DemoPage2(), | |
ViewPage(), | |
]), | |
), | |
); | |
} | |
} | |
class MyApp1 extends StatelessWidget { | |
MyApp1({Key? key}) : super(key: key); | |
TextEditingController txtName = new TextEditingController(); | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text("Demo"), | |
), | |
body: Column( | |
children: [ | |
TextField( | |
controller: txtName, | |
), | |
SizedBox( | |
height: 10, | |
), | |
ElevatedButton( | |
onPressed: () { | |
SharedData.stGlobal.add(txtName.text); | |
}, | |
child: Text("Save") | |
) | |
], | |
), | |
floatingActionButton: FloatingActionButton( | |
onPressed: () { | |
SharedData.name = txtName.text; | |
Navigator.push(context, MaterialPageRoute( | |
builder: (context) { | |
return SecondPage(); | |
}, | |
)); | |
}, | |
child: Icon(Icons.next_plan_outlined), | |
), | |
); | |
} | |
} | |
class DemoTabPage1 extends StatelessWidget { | |
DemoTabPage1({super.key}); | |
TextEditingController txtName = new TextEditingController(); | |
TextEditingController txtNo = new TextEditingController(); | |
TextEditingController txtMarks1 = new TextEditingController(); | |
TextEditingController txtMarks2 = new TextEditingController(); | |
@override | |
Widget build(BuildContext context) { | |
return Container( | |
child: Column( | |
children: [ | |
TextField( | |
controller: txtName, | |
decoration: InputDecoration(labelText: "Enter Name"), | |
), | |
TextField( | |
controller: txtNo, | |
decoration: InputDecoration(labelText: "Enter No"), | |
), | |
TextField( | |
controller: txtMarks1, | |
decoration: InputDecoration(labelText: "Enter Marks"), | |
), | |
TextField( | |
controller: txtMarks2, | |
decoration: InputDecoration(labelText: "Enter Marks2"), | |
), | |
ElevatedButton( | |
child: Text("Save"), | |
onPressed: () { | |
Student newStu = new Student(); | |
newStu.name = txtName.text; | |
newStu.no = txtNo.text; | |
newStu.marks1 = int.parse(txtMarks1.text); | |
newStu.marks2 = int.parse(txtMarks2.text); | |
SharedData.stStudent.add(newStu); | |
print(SharedData.stStudent.length); | |
}, | |
), | |
], | |
), | |
); | |
} | |
} | |
class DemoPage2 extends StatefulWidget { | |
const DemoPage2({Key? key}) : super(key: key); | |
@override | |
State<DemoPage2> createState() => DemoPage2State(); | |
} | |
class DemoPage2State extends State<DemoPage2> { | |
String str = ""; | |
TextEditingController txtNo = new TextEditingController(); | |
@override | |
Widget build(BuildContext context) { | |
return Container( | |
child: Column( | |
children: [ | |
TextField( | |
controller: txtNo, | |
decoration: InputDecoration(labelText: "Enter No"), | |
), | |
ElevatedButton( | |
onPressed: () { | |
for (int cntr = 0; | |
cntr < SharedData.stStudent.length; | |
cntr++) { | |
if (SharedData.stStudent[cntr].no == txtNo.text) { | |
print(SharedData.stStudent[cntr].name); | |
str = SharedData.stStudent[cntr].name; | |
SharedData.stStudent.removeAt(cntr); | |
} | |
} | |
setState(() {}); | |
}, | |
child: Text("Show Marks") | |
), | |
Text(str) | |
], | |
), | |
); | |
} | |
} | |
class ViewPage extends StatelessWidget { | |
const ViewPage({super.key}); | |
@override | |
Widget build(BuildContext context) { | |
return Container( | |
child: ListView.builder( | |
itemCount: SharedData.stStudent.length, | |
itemBuilder:(context, index) { | |
return ListTile( | |
onTap: () { | |
SharedData.selectedRecord = index; | |
Navigator.push(context, MaterialPageRoute( | |
builder: (context) { | |
return DetailView(); | |
}, | |
)); | |
}, | |
title: Text(SharedData.stStudent[index].name), | |
); | |
} , | |
), | |
); | |
} | |
} | |
class DetailView extends StatelessWidget { | |
const DetailView({Key? key}) : super(key: key); | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text("Detail View") | |
), | |
body: Column(children: [ | |
Text(SharedData.stStudent[SharedData.selectedRecord].name), | |
Text(SharedData.stStudent[SharedData.selectedRecord].no), | |
Text(SharedData.stStudent[SharedData.selectedRecord].marks1.toString()), | |
Text(SharedData.stStudent[SharedData.selectedRecord].marks2.toString()), | |
]), | |
); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
import 'package:flutter_application_5/SharedData.dart'; | |
class SecondPage extends StatelessWidget { | |
const SecondPage({super.key}); | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
backgroundColor: Colors.red, | |
appBar: AppBar( | |
title: Text("Second Page"), | |
), | |
body: ListView.builder( | |
itemCount: SharedData.stGlobal.length, | |
itemBuilder: (context, index) { | |
return ListTile( | |
title: ( | |
Text(SharedData.stGlobal[index]) | |
), | |
); | |
} , | |
), | |
); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Student{ | |
String name = ""; | |
String no = ""; | |
int marks1 = 0; | |
int marks2 = 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment