I am trying to do a registration in a flutter app linked to Prestashop API
import 'package:flutter/cupertino.dart';
import 'package:http/http.dart' as http;
import 'dart:convert';
import 'package:flutter/material.dart';
class SignupPage extends StatelessWidget{
TextEditingController ussename=new TextEditingController();
TextEditingController pass=new TextEditingController();
TextEditingController fname=new TextEditingController();
TextEditingController lname=new TextEditingController();
TextEditingController tec = TextEditingController();
var encryptedText, plainText;
var encpass;
var mhd;
@override
Widget build(BuildContext context) {
ussename.text="[email protected]";
pass.text="Mail123@000";
fname.text="mhd";
lname.text="mhd";
return Scaffold(
backgroundColor: Colors.white,
body: SafeArea(
child: Container(
padding: EdgeInsets.only(left: 16,right: 16),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
SizedBox(height: 50,),
Text("Create Account,",style: TextStyle(fontSize: 26,fontWeight: FontWeight.bold),),
SizedBox(height: 6,),
Text("Sign up to get started!",style: TextStyle(fontSize: 20,color: Colors.grey.shade400),),
],
),
Column(
children: <Widget>[
TextField(
controller: fname,
decoration: InputDecoration(
labelText: "First Name",
labelStyle: TextStyle(fontSize: 14,color: Colors.grey.shade400,fontWeight: FontWeight.w600),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
borderSide: BorderSide(color: Colors.grey.shade300),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
borderSide: BorderSide(color: Colors.red),
),
floatingLabelBehavior: FloatingLabelBehavior.auto,
),
),
SizedBox(height: 16,),
TextField(
controller: lname,
decoration: InputDecoration(
labelText: "Last Name",
labelStyle: TextStyle(fontSize: 14,color: Colors.grey.shade400,fontWeight: FontWeight.w600),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
borderSide: BorderSide(color: Colors.grey.shade300),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
borderSide: BorderSide(color: Colors.red),
),
floatingLabelBehavior: FloatingLabelBehavior.auto,
),
),
SizedBox(height: 16,),
TextField(
controller: ussename,
decoration: InputDecoration(
labelText: "Email ID",
labelStyle: TextStyle(fontSize: 14,color: Colors.grey.shade400,fontWeight: FontWeight.w600),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
borderSide: BorderSide(color: Colors.grey.shade300),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
borderSide: BorderSide(color: Colors.red),
),
floatingLabelBehavior: FloatingLabelBehavior.auto,
),
),
SizedBox(height: 16,),
TextField(
controller: pass,
//obscureText: true,
decoration: InputDecoration(
labelText: "Password",
labelStyle: TextStyle(fontSize: 14,color: Colors.grey.shade400,fontWeight: FontWeight.w600),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
borderSide: BorderSide(color: Colors.grey.shade300),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
borderSide: BorderSide(color: Colors.red),
),
floatingLabelBehavior: FloatingLabelBehavior.auto,
),
),
SizedBox(height: 30,),
Container(
height: 50,
child: FlatButton(
onPressed: (){
print(ussename.text);
print(pass.text);
print(fname.text);
print(lname.text);
//adcus();
//addData();
signup();
},
padding: EdgeInsets.all(0),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(6),
),
child: Ink(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.centerLeft,
end: Alignment.centerRight,
colors: [
Color(0xffff5f6d),
Color(0xffff5f6d),
Color(0xffffc371),
],
),
borderRadius: BorderRadius.circular(6),
),
child: Container(
alignment: Alignment.center,
constraints: BoxConstraints(minHeight: 50,maxWidth: double.infinity),
child: Text("Sign up",style: TextStyle(fontWeight: FontWeight.bold,color: Colors.white),textAlign: TextAlign.center,),
),
),
),
),
SizedBox(height: 30,),
],
),
Padding(
padding: const EdgeInsets.only(bottom: 10),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text("I'm already a member.",style: TextStyle(fontWeight: FontWeight.bold),),
GestureDetector(
onTap: (){
Navigator.pop(context);
},
child: Text("Sign in.",style: TextStyle(fontWeight: FontWeight.bold,color: Colors.red),),
)
],
),
)
],
),
),
),
);
}
Future<void> signup()
async {
String url = "http://tpowep.com/mhd/prestashop/api/customers?schema=blank";
String username = 'DM1AC87PAGQSHGLDT71XMNWCYFZ4BRDE';
String password = ':';
String auth =
'Basic ' + base64Encode(utf8.encode('$username:$password'));
print(url);
http.post(
url,
headers: <String, String>{'authorization': auth,},
body:{
'active' : '1',
'birthday' : '2011-12-02',
'deleted' : '0',
'email' : '[email protected]',
'firstname' : 'ILOL',
'id' : '845',
'id_default_group' : '1',
'id_gender' : '1',
'ip_registration_newsletter' : '',
'is_guest' : '0',
'last_passwd_gen' : '2011-12-02 16:15:22',
'lastname' : 'Lol',
'newsletter' : '0',
'newsletter_date_add' : '',
'note' : '',
'optin' : '0',
'passwd' : 'xxxx',
'secure_key' : 'xxxx'
// ignore: missing_return
}).then((response) {
print('Response status : ${response.statusCode}');
print('Response body : ${response.body}');
});
}
}
question from:
https://stackoverflow.com/questions/65923643/i-am-trying-to-do-a-registration-in-a-flutter-app-linked-to-prestashop-api