Last active
December 23, 2021 18:11
-
-
Save Jahidul007/c49b79830d21512768f3a8d79ca35887 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:convert'; | |
import 'package:flutter/material.dart'; | |
import 'package:http/http.dart' as http; | |
void main() { | |
runApp(const MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
const MyApp({Key key}) : super(key: key); | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'Playground', | |
theme: ThemeData( | |
primarySwatch: Colors.blue, | |
), | |
home: const MyHomePage(), | |
); | |
} | |
} | |
class MyHomePage extends StatelessWidget { | |
const MyHomePage({Key key}) : super(key: key); | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
backgroundColor: Colors.green, | |
body: Align( | |
alignment: Alignment.bottomCenter, | |
child: ResponsiveInput(), | |
), | |
); | |
} | |
} | |
class ResponsiveInput extends StatelessWidget { | |
ResponsiveInput({Key key}) : super(key: key); | |
TextEditingController emailTextEditingController = TextEditingController(); | |
TextEditingController passwordTextEditingController = TextEditingController(); | |
@override | |
Widget build(BuildContext context) { | |
return Container( | |
width: double.infinity, | |
padding: EdgeInsets.only(left: 30, right: 30), | |
child: Column( | |
crossAxisAlignment: CrossAxisAlignment.start, | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: [ | |
TextFormField( | |
controller: emailTextEditingController, | |
cursorColor: Colors.black, | |
obscureText: false, | |
onSaved: (input) {}, | |
), | |
TextFormField( | |
controller: passwordTextEditingController, | |
cursorColor: Colors.black, | |
obscureText: false, | |
onSaved: (input) {}, | |
), | |
TextButton(onPressed: (){ | |
LoginRequestModel login = LoginRequestModel( | |
email: emailTextEditingController.text, | |
password: passwordTextEditingController.text, | |
); | |
Auth().login(login); | |
}, child: Text("Login")) | |
], | |
), | |
); | |
} | |
} | |
class LoginRequestModel { | |
String email; | |
String password; | |
LoginRequestModel({ this.email, this.password} ); | |
factory LoginRequestModel.fromJson(Map<String, dynamic> json) { | |
return LoginRequestModel( | |
email: json['email'], | |
password: json['password'] | |
); | |
} | |
Map<String, dynamic> toJson() { | |
final Map<String, dynamic> data = new Map<String, dynamic>(); | |
data['email'] = this.email; | |
data['password'] = this.password; | |
return data; | |
} | |
} | |
class Auth { | |
static String baseUrl = "MY_API"; | |
var client = http.Client(); | |
void login(LoginRequestModel model) async { | |
print(model.toJson()); | |
await client.post(Uri.parse(baseUrl), body: jsonEncode(model.toJson())); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment