Skip to content

Instantly share code, notes, and snippets.

@Vatsal596
Created March 28, 2023 18:28
Show Gist options
  • Save Vatsal596/bd5ad2cd02d190b47b282ccf3dfdb094 to your computer and use it in GitHub Desktop.
Save Vatsal596/bd5ad2cd02d190b47b282ccf3dfdb094 to your computer and use it in GitHub Desktop.
import 'package:flutter/material.dart';
import 'dart:math';
import 'nextPage.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Set-3',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'SET-3'),
debugShowCheckedModeBanner: false,
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
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.blueAccent,
boxShadow: [
BoxShadow(color: Colors.black54, spreadRadius: 3),
],
borderRadius: BorderRadius.circular(10)),
child: Column(
children: [
SizedBox(
height: 80,
),
Container(
width: 120,
height: 120,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(50),
color: Colors.white38,
image: DecorationImage(
fit: BoxFit.cover,
image: NetworkImage(
"https://cdn.pixabay.com/photo/2021/03/02/17/26/pixel-6063246_1280.png"))),
),
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(
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),
errorText:
_validatePass ? 'Value Can\'t Be Empty' : null),
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.blueAccent),
),
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 newPage()),
);
},
tooltip: 'Next Page',
child: const Icon(Icons.navigate_next_rounded),
),
);
}
}
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
class newPage extends StatefulWidget {
const newPage({super.key});
@override
State<newPage> createState() => _newPageState();
}
class _newPageState extends State<newPage> {
TextEditingController price = TextEditingController();
TextEditingController name = TextEditingController();
TextEditingController seachtext = TextEditingController();
List Mobiles = [];
bool isSearch = false;
List searched = [];
void searchWindow(int number) {
setState(() {
for (int i = 0; i < Mobiles.length; i++) {
if (Mobiles[i]['Price'] <= number) {
searched.add(Mobiles[i]);
}
}
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Mobile Phones"),
),
body: Row(
children: [
SizedBox(
width: 90,
),
Expanded(
child: Center(
child: Container(
width: 500,
height: 600,
decoration: BoxDecoration(
color: Colors.blueAccent,
boxShadow: [
BoxShadow(color: Colors.black54, spreadRadius: 3),
],
borderRadius: BorderRadius.circular(10)),
child: Column(
children: [
SizedBox(
height: 100,
),
Row(
children: [
SizedBox(
width: 20,
),
Text("Enter Name:- ",
style:
TextStyle(color: Colors.white, fontSize: 18)),
SizedBox(
width: 20,
),
Expanded(
child: TextField(
controller: name,
cursorColor: Colors.white,
decoration: InputDecoration(
enabledBorder: const OutlineInputBorder(
borderSide: const BorderSide(
color: Colors.grey, width: 0.0),
),
fillColor: Colors.white,
border: OutlineInputBorder(),
hintText: 'Enter Name',
hintStyle: TextStyle(color: Colors.white),
),
style: TextStyle(color: Colors.white),
),
),
SizedBox(
width: 20,
)
],
),
SizedBox(
height: 10,
),
Row(
children: [
SizedBox(
width: 20,
),
Text("Enter Prices:- ",
style:
TextStyle(color: Colors.white, fontSize: 18)),
SizedBox(
width: 20,
),
Expanded(
child: TextField(
controller: price,
cursorColor: Colors.white,
decoration: InputDecoration(
enabledBorder: const OutlineInputBorder(
borderSide: const BorderSide(
color: Colors.grey, width: 0.0),
),
fillColor: Colors.white,
border: OutlineInputBorder(),
hintText: 'Enter Price',
hintStyle: TextStyle(color: Colors.white),
),
style: TextStyle(color: Colors.white),
),
),
SizedBox(
width: 20,
)
],
),
SizedBox(
height: 20,
),
ElevatedButton(
onPressed: () {
setState(() {
Mobiles.add({
'Name': name.value.text,
'Price': double.parse(price.text.toString())
});
});
print(Mobiles);
},
child: Text(
"Add Mobile",
style: TextStyle(
fontWeight: FontWeight.w800,
color: Colors.blueAccent),
),
style: ElevatedButton.styleFrom(
backgroundColor: Colors.white,
fixedSize: const Size(120, 50),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(50))),
),
SizedBox(
height: 20,
),
TextField(
controller: seachtext,
keyboardType: TextInputType.number,
cursorColor: Colors.white,
inputFormatters: <TextInputFormatter>[
FilteringTextInputFormatter.digitsOnly
],
decoration: InputDecoration(
enabledBorder: const OutlineInputBorder(
borderSide:
const BorderSide(color: Colors.white, width: 0.0),
),
fillColor: Colors.white,
border: OutlineInputBorder(),
hintText: 'Enter Price Range',
hintStyle: TextStyle(color: Colors.white),
),
style: TextStyle(color: Colors.white),
),
SizedBox(
height: 20,
),
ElevatedButton(
onPressed: () {
searched.clear();
searchWindow(int.parse(seachtext.text.toString()));
setState(() {
seachtext.text.toString() == "0"
? isSearch = false
: isSearch = true;
});
},
child: Text(
"Search",
style: TextStyle(
fontWeight: FontWeight.w800,
color: Colors.blueAccent),
),
style: ElevatedButton.styleFrom(
backgroundColor: Colors.white,
fixedSize: const Size(120, 50),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(50))),
),
],
),
),
),
),
SizedBox(
width: 50,
),
Expanded(
child: Container(
width: 500,
height: 600,
decoration: BoxDecoration(
color: Colors.blueAccent,
boxShadow: [
BoxShadow(color: Colors.black54, spreadRadius: 3),
],
borderRadius: BorderRadius.circular(10)),
child: Column(
children: [
Expanded(
child: isSearch == false
? ListView.builder(
itemCount: Mobiles.length,
itemBuilder: (context, index) {
return ListTile(
title: Text(
Mobiles[index]['Name'].toString(),
style: TextStyle(
color: Colors.white, fontSize: 20),
),
trailing: Text(
Mobiles[index]['Price'].toString(),
style: TextStyle(
color: Colors.white, fontSize: 20)),
);
},
)
: ListView.builder(
itemCount: searched.length,
itemBuilder: (context, index) {
return ListTile(
title: Text(
searched[index]['Name'].toString(),
style: TextStyle(
color: Colors.white, fontSize: 20),
),
trailing: Text(
searched[index]['Price'].toString(),
style: TextStyle(
color: Colors.white, fontSize: 20)),
);
},
),
),
],
),
),
),
SizedBox(
width: 50,
),
],
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment