Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
import 'package:redux/redux.dart';
import 'package:chatmetricsproject/models/models.dart' show Login, AppState;
import 'package:chatmetricsproject/widgetutils/widgetutils.dart' show WidgetUtils;
class LoginRequest {
class LoginSuccess{
final int success;
final String message;
final Login login;
LoginSuccess(this.success, this.message, this.login);
class LoginError {
final int success;
final String message;
LoginError(this.success, this.message);
final login = (BuildContext context, String email, String password) {
return (Store<AppState> store) {
WidgetUtils.showLoadingDialog(context, 'Signing');
store.dispatch(new LoginRequest());
var url = '';
var client = new http.Client();, body: {
'email': email,
'password': password
}).then((response) => JSON.decode(response.body)).then((value) {
if (value['success'] == 1) {
var login = new Login.fromJson(value);
store.dispatch(new LoginSuccess(login.success, login.message, login));
WidgetUtils.showSuccess(context, 'Login', login.message);
} else {
store.dispatch(new LoginError(value['success'], value['message']));
WidgetUtils.showError(context, 'Login Error', value['message']);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.