Skip to content

Instantly share code, notes, and snippets.

@aldhinya
Created January 15, 2021 10:58
Show Gist options
  • Save aldhinya/6f69f6fd85247cfa7dbbe347d6f718ea to your computer and use it in GitHub Desktop.
Save aldhinya/6f69f6fd85247cfa7dbbe347d6f718ea to your computer and use it in GitHub Desktop.
import 'package:flutter/material.dart';
import 'package:flutter_task/mainmenu.dart';
class Login extends StatefulWidget {
@override
_LoginPageState createState() => _LoginPageState();
}
class _LoginPageState extends State<Login> {
String username, password;
bool visible = false;
_cekLogin() async {
setState(() {
visible = true;
});
try {
if (username == "anandagalang" && password == "admin123") {
Navigator.pushReplacement(context,
MaterialPageRoute(builder: (context) {
return MainMenu();
}));
AlertDialog alert = AlertDialog(
title: Text("Sukses"),
content: Text("Welcome to IT Catalog"),
);
showDialog(
context: context,
builder: (BuildContext context) {
return alert;
},
);
} else if(username == "" || password == "") {
_popupAlert(context, "Oopss", "Silahkan Isi Username dan Password");
} else {
_popupAlert(context, "Gagal Login", "Username atau Password Salah");
}
} catch (e) {}
}
_popupAlert(BuildContext context, String ttl, String err) {
Widget okButton = FlatButton(
child: Text("OK"),
onPressed: () => Navigator.pop(context),
);
AlertDialog alert = AlertDialog(
title: Text(ttl),
content: Text(err),
actions: [
okButton,
],
);
showDialog(
context: context,
builder: (BuildContext context) {
return alert;
},
);
}
Widget _buildLogo(){
return Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Padding(
padding: const EdgeInsets.symmetric(vertical: 70),
child: Text(
'Welcome',
style: TextStyle(
fontSize: MediaQuery.of(context).size.height / 25,
fontWeight: FontWeight.bold,
color: Colors.white,
),
),
),
],
);
}
Widget _buildUsernameRow(){
return Padding(
padding: EdgeInsets.all(8),
child: TextFormField(
keyboardType: TextInputType.text,
onChanged: (value){
setState(() {
username = value;
});
},
decoration: InputDecoration(
prefixIcon: Icon(
Icons.person,
color: Color(0xFFB8E994),
),
labelText: 'Username'),
),
);
}
Widget _buildPasswordRow(){
return Padding(
padding: EdgeInsets.all(8),
child: TextFormField(
keyboardType: TextInputType.text,
obscureText: true,
onChanged: (value){
setState(() {
password = value;
});
},
decoration: InputDecoration(
prefixIcon: Icon(
Icons.lock,
color: Color(0xFFB8E994),
),
labelText: 'Password'),
),
);
}
Widget _buildLoginButton(){
return Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(
height: 1.4*(MediaQuery.of(context).size.height/20),
width: 5*(MediaQuery.of(context).size.width/10),
margin: EdgeInsets.only(bottom:20),
child: RaisedButton(
elevation: 5.0,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30.0),
),
onPressed: _cekLogin,
child: Text(
"Login",
style: TextStyle(
color: Colors.white,
letterSpacing: 1.5,
fontSize: MediaQuery.of(context).size.height / 40,
),
),
),
)
],
);
}
Widget _buildContainer(){
return Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
ClipRRect(
borderRadius: BorderRadius.all(
Radius.circular(20)
),
child: Container(
height: MediaQuery.of(context).size.height*0.6,
width: MediaQuery.of(context).size.width*0.8,
decoration: BoxDecoration(
color: Colors.white,
),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
"Login",
style: TextStyle(
fontSize: MediaQuery.of(context).size.height / 30,
),
),
],
),
_buildUsernameRow(),
_buildPasswordRow(),
_buildLoginButton(),
],
),
),
),
],
);
}
@override
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold(
resizeToAvoidBottomPadding: false,
backgroundColor: Color(0xfff2f3f7),
body: Stack(
children: <Widget>[
Container(
height: MediaQuery.of(context).size.height*0.7,
width: MediaQuery.of(context).size.width,
child: Container(
decoration: BoxDecoration(
color: Color(0xFFB8E994) ,
borderRadius: BorderRadius.only(
bottomLeft: const Radius.circular(70),
bottomRight: const Radius.circular(70),
)
),
),
),
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget> [
_buildLogo(),
_buildContainer(),
],
)
],
),
));
}
}
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter_task/login.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home:Login(),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment