shawondeveloper / php-mysql-flutter-login-register

complete flutter php mysql login and register
47 stars 20 forks source link

asynchronus suspension #2

Open himangshu190 opened 3 years ago

himangshu190 commented 3 years ago

E/flutter (15879): #1 _ChunkedJsonParser.parseNumber (dart:convert-patch/convert_patch.dart:1271:9) E/flutter (15879): #2 _ChunkedJsonParser.parse (dart:convert-patch/convert_patch.dart:936:22) E/flutter (15879): #3 _parseJson (dart:convert-patch/convert_patch.dart:40:10) E/flutter (15879): #4 JsonDecoder.convert (dart:convert/json.dart:506:36) E/flutter (15879): #5 JsonCodec.decode (dart:convert/json.dart:157:41) E/flutter (15879): #6 _RegisterState.register (package:php_mysql_login_register/register.dart:26:21) E/flutter (15879): E/flutter (15879):

himangshu190 commented 3 years ago

please help me

himangshu190 commented 3 years ago

import 'dart:convert';

import 'package:flutter/material.dart'; import 'package:fluttertoast/fluttertoast.dart'; import 'package:http/http.dart' as http; import 'DashBoard.dart'; import 'main.dart';

class Register extends StatefulWidget { @override _RegisterState createState() => _RegisterState(); }

class _RegisterState extends State { TextEditingController email = TextEditingController(); TextEditingController pass = TextEditingController(); TextEditingController fullname = TextEditingController();

Future register() async { var url = "http://192.168.88.137/db_login_reg/register.php"; var response = await http.post(url, body: { "email": email.text, "password": pass.text, "fullname": fullname.text, }); var data = json.decode(response.body); if (data == "Error") { FlutterToast(context).showToast( child: Text( 'User allready exit!', style: TextStyle(fontSize: 25, color: Colors.red), )); } else { FlutterToast(context).showToast( child: Text('Registration Successful', style: TextStyle(fontSize: 25, color: Colors.green))); Navigator.push( context, MaterialPageRoute( builder: (context) => DashBoard(), ), ); } }

@override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text( 'Welcome to ACCF', style: TextStyle(fontWeight: FontWeight.bold), ), ), body: Container( height: 700, child: Card( color: Colors.white, child: Column( children: [ Padding( padding: const EdgeInsets.all(8.0), child: Text( 'Register', style: TextStyle(fontSize: 25, fontWeight: FontWeight.bold), ), ), Padding( padding: const EdgeInsets.all(8.0), child: TextField( controller: email, decoration: InputDecoration( labelText: 'email', prefixIcon: Icon(Icons.email), border: OutlineInputBorder( borderRadius: BorderRadius.circular(8)), ), ), ), Padding( padding: const EdgeInsets.all(8.0), child: TextField( controller: pass, obscureText: true, decoration: InputDecoration( labelText: 'Password', prefixIcon: Icon(Icons.lock), border: OutlineInputBorder( borderRadius: BorderRadius.circular(8)), ), ), ), Padding( padding: const EdgeInsets.all(8.0), child: TextField( controller: fullname, decoration: InputDecoration( labelText: 'fullname', prefixIcon: Icon(Icons.person), border: OutlineInputBorder( borderRadius: BorderRadius.circular(8)), ), ), ), Row( children: [ Expanded( child: MaterialButton( color: Colors.green, child: Text('Register', style: TextStyle( fontSize: 20, fontWeight: FontWeight.bold, color: Colors.white)), onPressed: () { register(); }, ), ), Expanded( child: MaterialButton( color: Colors.blue, child: Text('Login', style: TextStyle( fontSize: 20, fontWeight: FontWeight.bold, color: Colors.black)), onPressed: () { Navigator.push( context, MaterialPageRoute( builder: (context) => MyHomePage(), ), ); }, ), ), ], ) ], ), ), ), ); } }