no message

parent 11909f6d
import 'package:feelverapp/ui/login/login.dart';
import 'package:feelverapp/ui/shop/shop_main.dart'; import 'package:feelverapp/ui/shop/shop_main.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'ui/splashscreen/splash_screen_page.dart'; import 'ui/splashscreen/splash_screen_page.dart';
...@@ -20,7 +21,7 @@ class MyApp extends StatelessWidget { ...@@ -20,7 +21,7 @@ class MyApp extends StatelessWidget {
//home: ShopNearbyPlacesPage(), //home: ShopNearbyPlacesPage(),
// home: service_tab(), // home: service_tab(),
home: SplashScreenPage(), home: LoginPage(),
); );
} }
} }
class LoginModel {
String token;
int expires;
User user;
LoginModel({this.token, this.expires, this.user});
LoginModel.fromJson(Map<String, dynamic> json) {
token = json['token'];
expires = json['expires'];
user = json['user'] != null ? new User.fromJson(json['user']) : null;
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['token'] = this.token;
data['expires'] = this.expires;
if (this.user != null) {
data['user'] = this.user.toJson();
}
return data;
}
}
class User {
int id;
String roleId;
String name;
String email;
String avatar;
String emailVerifiedAt;
int status;
int fvRoleId;
String settings;
String createdAt;
String updatedAt;
String customerInfo;
User(
{this.id,
this.roleId,
this.name,
this.email,
this.avatar,
this.emailVerifiedAt,
this.status,
this.fvRoleId,
this.settings,
this.createdAt,
this.updatedAt,
this.customerInfo});
User.fromJson(Map<String, dynamic> json) {
id = json['id'];
roleId = json['role_id'];
name = json['name'];
email = json['email'];
avatar = json['avatar'];
emailVerifiedAt = json['email_verified_at'];
status = json['status'];
fvRoleId = json['fv_role_id'];
settings = json['settings'];
createdAt = json['created_at'];
updatedAt = json['updated_at'];
customerInfo = json['customer_info'];
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['id'] = this.id;
data['role_id'] = this.roleId;
data['name'] = this.name;
data['email'] = this.email;
data['avatar'] = this.avatar;
data['email_verified_at'] = this.emailVerifiedAt;
data['status'] = this.status;
data['fv_role_id'] = this.fvRoleId;
data['settings'] = this.settings;
data['created_at'] = this.createdAt;
data['updated_at'] = this.updatedAt;
data['customer_info'] = this.customerInfo;
return data;
}
}
\ No newline at end of file
import 'package:json_annotation/json_annotation.dart';
part 'base.g.dart';
@JsonSerializable()
class BaseModel {
final bool status;
final String message;
BaseModel(this.status, this.message);
factory BaseModel.fromJson(Map<String, dynamic> json) => _$BaseModelFromJson(json);
Map<String, dynamic> toJson() => _$BaseModelToJson(this);
}
@JsonSerializable()
class FailModel {
final bool status;
final String message;
FailModel(this.status, this.message);
factory FailModel.fromJson(Map<String, dynamic> json) =>
_$FailModelFromJson(json);
Map<String, dynamic> toJson() => _$FailModelToJson(this);
}
\ No newline at end of file
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'base.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
BaseModel _$BaseModelFromJson(Map<String, dynamic> json) {
return BaseModel(
json['status'] as bool,
json['message'] as String,
);
}
Map<String, dynamic> _$BaseModelToJson(BaseModel instance) => <String, dynamic>{
'status': instance.status,
'message': instance.message,
};
FailModel _$FailModelFromJson(Map<String, dynamic> json) {
return FailModel(
json['status'] as bool,
json['message'] as String,
);
}
Map<String, dynamic> _$FailModelToJson(FailModel instance) => <String, dynamic>{
'status': instance.status,
'message': instance.message,
};
import 'package:feelverapp/service/MyAlert.dart';
import 'package:flutter/cupertino.dart';
class Alert {
final MyAlertType type;
final BuildContext context;
final String title;
final String message;
final Function onOK;
final Function onCancel;
final String okText;
final String cancelText;
Alert({
this.type = MyAlertType.normal,
@required this.context,
this.title,
@required this.message,
this.onOK,
this.onCancel,
this.okText, this.cancelText,
}){
showCupertinoModalPopup(context: this.context, builder: (context){
return MyAlert(
type: this.type,
title: this.title,
message: this.message,
onOK: this.onOK,
onCancel: this.onCancel,
okText: this.okText ,
cancelText: this.cancelText ,
);
});
}
}
import 'package:feelverapp/util/SizeConfig.dart';
import 'package:flutter/material.dart';
enum MyAlertType {
normal,
confirm,
}
class MyAlert extends StatelessWidget {
final MyAlertType type;
final String title;
final String message;
final Function onOK;
final Function onCancel;
final String okText;
final String cancelText;
MyAlert({
@required this.title,
this.message,
this.type = MyAlertType.normal,
this.onOK,
this.onCancel, this.okText = 'ตกลง', this.cancelText = 'ยกเลิก',
});
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.black.withOpacity(.4),
body: Center(
child: Padding(
padding: EdgeInsets.symmetric(horizontal: SizeConfig.getPadding(24)),
child: AspectRatio(
aspectRatio: 4 / 3,
child: ClipRRect(
borderRadius: BorderRadius.circular(10),
child: Container(
color: Colors.white,
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
_title(),
_message(),
_actionButton(context),
],
),
),
),
),
),
),
);
}
Widget _title() {
return Container(
padding: EdgeInsets.symmetric(
vertical: SizeConfig.getPadding(30),
horizontal: SizeConfig.getPadding(10),
),
child: Text(
'${this.title}',
style: TextStyle(
fontSize: SizeConfig.getFontSize(22),
fontWeight: FontWeight.bold,
),
),
);
}
Widget _message() {
return Expanded(
child: Container(
padding: EdgeInsets.symmetric(
horizontal: SizeConfig.getPadding(16),
),
child: SingleChildScrollView(
child: Text(
'${this.message}',
style: TextStyle(
fontSize: SizeConfig.getFontSize(18),
),
textAlign: TextAlign.center,
),
),
),
);
}
Widget _actionButton(BuildContext context) {
return Container(
padding: EdgeInsets.only(
// left: SizeConfig.getPadding(8),
// right: SizeConfig.getPadding(8),
// bottom: SizeConfig.getPadding(0),
),
child: Row(
children: <Widget>[
_okButton(context),
this.type != MyAlertType.normal
? _cancelButton(context)
: Container(),
],
),
);
}
Widget _okButton(BuildContext context) {
return Expanded(
child: Container(
padding: EdgeInsets.symmetric(
horizontal: SizeConfig.getPadding(16),
vertical: SizeConfig.getPadding(16)),
child: RaisedButton(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
),
padding: EdgeInsets.symmetric(vertical: SizeConfig.getPadding(8)),
onPressed: () {
Navigator.pop(context);
if (onOK != null) {
onOK();
}
},
color: Theme.of(context).primaryColor,
child: Text(
this.okText,
style: TextStyle(
color: Colors.white,
fontSize: SizeConfig.getFontSize(18),
),
),
),
),
);
}
Widget _cancelButton(BuildContext context) {
return Expanded(
child: Container(
padding: EdgeInsets.symmetric(
horizontal: SizeConfig.getPadding(16),
vertical: SizeConfig.getPadding(16)),
child: RaisedButton(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
),
padding: EdgeInsets.symmetric(vertical: SizeConfig.getPadding(8)),
onPressed: () {
Navigator.pop(context);
if (onCancel != null) {
onCancel();
}
},
color: Colors.grey[400],
child: Text(
this.cancelText,
style: TextStyle(
color: Colors.white,
fontSize: SizeConfig.getFontSize(18),
),
),
),
),
);
}
}
import 'dart:convert';
import 'package:feelverapp/model/base/Login/login_model.dart';
import 'package:feelverapp/model/base/base.dart';
import 'package:http/http.dart' as http;
class Api<T>{
final String _baseApi = "https://backend.feelver.com/api";
final _headerApi = {
"Authorization": "Bearer {{ token }}",
};
Future<Response<T>> login(Object body) async {
var _model;
var _fail;
var result;
// (body as Map)['lang'] = allTranslations.currentLanguage;
await _httpConnection(
"${this._baseApi}/login", this._headerApi, body)
.then((response) {
if (response.statusCode == 200 && json.decode(response.body)['status']) {
_model = LoginModel.fromJson(json.decode(response.body));
} else {
_fail = FailModel.fromJson(json.decode(response.body));
}
result = new Response<T>(_model, _fail);
});
return result;
}
///api environment
Future<http.Response> _httpConnection(
String url, Map<String, String> headers, Object body) async {
if (body != null) {
final response = headers != null
? http.post(Uri.encodeFull(url), headers: headers, body: body)
: http.post(Uri.encodeFull(url), body: body);
return response;
} else {
final response = headers != null
? http.get(Uri.encodeFull(url), headers: headers)
: http.get(Uri.encodeFull(url));
return response;
}
}
dynamic _jsonDecode(String json) {
var resJson = jsonDecode(json);
return resJson;
}
}
class Response<T> {
T success;
FailModel fail;
Response(this.success, this.fail);
}
import 'package:flutter/material.dart';
abstract class BasePre{
}
class BasePresenter<T extends StatefulWidget> {
State<T> state;
bool loader = true;
BasePresenter(this.state);
setState(Function v){
state.setState(v);
}
loading(){
setState((){
loader = true;
});
}
dispose() {
state = null;
}
loaded(){
setState((){
loader = false;
});
}
}
\ No newline at end of file
...@@ -105,7 +105,7 @@ class _HomePageState extends State<HomePage> { ...@@ -105,7 +105,7 @@ class _HomePageState extends State<HomePage> {
'รถเข็นของฉัน', 'รถเข็นของฉัน',
style: TextStyle( style: TextStyle(
color: Colors.grey, color: Colors.grey,
fontSize: SizeConfig.getFontSize(12), fontSize: SizeConfig.getFontSize(11),
fontFamily: "SF_Pro_Text", fontFamily: "SF_Pro_Text",
fontWeight: FontWeight.w700), fontWeight: FontWeight.w700),
) )
......
import 'dart:developer';
import 'package:feelverapp/model/base/Login/login_model.dart';
import 'package:feelverapp/service/Alert.dart';
import 'package:feelverapp/service/api.dart';
import 'package:feelverapp/service/base_presenter.dart';
import 'package:feelverapp/ui/login/login.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
class LoginPresenter extends BasePresenter<LoginPage> {
Api _api;
final formKey = GlobalKey<FormState>();
TextEditingController emailCtrl = TextEditingController();
TextEditingController passCtrl = TextEditingController();
LoginPresenter(State<LoginPage> state) : super(state);
onSignIn() async {
if (formKey.currentState.validate()) {
await _letSignIn();
}
}
_letSignIn() async {
_api = Api<LoginModel>();
var res = await _api.login({
"email": emailCtrl.text,
'password': passCtrl.text,
});
if (res.fail == null) {
LoginModel model = res.success;
print("Username ="+"${model.user}");
print("Token ="+"${model.token}");
} else {
Alert(
context: state.context,
message:'email_or_password_invalid'
);
}
}
// facebookLogin() async {
// try {
// await _facebookLogin.logIn(['email']).then((result) async {
// var fbData = await Api().getFacebookInfo(result.accessToken.token);
// print(fbData);
// await _letSocialSignIn(result.accessToken.userId, 'facebook')
// .then((value) {
// if (value) {
// Navigator.popUntil(state.context, (route) => route.isFirst);
// Navigator.pushReplacement(state.context, CupertinoPageRoute(builder: (_) =>
// NavigatorPage(),
// ));
// } else {
// Navigator.push(
// state.context,
// CupertinoPageRoute(
// builder: (_) => SignUpEmail(
// socialType: SocialType.facebook,
// socialData: new RegisterSocialDataModel(
// socialId: result.accessToken.userId,
// token: result.accessToken.token,
// email: fbData['email'],
// firstName: fbData['first_name'],
// lastName: fbData['last_name'],
// ),
// )));
// }
// });
// });
// } catch (e) {
// print(e);
// }
// }
}
...@@ -397,6 +397,7 @@ class _ShopState extends State<Shop> { ...@@ -397,6 +397,7 @@ class _ShopState extends State<Shop> {
children: <Widget>[ children: <Widget>[
Container( Container(
color: Color.fromRGBO(106, 179, 170, 1), color: Color.fromRGBO(106, 179, 170, 1),
height: SizeConfig.getHeight(470), height: SizeConfig.getHeight(470),
width: MediaQuery.of(context).size.width, width: MediaQuery.of(context).size.width,
), ),
......
...@@ -54,9 +54,7 @@ class _MainShopState extends State<MainShop> with SingleTickerProviderStateMixi ...@@ -54,9 +54,7 @@ class _MainShopState extends State<MainShop> with SingleTickerProviderStateMixi
Widget build(BuildContext context) { Widget build(BuildContext context) {
SizeConfig(context); SizeConfig(context);
// Init the items // Init the items
for (var i = 0; i < 100; i++) {
items.add('Item $i');
}
return Scaffold( return Scaffold(
// backgroundColor: Colors.transparent, // backgroundColor: Colors.transparent,
......
...@@ -81,6 +81,20 @@ packages: ...@@ -81,6 +81,20 @@ packages:
description: flutter description: flutter
source: sdk source: sdk
version: "0.0.0" version: "0.0.0"
http:
dependency: "direct main"
description:
name: http
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.1"
http_parser:
dependency: transitive
description:
name: http_parser
url: "https://pub.dartlang.org"
source: hosted
version: "3.1.4"
image: image:
dependency: transitive dependency: transitive
description: description:
...@@ -88,6 +102,13 @@ packages: ...@@ -88,6 +102,13 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.1.4" version: "2.1.4"
json_annotation:
dependency: "direct main"
description:
name: json_annotation
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.1"
matcher: matcher:
dependency: transitive dependency: transitive
description: description:
......
...@@ -24,6 +24,8 @@ dependencies: ...@@ -24,6 +24,8 @@ dependencies:
# Use with the CupertinoIcons class for iOS style icons. # Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.2 cupertino_icons: ^0.1.2
flutter_screenutil: ^1.0.2 flutter_screenutil: ^1.0.2
http: ^0.12.0+4
json_annotation: ^3.0.1
dev_dependencies: dev_dependencies:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment