i'm new to flutter and i'm tried many tym fr this api access and it is accessing but problem is that.. when i called onpress button Unactived... i pass parameter to textfileds and its passing....! actully can u check whre is the problm fr Unactivte button without SignUp function code read ??
look in the SignUp method in that method i describe to navigate when if my response is != null then i want navigate ! but in my case not happen in my code plz help me
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:http/http.dart' as http;
import 'package:shared_preferences/shared_preferences.dart';
import 'package:sms_snd/data.dart';
import 'new.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Loginpage(),
);
}
}
class Loginpage extends StatefulWidget {
@override
_LoginpageState createState() => _LoginpageState();
}
class _LoginpageState extends State<Loginpage> {
Signup(String email,String Password) async{
SharedPreferences sharedPreferences = await SharedPreferences.getInstance();
Map data = {
"APIKEY":"QVBAMTIjMllIRC1TREFTNUQtNUFTRksyMjE4Ng==",
"SECRETKEY":"MjQ1QDEyIzJZSEQtODVEQTJTM0RFQTg1Mz1JRTVCNEE1ODY=",
"Email": email,
"Password":Password
};
var jsonResponse;
var response = await http.post("http://services.edbrix.net/auth/login",
headers: <String, String>{
'Content-Type': 'application/json; charset=UTF-8',
},
body: jsonEncode(data));
if (response.statusCode == 200){
jsonResponse = json.decode(response.body);
print("Response status : ${response.statusCode}");
print("Response status : ${response.body}");
if(jsonResponse != null){
setState(() {
_isLoading = false;
});
sharedPreferences.setString("AccessToken", jsonResponse["AccessToken"]);
Navigator.of(context).pushAndRemoveUntil(MaterialPageRoute(builder: (BuildContext context) =>
newapp()), (Route<dynamic> route) => false);
}
else{
setState(() {
_isLoading = false;
});
print("Response status : ${response.body}");
}
}
}
String _email;
bool _isLoading = false;
String _pass;
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
final TextEditingController emailController = new TextEditingController();
final TextEditingController passwordController = new TextEditingController();
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white10,
body:_isLoading ? Center(child: CircularProgressIndicator()) : Form(
key: _formKey,
child: Stack(
children: <Widget>[
Positioned(
left: 40,
right: 40,
top: 250,
child: Center(
child: Text(
'Welcome!',
style: GoogleFonts.nunito(
fontSize: 31,
color: const Color(0xfff58634),
fontWeight: FontWeight.w700,
height: 1.1290322580645162,
),
textAlign: TextAlign.center,
),
),
),
Positioned(
left: 30,
right: 30,
top: 320,
child: SizedBox(
height: 50,
width: 170,
child: TextFormField(
controller: emailController,
cursorColor: Colors.black,
style: TextStyle(color: Colors.white70),
decoration: InputDecoration(
icon: Icon(Icons.email, color: Colors.white70),
hintText: "Email",
border: UnderlineInputBorder(borderSide: BorderSide(color: Colors.white70)),
hintStyle: TextStyle(color: Colors.white70),
),
),
),
),
Positioned(
left: 30,
right: 30,
top: 380,
child: SizedBox(
height: 50,
width: 170,
child: TextFormField(
controller: passwordController,
cursorColor: Colors.black,
style: TextStyle(color: Colors.white70),
decoration: InputDecoration(
icon: Icon(Icons.lock, color: Colors.white70),
hintText: "Password",
border: UnderlineInputBorder(borderSide: BorderSide(color: Colors.white70)),
hintStyle: TextStyle(color: Colors.white70),
),
),
),
),
Positioned(
top: 460,
right: 30,
child:SizedBox(
height: 45,
child: RaisedButton(
onPressed:
emailController.text == "" || passwordController.text == "" ? null : () {
Signup(emailController.text.toString(), passwordController.text.toString());
},
shape: new RoundedRectangleBorder(borderRadius: new BorderRadius.circular(5.0)),
color: const Color(0xfff58634),
child: Text(
"SEND OTP",style:
GoogleFonts.nunito( color: const Color(0xffffffff),
fontSize: 12
),
),
),
),
)
],
),
),
);
}
}
User contributions licensed under CC BY-SA 3.0