Flutter
/ * main dart dosyam */
import ‘dart:convert’;
import ‘package:flutter/cupertino.dart’;
import ‘package:flutter/material.dart’;
import ‘package:http/http.dart’ as http;
import ‘package:fluttertoast/fluttertoast.dart’;
void main(){
runApp(MaterialApp(
home: login_page(),
debugShowCheckedModeBanner: false,
));
}
class login_page extends StatefulWidget{
@override
_login_pageState createState() => _login_pageState();
}
class _login_pageState extends State<login_page>{
TextEditingController user = TextEditingController();
TextEditingController pass = TextEditingController();
Future register() async{
var url = “http://192.168.1.105/login/login.php”;
var response = await http.post(url,body: {
“username” : user.text,
“userpassword” : pass.text,
});
var data = jsonDecode(response.body);
if(data == "Hata"){
Fluttertoast.showToast(
msg: "Hata",
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.CENTER,
timeInSecForIosWeb: 1,
backgroundColor: Colors.red,
textColor: Colors.white,
fontSize: 16.0
);
}else{
Fluttertoast.showToast(
msg: "Başarılı",
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.CENTER,
timeInSecForIosWeb: 1,
backgroundColor: Colors.red,
textColor: Colors.white,
fontSize: 16.0
);
}
}
@override
Widget build(BuildContext context) {
final screenSize = MediaQuery.of(context).size;
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.lightGreenAccent,
title: Text(“Hesabına Giriş Yap”),
),
body: Container(
width: screenSize.width,
height: screenSize.height,
child: SingleChildScrollView(
child: Column(
children: <Widget>[
Container(
width: screenSize.width,
height: 190,
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(30),
bottomRight:Radius.circular(30),
),
image: DecorationImage(
image: AssetImage(“assets/ımages/tarlaa.jpg”),
fit: BoxFit.cover,
)
),
),
Container(
alignment: Alignment.centerLeft,
margin: EdgeInsets.only(left: 40,top: 35),
child: Text(
“Hesabına Giriş Yap”,
style: TextStyle(
fontFamily: ‘Teko’,
color: Colors.black45,
fontSize: 22,
),
),
),
Container(
width: screenSize.width,
height: 50,
margin: EdgeInsets.only(left: 40,right: 40,top: 25),
padding: EdgeInsets.only(left: 5,right: 5,),
decoration: BoxDecoration(
color: Colors.grey.shade200,
),
child: TextField(
controller: user,
decoration: InputDecoration(
icon: Icon(
Icons.account_box
),
border: InputBorder.none,
focusedBorder: InputBorder.none,
enabledBorder: InputBorder.none,
errorBorder: InputBorder.none,
disabledBorder: InputBorder.none,
hintText: “Kullanıcı Adınız”,
),
),
),
Container(
width: screenSize.width,
height: 50,
margin: EdgeInsets.only(left: 40,right: 40,top: 25),
padding: EdgeInsets.only(left: 5,right: 5,),
decoration: BoxDecoration(
color: Colors.grey.shade200,
),
child: TextField(
controller: pass,
obscureText: true,
decoration: InputDecoration(
icon: Icon(
Icons.lock
),
border: InputBorder.none,
focusedBorder: InputBorder.none,
enabledBorder: InputBorder.none,
errorBorder: InputBorder.none,
disabledBorder: InputBorder.none,
hintText: “Kullanıcı Şifreniz”,
),
),
),
Container(
width: screenSize.width,
height: 50,
margin: EdgeInsets.only(top:25,left: 40,right: 40),
decoration: BoxDecoration(
color: Colors.lightGreen,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(4),
topRight:Radius.circular(4),
bottomLeft:Radius.circular(4),
bottomRight:Radius.circular(4),
),
),
child: MaterialButton(
child: Text(
“Giriş Yap”,
style: TextStyle(
fontFamily: ‘Teko’,
color: Colors.white,
),
),
onPressed: (){
register();
},
),
),
Container(
width: screenSize.width,
height: 50,
alignment: Alignment.centerRight,
margin: EdgeInsets.only(left: 40,right: 40,top: 10),
child: TextButton(
child: Text(
"Şifremi Unuttum",
style: TextStyle(
color: Colors.black45,
fontFamily: 'Teko',
letterSpacing: 0.3,
),
),
onPressed: (){
},
),
),
],
),
),
),
);
}
}
/* login.php dosyam */
<?php
$db = mysqli_connect(‘localhost’,‘root’,'',‘ornek’);
if(!$db){
echo “hata”;
}
if($POST){
$username = $POST[‘username’];
$userpassword = $_POST[‘userpassword’];
$sql = "SELECT * FROM trader_account WHERE username = '".$username."' AND userpassword = '".$userpassword."'";
$result = mysqli_query($db,$sql);
$count = mysqli_num_rows($result);
if ($count == 1) {
echo json_encode("Hata");
}else{
$insert = "INSERT INTO trader_account(username,userpassword) VALUES('".$userpassword."'','".$userpassword."')";
$query = mysqli_query($db,$insert);
if($query){
echo json_encode("Başarılı");
}
}
}
?>
aldıgım hata ise;
[ERROR:flutter/lib/ui/ui_dart_state.cc(186)] Unhandled Exception: FormatException: Unexpected end of input (at character 1)