Commit f0064b8a by Rizal Hermawan

feat (login) : add login feature using package state_rebuilder (related…

feat (login) : add login feature using package state_rebuilder (related components are still static). Story #1
parent 5407e7cb
......@@ -3,7 +3,7 @@
#
# For more info see: https://dart.dev/go/dot-packages-deprecation
#
# Generated by pub on 2021-06-16 16:46:58.663440.
# Generated by pub on 2021-06-23 14:29:28.997524.
async:file:///D:/flutter/2.0.4-stable/.pub-cache/hosted/pub.dartlang.org/async-2.5.0/lib/
boolean_selector:file:///D:/flutter/2.0.4-stable/.pub-cache/hosted/pub.dartlang.org/boolean_selector-2.1.0/lib/
characters:file:///D:/flutter/2.0.4-stable/.pub-cache/hosted/pub.dartlang.org/characters-1.1.0/lib/
......
......@@ -3,68 +3,69 @@
#
# For more info see: https://dart.dev/go/dot-packages-deprecation
#
# Generated by pub on 2021-06-16 16:47:00.746173.
args:file:///D:/flutter/2.0.4-stable/.pub-cache/hosted/pub.dartlang.org/args-1.6.0/lib/
# Generated by pub on 2021-06-23 15:35:44.277132.
args:file:///D:/flutter/2.0.4-stable/.pub-cache/hosted/pub.dartlang.org/args-2.1.1/lib/
async:file:///D:/flutter/2.0.4-stable/.pub-cache/hosted/pub.dartlang.org/async-2.5.0/lib/
bloc:file:///D:/flutter/2.0.4-stable/.pub-cache/hosted/pub.dartlang.org/bloc-7.0.0/lib/
boolean_selector:file:///D:/flutter/2.0.4-stable/.pub-cache/hosted/pub.dartlang.org/boolean_selector-2.1.0/lib/
characters:file:///D:/flutter/2.0.4-stable/.pub-cache/hosted/pub.dartlang.org/characters-1.1.0/lib/
charcode:file:///D:/flutter/2.0.4-stable/.pub-cache/hosted/pub.dartlang.org/charcode-1.2.0/lib/
cli_repl:file:///D:/flutter/2.0.4-stable/.pub-cache/hosted/pub.dartlang.org/cli_repl-0.2.2/lib/
clock:file:///D:/flutter/2.0.4-stable/.pub-cache/hosted/pub.dartlang.org/clock-1.1.0/lib/
collection:file:///D:/flutter/2.0.4-stable/.pub-cache/hosted/pub.dartlang.org/collection-1.15.0/lib/
colorize:file:///D:/flutter/2.0.4-stable/.pub-cache/hosted/pub.dartlang.org/colorize-2.0.0/lib/
crypto:file:///D:/flutter/2.0.4-stable/.pub-cache/hosted/pub.dartlang.org/crypto-3.0.1/lib/
cupertino_icons:file:///D:/flutter/2.0.4-stable/.pub-cache/hosted/pub.dartlang.org/cupertino_icons-1.0.2/lib/
dart2_constant:file:///D:/flutter/2.0.4-stable/.pub-cache/hosted/pub.dartlang.org/dart2_constant-1.0.2+dart2/lib/
equatable:file:///D:/flutter/2.0.4-stable/.pub-cache/hosted/pub.dartlang.org/equatable-1.1.1/lib/
fake_async:file:///D:/flutter/2.0.4-stable/.pub-cache/hosted/pub.dartlang.org/fake_async-1.2.0/lib/
file:file:///D:/flutter/2.0.4-stable/.pub-cache/hosted/pub.dartlang.org/file-5.2.1/lib/
fluri:file:///D:/flutter/2.0.4-stable/.pub-cache/hosted/pub.dartlang.org/fluri-1.3.0/lib/
ffi:file:///D:/flutter/2.0.4-stable/.pub-cache/hosted/pub.dartlang.org/ffi-1.1.2/lib/
file:file:///D:/flutter/2.0.4-stable/.pub-cache/hosted/pub.dartlang.org/file-6.1.2/lib/
flutter:file:///D:/flutter/2.0.4-stable/packages/flutter/lib/
flutter_bloc:file:///D:/flutter/2.0.4-stable/.pub-cache/hosted/pub.dartlang.org/flutter_bloc-7.0.1/lib/
flutter_sequence_animation_null_safety:file:///D:/flutter/2.0.4-stable/.pub-cache/git/flutter_sequence_animation_null_safety-773d67311fed31fae22214b385265ae275854495/lib/
flutter_test:file:///D:/flutter/2.0.4-stable/packages/flutter_test/lib/
flutter_user_agent:file:///D:/flutter/2.0.4-stable/.pub-cache/hosted/pub.dartlang.org/flutter_user_agent-1.2.2/lib/
flutter_web_plugins:file:///D:/flutter/2.0.4-stable/packages/flutter_web_plugins/lib/
fluttertoast:file:///D:/flutter/2.0.4-stable/.pub-cache/hosted/pub.dartlang.org/fluttertoast-8.0.7/lib/
font_awesome_flutter:file:///D:/flutter/2.0.4-stable/.pub-cache/hosted/pub.dartlang.org/font_awesome_flutter-9.0.0/lib/
glob:file:///D:/flutter/2.0.4-stable/.pub-cache/hosted/pub.dartlang.org/glob-1.2.0/lib/
http:file:///D:/flutter/2.0.4-stable/.pub-cache/hosted/pub.dartlang.org/http-0.12.2/lib/
http_parser:file:///D:/flutter/2.0.4-stable/.pub-cache/hosted/pub.dartlang.org/http_parser-3.1.4/lib/
hive:file:///D:/flutter/2.0.4-stable/.pub-cache/hosted/pub.dartlang.org/hive-2.0.4/lib/
hive_flutter:file:///D:/flutter/2.0.4-stable/.pub-cache/hosted/pub.dartlang.org/hive_flutter-1.1.0/lib/
http:file:///D:/flutter/2.0.4-stable/.pub-cache/hosted/pub.dartlang.org/http-0.13.0/lib/
http_parser:file:///D:/flutter/2.0.4-stable/.pub-cache/hosted/pub.dartlang.org/http_parser-4.0.0/lib/
intl:file:///D:/flutter/2.0.4-stable/.pub-cache/hosted/pub.dartlang.org/intl-0.17.0/lib/
js:file:///D:/flutter/2.0.4-stable/.pub-cache/hosted/pub.dartlang.org/js-0.6.3/lib/
json_pointer:file:///D:/flutter/2.0.4-stable/.pub-cache/hosted/pub.dartlang.org/json_pointer-0.1.0/lib/
json_schema:file:///D:/flutter/2.0.4-stable/.pub-cache/hosted/pub.dartlang.org/json_schema-3.0.0/lib/
json_class:file:///D:/flutter/2.0.4-stable/.pub-cache/hosted/pub.dartlang.org/json_class-2.0.0+1/lib/
json_schema2:file:///D:/flutter/2.0.4-stable/.pub-cache/hosted/pub.dartlang.org/json_schema2-2.0.0+2/lib/
llswidget:../lib/
logging:file:///D:/flutter/2.0.4-stable/.pub-cache/hosted/pub.dartlang.org/logging-0.11.4/lib/
logging:file:///D:/flutter/2.0.4-stable/.pub-cache/hosted/pub.dartlang.org/logging-1.0.1/lib/
matcher:file:///D:/flutter/2.0.4-stable/.pub-cache/hosted/pub.dartlang.org/matcher-0.12.10/lib/
meta:file:///D:/flutter/2.0.4-stable/.pub-cache/hosted/pub.dartlang.org/meta-1.3.0/lib/
mime:file:///D:/flutter/2.0.4-stable/.pub-cache/hosted/pub.dartlang.org/mime-0.9.7/lib/
nested:file:///D:/flutter/2.0.4-stable/.pub-cache/hosted/pub.dartlang.org/nested-1.0.0/lib/
node_interop:file:///D:/flutter/2.0.4-stable/.pub-cache/hosted/pub.dartlang.org/node_interop-1.2.1/lib/
node_io:file:///D:/flutter/2.0.4-stable/.pub-cache/hosted/pub.dartlang.org/node_io-1.2.0/lib/
package_config:file:///D:/flutter/2.0.4-stable/.pub-cache/hosted/pub.dartlang.org/package_config-1.9.3/lib/
package_resolver:file:///D:/flutter/2.0.4-stable/.pub-cache/hosted/pub.dartlang.org/package_resolver-1.0.10/lib/
path:file:///D:/flutter/2.0.4-stable/.pub-cache/hosted/pub.dartlang.org/path-1.8.0/lib/
path_provider:file:///D:/flutter/2.0.4-stable/.pub-cache/hosted/pub.dartlang.org/path_provider-2.0.2/lib/
path_provider_linux:file:///D:/flutter/2.0.4-stable/.pub-cache/hosted/pub.dartlang.org/path_provider_linux-2.0.0/lib/
path_provider_macos:file:///D:/flutter/2.0.4-stable/.pub-cache/hosted/pub.dartlang.org/path_provider_macos-2.0.0/lib/
path_provider_platform_interface:file:///D:/flutter/2.0.4-stable/.pub-cache/hosted/pub.dartlang.org/path_provider_platform_interface-2.0.1/lib/
path_provider_windows:file:///D:/flutter/2.0.4-stable/.pub-cache/hosted/pub.dartlang.org/path_provider_windows-2.0.1/lib/
pedantic:file:///D:/flutter/2.0.4-stable/.pub-cache/hosted/pub.dartlang.org/pedantic-1.11.0/lib/
platform:file:///D:/flutter/2.0.4-stable/.pub-cache/hosted/pub.dartlang.org/platform-3.0.0/lib/
plugin_platform_interface:file:///D:/flutter/2.0.4-stable/.pub-cache/hosted/pub.dartlang.org/plugin_platform_interface-2.0.0/lib/
process:file:///D:/flutter/2.0.4-stable/.pub-cache/hosted/pub.dartlang.org/process-4.2.1/lib/
provider:file:///D:/flutter/2.0.4-stable/.pub-cache/hosted/pub.dartlang.org/provider-5.0.0/lib/
quiver:file:///D:/flutter/2.0.4-stable/.pub-cache/hosted/pub.dartlang.org/quiver-2.1.5/lib/
quiver:file:///D:/flutter/2.0.4-stable/.pub-cache/hosted/pub.dartlang.org/quiver-3.0.1/lib/
responsive_framework:file:///D:/flutter/2.0.4-stable/.pub-cache/hosted/pub.dartlang.org/responsive_framework-0.1.0/lib/
sass:file:///D:/flutter/2.0.4-stable/.pub-cache/hosted/pub.dartlang.org/sass-1.32.8/lib/
rest_client:file:///D:/flutter/2.0.4-stable/.pub-cache/hosted/pub.dartlang.org/rest_client-2.0.1+2/lib/
sky_engine:file:///D:/flutter/2.0.4-stable/bin/cache/pkg/sky_engine/lib/
sockjs_client:file:///D:/flutter/2.0.4-stable/.pub-cache/git/sockjs-dart-client-2e8dc8d2fe8486d31b6e220277c94d746ced1691/lib/
sockjs_client_wrapper:file:///D:/flutter/2.0.4-stable/.pub-cache/hosted/pub.dartlang.org/sockjs_client_wrapper-1.1.0/lib/
source_maps:file:///D:/flutter/2.0.4-stable/.pub-cache/hosted/pub.dartlang.org/source_maps-0.10.10/lib/
source_span:file:///D:/flutter/2.0.4-stable/.pub-cache/hosted/pub.dartlang.org/source_span-1.8.0/lib/
stack_trace:file:///D:/flutter/2.0.4-stable/.pub-cache/hosted/pub.dartlang.org/stack_trace-1.10.0/lib/
states_rebuilder:file:///D:/flutter/2.0.4-stable/.pub-cache/hosted/pub.dartlang.org/states_rebuilder-4.3.0/lib/
stream_channel:file:///D:/flutter/2.0.4-stable/.pub-cache/hosted/pub.dartlang.org/stream_channel-2.1.0/lib/
stream_transform:file:///D:/flutter/2.0.4-stable/.pub-cache/hosted/pub.dartlang.org/stream_transform-2.0.0/lib/
string_scanner:file:///D:/flutter/2.0.4-stable/.pub-cache/hosted/pub.dartlang.org/string_scanner-1.1.0/lib/
term_glyph:file:///D:/flutter/2.0.4-stable/.pub-cache/hosted/pub.dartlang.org/term_glyph-1.2.0/lib/
test_api:file:///D:/flutter/2.0.4-stable/.pub-cache/hosted/pub.dartlang.org/test_api-0.2.19/lib/
tuple:file:///D:/flutter/2.0.4-stable/.pub-cache/hosted/pub.dartlang.org/tuple-1.0.3/lib/
typed_data:file:///D:/flutter/2.0.4-stable/.pub-cache/hosted/pub.dartlang.org/typed_data-1.3.0/lib/
uri:file:///D:/flutter/2.0.4-stable/.pub-cache/hosted/pub.dartlang.org/uri-0.11.4/lib/
uri:file:///D:/flutter/2.0.4-stable/.pub-cache/hosted/pub.dartlang.org/uri-1.0.0/lib/
uuid:file:///D:/flutter/2.0.4-stable/.pub-cache/hosted/pub.dartlang.org/uuid-3.0.4/lib/
vector_math:file:///D:/flutter/2.0.4-stable/.pub-cache/hosted/pub.dartlang.org/vector_math-2.1.0/lib/
w_common:file:///D:/flutter/2.0.4-stable/.pub-cache/hosted/pub.dartlang.org/w_common-1.20.4/lib/
w_transport:file:///D:/flutter/2.0.4-stable/.pub-cache/hosted/pub.dartlang.org/w_transport-3.2.8/lib/
watcher:file:///D:/flutter/2.0.4-stable/.pub-cache/hosted/pub.dartlang.org/watcher-0.9.7+15/lib/
widgetparser:../../widgetparser/lib/
win32:file:///D:/flutter/2.0.4-stable/.pub-cache/hosted/pub.dartlang.org/win32-2.0.5/lib/
xdg_directories:file:///D:/flutter/2.0.4-stable/.pub-cache/hosted/pub.dartlang.org/xdg_directories-0.2.0/lib/
demo_package_ui_semantic:lib/
import 'package:states_rebuilder/states_rebuilder.dart';
import 'package:hive/hive.dart';
import 'package:hive_flutter/hive_flutter.dart';
class HiveStorage implements IPersistStore {
late Box box;
@override
Future<void> init() async {
await Hive.initFlutter();
box = await Hive.openBox('myBox');
}
@override
Object? read(String key) {
return box.get(key);
}
@override
Future<void> write<T>(String key, T value) async {
return box.put(key, value);
}
@override
Future<void> delete(String key) async {
return box.delete(key);
}
@override
Future<void> deleteAll() async {
await box.clear();
}
}
part 'shared_method.dart';
\ No newline at end of file
import 'package:flutter/cupertino.dart';
import 'package:flutter/services.dart';
import 'package:fluttertoast/fluttertoast.dart';
// ignore: import_of_legacy_library_into_null_safe
import 'package:flutter_user_agent/flutter_user_agent.dart';
import 'package:llswidget/llswidget.dart';
part 'shared_method.dart';
part 'shared_value.dart';
\ No newline at end of file
......@@ -3,4 +3,110 @@ part of 'helpers.dart';
void printWrapped(String text) {
final pattern = new RegExp('.{1,800}');
pattern.allMatches(text).forEach((match) => print(match.group(0)));
}
String checkError(String checkError) {
String error;
if (checkError.contains('No address associated with hostname')) {
error = SharedValue.titleAlertDisconnected;
}
else if(checkError.contains('SocketException')) {
error = "Please Check Your Network Connection";
}
else if(checkError.contains('SQLSTATE') || checkError.contains('<HTML>')) {
error = "API Error";
}
else {
error = checkError;
}
return error;
}
Map checkAPIResultStatus(Map data) {
String errorGeneral = 'There was an error. Please try again';
Map checkResult;
String keysFromJson = data.keys.join(',');
if (!keysFromJson.contains('status')) {
if (keysFromJson.contains('message')) {
checkResult = {
'error': true,
'message': data['message'] != 'invalid_token' ? errorGeneral : data['message']
};
} else {
checkResult = {
'error': true,
'message': errorGeneral
};
}
} else if (data['status'] == 'error') {
if (keysFromJson.contains('errors')) {
checkResult = {
'error': true,
'message': data['errors'].runtimeType == String ? data['errors'] : errorGeneral
};
} else if (keysFromJson.contains('error')) {
checkResult = {
'error': true,
'message': data['error'].runtimeType == String ? data['error'] : errorGeneral
};
} else {
checkResult = {
'error': true,
'message': errorGeneral
};
}
} else {
checkResult = {
'error': false,
'message': null
};
}
return checkResult;
}
showToastWidget(
String message,
{
String duration = 'short',
String position = 'top',
int durationIos = 5,
Color bgColor = LLSColors.DARK,
Color textColor = LLSColors.WHITE,
double fontSize = 12.0
}
) {
Toast toastDuration;
if (duration == 'long') {
toastDuration = Toast.LENGTH_LONG;
} else {
toastDuration = Toast.LENGTH_SHORT;
}
ToastGravity toastPosition;
if (position == 'center') {
toastPosition = ToastGravity.CENTER;
} else if (position == 'bottom') {
toastPosition = ToastGravity.BOTTOM;
} else {
toastPosition = ToastGravity.TOP;
}
Fluttertoast.showToast(
msg: message,
toastLength: toastDuration,
gravity: toastPosition,
timeInSecForIosWeb: durationIos,
backgroundColor: bgColor,
textColor: textColor,
fontSize: fontSize
);
}
Future<String> initUserAgentState() async {
String userAgent;
try {
userAgent = await FlutterUserAgent.getPropertyAsync('userAgent');
await FlutterUserAgent.init();
} on PlatformException {
userAgent = '<error>';
}
return userAgent;
}
\ No newline at end of file
part of 'helpers.dart';
class SharedValue {
//static const String baseUrl = 'https://api.laukita.com';
static const String baseUrl = 'http://192.168.100.109';
static const String api = '$baseUrl/v0.1';
static const String titleAlertDisconnected = 'No Internet Connection';
static const String bodyAlertDisconnected = 'You must be connected to the Internet to continue this action';
static const String email = 'setyawanfaisal90@gmail.com';
static const String password = '142142';
// static const String email = 'rizalhrm@outlook.com';
// static const String password = 'Q-werty123';
}
\ No newline at end of file
import 'package:flutter/material.dart';
import 'package:responsive_framework/responsive_framework.dart';
import 'package:states_rebuilder/states_rebuilder.dart';
import 'package:demo_package_ui_semantic/data_source/hive_storage.dart';
import 'route_generator.dart';
import 'ui/pages/pages.dart';
void main() {
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await RM.storageInitializer(HiveStorage());
FlutterError.onError = (FlutterErrorDetails details) {
print("Error : ${details.exception}");
print("StackTrace : ${details.stack}");
......@@ -15,26 +19,84 @@ class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
builder: (context, widget) => ResponsiveWrapper.builder(
ClampingScrollWrapper.builder(context, widget!),
maxWidth: 1000,
minWidth: 450,
defaultScale: true,
defaultName: MOBILE,
breakpoints: [
ResponsiveBreakpoint.resize(450, name: MOBILE),
ResponsiveBreakpoint.autoScale(800, name: TABLET),
ResponsiveBreakpoint.autoScale(1000, name: TABLET)
],
return TopAppWidget(
ensureInitialization: () => [
RM.storageInitializer(HiveStorage()),
],
onWaiting: () => MaterialApp(
theme: ThemeData.dark(),
home: Scaffold(
body: Center(child: CircularProgressIndicator())
),
),
title: 'Demo Package UI Semantic',
theme: ThemeData(
primarySwatch: Colors.blue,
),
initialRoute: '/main_page',
onGenerateRoute: RouteGenerator.generateRoute,
debugShowCheckedModeBanner: false,
onError: (error, refresh) {
return MaterialApp(
theme: ThemeData.dark(),
home: Scaffold(
body: Text('$error'),
),
);
},
injectedAuth: user,
builder: (context) {
return MaterialApp(
builder: (context, widget) => ResponsiveWrapper.builder(
ClampingScrollWrapper.builder(context, widget!),
maxWidth: 1000,
minWidth: 450,
defaultScale: true,
defaultName: MOBILE,
breakpoints: [
ResponsiveBreakpoint.resize(450, name: MOBILE),
ResponsiveBreakpoint.autoScale(800, name: TABLET),
ResponsiveBreakpoint.autoScale(1000, name: TABLET)
],
),
title: 'Demo Package UI Semantic',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: On.auth(
onInitialWaiting: () => Center(child: CircularProgressIndicator()),
onUnsigned: () => LoginPage(),
onSigned: () => MainPage(),
).listenTo(
user,
useRouteNavigation: true
),
navigatorKey: RM.navigate.navigatorKey,
onGenerateRoute: RM.navigate.onGenerateRoute(
{
MainPage.routeName: (_) => MainPage(),
LoginPage.routeName: (_) => LoginPage(),
ButtonsPage.routeName: (_) => ButtonsPage(),
StandardsButtonPage.routeName: (_) => StandardsButtonPage(),
LabelPage.routeName: (_) => LabelPage(),
TilesPage.routeName: (_) => TilesPage(),
RoundedButtonPage.routeName: (_) => RoundedButtonPage(),
SquareButtonPage.routeName: (_) => SquareButtonPage(),
ButtonsPageDynamic.routeName: (_) => ButtonsPageDynamic(),
AccordionPage.routeName: (_) => AccordionPage(),
AlertPage.routeName: (_) => AlertPage(),
AppbarHomePage.routeName: (_) => AppbarHomePage(),
AvatarPage.routeName: (_) => AvatarPage(),
BadgesPage.routeName: (_) => BadgesPage(),
IconsButtonsPage.routeName: (_) => IconsButtonsPage(),
CardPage.routeName: (_) => CardPage(),
TabsPage.routeName: (_) => TabsPage(),
SegmentedTabPage.routeName: (_) => SegmentedTabPage(),
IconTabPage.routeName: (_) => IconTabPage(),
LabeledTabPage.routeName: (_) => LabeledTabPage(),
BottomIconTabPage.routeName: (_) => BottomIconTabPage(),
BottomLabeledTabPage.routeName: (_) => BottomLabeledTabPage(),
CarouselPage.routeName: (_) => CarouselPage(),
ToastPage.routeName: (_) => ToastPage(),
TogglePage.routeName: (_) => TogglePage()
},
),
debugShowCheckedModeBanner: false,
);
}
);
}
}
\ No newline at end of file
import 'dart:convert';
import 'package:flutter/foundation.dart';
import 'package:demo_package_ui_semantic/helpers/helpers.dart';
@immutable
class AuthModel {
final String? status;
final ResultAuthModel? data;
AuthModel({
this.status,
this.data,
});
AuthModel copyWith(ResultAuthModel data) =>
AuthModel(
status: this.status,
data: data
);
Map<String, dynamic> toMap() => {
"status": status,
"data": data == null ? null : data!.toMap(),
};
factory AuthModel.fromMap(Map<String, dynamic> json) {
Map checkResult = checkAPIResultStatus(json);
if (checkResult['error']) {
return AuthModel(
status: checkResult['message'],
data: null,
);
} else {
return AuthModel(
status: json['status'],
data: ResultAuthModel.fromJson(json["data"]),
);
}
}
String toJson() => json.encode(toMap());
factory AuthModel.fromJson(String source) => AuthModel.fromMap(json.decode(source));
@override
String toString() {
return 'AuthModel(status: $status, data: ${data!.toJson()})';
}
}
@immutable
class ResultAuthModel {
final int? userId;
final String? userName;
final String? isSa;
final String? active;
final String? token;
final String? email;
ResultAuthModel({
this.userId,
this.userName,
this.isSa,
this.active,
this.token,
this.email
});
ResultAuthModel copyWith(String email) =>
ResultAuthModel(
userId: this.userId,
userName: this.userName,
isSa: this.isSa,
active: this.active,
token: this.token,
email: this.email
);
Map<String, dynamic> toMap() => {
"user_id": userId,
"user_name": userName,
"is_sa": isSa,
"active": active,
"token": token,
"email": email
};
factory ResultAuthModel.fromMap(Map<dynamic, dynamic> json) => ResultAuthModel(
userId: json["user_id"],
userName: json["user_name"],
isSa: json["is_sa"],
active: json["active"],
token: json["token"],
email: json["email"]
);
String toJson() => json.encode(toMap());
factory ResultAuthModel.fromJson(Map<String, dynamic> source) => ResultAuthModel.fromMap(source);
@override
String toString() {
return 'ResultAuthModel(user_id: $userId, user_name: $userName, is_sa: $isSa, active: $active, token: $token, email: $email)';
}
}
class LoginParam {
final String? email;
final String? password;
final String? token;
final int? userId;
LoginParam({
this.email,
this.password,
this.token,
this.userId
});
}
\ No newline at end of file
export 'auth_model.dart';
\ No newline at end of file
part of 'repositories.dart';
class AuthRepository implements IAuth<AuthModel?, LoginParam> {
@override
void dispose() {}
@override
Future<void> init() async {}
@override
Future<AuthModel?> signIn(LoginParam? param) async {
AuthModel auth;
String url = '${SharedValue.api}/login/store';
String userAgent = await initUserAgentState();
var response = await http.post(Uri.parse(url), body: {
"email": param!.email,
"password": param.password
}, headers: {
"User-Agent" : userAgent
});
if (response.statusCode == 200) {
auth = AuthModel.fromJson(response.body);
} else {
final responseData = json.decode(response.body);
Map checkResult = checkAPIResultStatus(responseData);
if (checkResult['error']) {
throw AuthException(checkResult['message']);
}
throw AuthException('There was an error. Please try again');
}
return auth;
}
@override
Future<String> signOut(LoginParam? param) async {
String url = '${SharedValue.api}/logout?token=${param!.token}';
String userAgent = await initUserAgentState();
var response = await http.post(Uri.parse(url), body: {
"userId": param.userId.toString()
}, headers: {
"User-Agent" : userAgent
});
if (response.statusCode == 200) {
return '200';
} else {
return response.statusCode.toString();
}
}
@override
Future<AuthModel?> signUp(LoginParam? param) {
// TODO: implement signUp
throw UnimplementedError();
}
}
\ No newline at end of file
import 'dart:convert';
import 'dart:io';
import 'package:demo_package_ui_semantic/ui/pages/pages.dart';
import 'package:http/http.dart' as http;
import 'package:http_parser/http_parser.dart';
import 'package:states_rebuilder/states_rebuilder.dart';
import 'package:demo_package_ui_semantic/models/models.dart';
import 'package:demo_package_ui_semantic/helpers/helpers.dart';
part 'auth_repository.dart';
\ No newline at end of file
part of '../pages.dart';
final user = RM.injectAuth<AuthModel?, LoginParam>(
() => AuthRepository(),
persist: () => PersistState<AuthModel?>(
key: '__AuthModel__',
toJson: (user) => user!.toJson(),
fromJson: (json) {
final user = AuthModel.fromJson(json);
return user.data!.token != null ? user : null;
},
debugPrintOperations: true,
),
autoSignOut: (user) {
if (user!.data == null) {
return Duration(seconds: 5);
}
return Duration(days: 3);
},
onSetState: On.error(
(error, refresh) {
String err = checkError(error.toString());
showToastWidget(
err,
duration: 'long'
);
},
),
);
final RegExp _passwordRegExp = RegExp(
r'^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{8,}$',
);
final RegExp _emailRegExp = RegExp(
r'^[a-zA-Z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$',
);
final _email = RM.injectTextEditing(
validator: (email) {
if (!_emailRegExp.hasMatch(email!)) {
return "Enter a valid email";
}
},
);
final _password = RM.injectTextEditing(
validateOnTyping: true,
validator: (password) {
if (password!.length < 4) {
return "Enter a valid password";
}
},
);
final _form = RM.injectForm(
submit: () async {
await user.auth.signIn(
(_) => LoginParam(
email: _email.text,
password: _password.text,
),
onError: (error, refresh) {
showToastWidget(
error.message,
duration: 'long'
);
}
);
if (user.error != null) {
showToastWidget(
user.error.message,
duration: 'long'
);
}
},
);
class AuthException implements Exception {
final String message;
AuthException(this.message);
}
class LoginPage extends StatelessWidget {
const LoginPage({Key? key}) : super(key: key);
static const routeName = '/login_page';
@override
Widget build(BuildContext context) {
return Scaffold(
body: Padding(
padding: EdgeInsets.all(10),
child: On.form(
() => Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
TextField(
key: Key('__EmailField__'),
controller: _email.controller,
focusNode: _email.focusNode,
decoration: InputDecoration(
icon: Icon(Icons.email),
labelText: "Email",
errorText: _email.error,
),
keyboardType: TextInputType.emailAddress,
autocorrect: false,
onSubmitted: (_) {
_password.focusNode.requestFocus();
},
),
TextField(
key: Key('__PasswordField__'),
controller: _password.controller,
focusNode: _password.focusNode,
decoration: InputDecoration(
icon: Icon(Icons.lock),
labelText: "Password",
errorText: _password.error,
),
obscureText: true,
autocorrect: false,
onSubmitted: (_) {
_form.submitFocusNode.requestFocus();
},
),
SizedBox(height: 10),
On.formSubmission(
onSubmitting: () => const Center(
child: CircularProgressIndicator(),
),
child: ElevatedButton(
focusNode: _form.submitFocusNode,
child: Text("Sign in"),
onPressed: _form.submit,
),
).listenTo(_form),
SizedBox(height: 10),
SelectableText("email : ${SharedValue.email}"),
SelectableText("password : ${SharedValue.password}"),
],
),
).listenTo(_form)
)
);
}
}
\ No newline at end of file
......@@ -30,7 +30,7 @@ class _ButtonsPageDynamicState extends State<ButtonsPageDynamic> {
"leading": {
"widget": "InkWell",
"onTap": {
"func_name": "goToBack"
"function": "goToBack"
},
"child": {
"widget": "Container",
......@@ -52,7 +52,7 @@ class _ButtonsPageDynamicState extends State<ButtonsPageDynamic> {
{
"widget": "GestureDetector",
"onTap": {
"func_name": "goToStandardButtonPage"
"function": "goToStandardButtonPage"
},
"child": {
"widget": "Container",
......@@ -138,7 +138,7 @@ class _ButtonsPageDynamicState extends State<ButtonsPageDynamic> {
Future<Widget?> _buildWidget(BuildContext context) async {
try {
return WidgetParserBuilder.build(pageJson, context, ButtonsPageMethodListener());
return WidgetParserBuilder.build(pageJson, context, ButtonsPageMethodListener(), null);
} catch (e) {
String err = e.toString();
return _buildErrorPage("${err.split('.')[0]} ${err.split('.')[1]}");
......@@ -205,13 +205,16 @@ class _ButtonsPageDynamicState extends State<ButtonsPageDynamic> {
class ButtonsPageMethodListener extends MethodListener {
@override
void run(BuildContext context, Map<String, dynamic>? event) {
run(BuildContext context, Map<String, dynamic>? event) {
if (isFunctionNameExist(event)) {
if (event!['func_name'] == 'goToStandardButtonPage') {
if (event!['function'] == 'goToStandardButtonPage') {
Navigator.of(context).pushNamed(
StandardsButtonPage.routeName
);
} else if (event['func_name'] == 'goToBack') {
// if (isParametersExist(event)) {
// printWrapped(event['parameters']['tapDownDetails']);
// }
} else if (event['function'] == 'goToBack') {
Navigator.of(context).pop();
}
} else {
......
......@@ -106,7 +106,7 @@ class _MainPageState extends State<MainPage> {
},
"Static",
"Dynamic from JSON",
17,
16,
Icons.format_list_numbered,
Icons.dynamic_form
);
......@@ -128,7 +128,7 @@ class _MainPageState extends State<MainPage> {
children: <Widget>[
Text(
title,
style: const TextStyle(color: LLSColors.WHITE, fontSize: 18),
style: const TextStyle(color: LLSColors.WHITE, fontSize: 16),
)
],
),
......@@ -148,6 +148,9 @@ class _MainPageState extends State<MainPage> {
),
centerTitle: true,
automaticallyImplyLeading: false,
actions: [
const PopupActionsButton()
]
),
body: ListView(
physics: const ScrollPhysics(),
......@@ -187,7 +190,7 @@ class _MainPageState extends State<MainPage> {
},
"Static",
"Dynamic from JSON",
17,
16,
Icons.format_list_numbered,
Icons.dynamic_form
);
......
......@@ -3,9 +3,12 @@ import 'package:flutter/material.dart';
import 'package:llswidget/llswidget.dart';
import 'package:flutter/widgets.dart';
import 'package:widgetparser/widgetparser.dart';
import 'package:states_rebuilder/states_rebuilder.dart';
import 'package:demo_package_ui_semantic/ui/widgets/widgets.dart';
import 'package:demo_package_ui_semantic/helpers/helpers.dart';
import 'package:demo_package_ui_semantic/models/models.dart';
import 'package:demo_package_ui_semantic/repositories/repositories.dart';
part 'main_page.dart';
part 'buttons_page/buttons_page.dart';
......@@ -33,4 +36,5 @@ part 'tabs_page/bottom_icon_tab_page.dart';
part 'tabs_page/bottom_labeled_tab_page.dart';
part 'carousel_page.dart';
part 'toast_page.dart';
part 'toggle_page.dart';
\ No newline at end of file
part 'toggle_page.dart';
part 'auth/login_page.dart';
\ No newline at end of file
......@@ -30,7 +30,7 @@ class _TestStatePageState extends State<TestStatePage> {
"leading": {
"widget": "InkWell",
"onTap": {
"func_name": "goToBack"
"function": "goToBack"
},
"child": {
"widget": "Container",
......@@ -52,7 +52,7 @@ class _TestStatePageState extends State<TestStatePage> {
{
"widget": "GestureDetector",
"onTap": {
"func_name": "goToStandardButtonPage"
"function": "goToStandardButtonPage"
},
"child": {
"widget": "Container",
......@@ -96,7 +96,7 @@ class _TestStatePageState extends State<TestStatePage> {
Future<Widget?> _buildWidget(BuildContext context) async {
try {
return WidgetParserBuilder.build(pageJson, context, MethodListener());
return WidgetParserBuilder.build(pageJson, context, MethodListener(), null);
} catch (e) {
String err = e.toString();
print(err);
......
part of 'widgets.dart';
enum PopupAction {
home,
logout
}
final _extraAction = RM.inject(
() => PopupAction.home
);
class PopupActionsButton extends StatelessWidget {
const PopupActionsButton({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return On.data(
() {
return PopupMenuButton<PopupAction>(
onSelected: (action) async {
_extraAction.state = action;
if (action == PopupAction.logout) {
String? token = user.state!.data!.token;
int? userId = user.state!.data!.userId;
user.auth.signOut(
param: (_) {
return LoginParam(
token: token,
userId: userId,
);
},
onError: (error, refresh) {
showToastWidget(
error.message,
duration: 'long'
);
}
);
return;
}
},
itemBuilder: (BuildContext context) {
return <PopupMenuItem<PopupAction>>[
PopupMenuItem<PopupAction>(
key: Key('__logout__'),
value: PopupAction.logout,
child: Text("Logout"),
)
];
},
);
},
).listenTo(_extraAction);
}
}
import 'package:demo_package_ui_semantic/helpers/helpers.dart';
import 'package:demo_package_ui_semantic/models/models.dart';
import 'package:demo_package_ui_semantic/ui/pages/pages.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:states_rebuilder/states_rebuilder.dart';
part 'action_sheet.dart';
\ No newline at end of file
part 'action_sheet.dart';
part 'popup_menu.dart';
\ No newline at end of file
......@@ -7,7 +7,7 @@ packages:
name: args
url: "https://pub.dartlang.org"
source: hosted
version: "1.6.0"
version: "2.1.1"
async:
dependency: transitive
description:
......@@ -43,13 +43,6 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
cli_repl:
dependency: transitive
description:
name: cli_repl
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.2"
clock:
dependency: transitive
description:
......@@ -64,13 +57,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.15.0"
colorize:
crypto:
dependency: transitive
description:
name: colorize
name: crypto
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.0"
version: "3.0.1"
cupertino_icons:
dependency: "direct main"
description:
......@@ -78,13 +71,6 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.2"
dart2_constant:
dependency: transitive
description:
name: dart2_constant
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.2+dart2"
equatable:
dependency: "direct main"
description:
......@@ -99,20 +85,20 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
file:
ffi:
dependency: transitive
description:
name: file
name: ffi
url: "https://pub.dartlang.org"
source: hosted
version: "5.2.1"
fluri:
version: "1.1.2"
file:
dependency: transitive
description:
name: fluri
name: file
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.0"
version: "6.1.2"
flutter:
dependency: "direct main"
description: flutter
......@@ -139,6 +125,25 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
flutter_user_agent:
dependency: "direct main"
description:
name: flutter_user_agent
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.2"
flutter_web_plugins:
dependency: transitive
description: flutter
source: sdk
version: "0.0.0"
fluttertoast:
dependency: "direct main"
description:
name: fluttertoast
url: "https://pub.dartlang.org"
source: hosted
version: "8.0.7"
font_awesome_flutter:
dependency: transitive
description:
......@@ -146,27 +151,34 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "9.0.0"
glob:
dependency: transitive
hive:
dependency: "direct main"
description:
name: glob
name: hive
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
version: "2.0.4"
hive_flutter:
dependency: "direct main"
description:
name: hive_flutter
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
http:
dependency: "direct main"
description:
name: http
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.2"
version: "0.13.0"
http_parser:
dependency: transitive
description:
name: http_parser
url: "https://pub.dartlang.org"
source: hosted
version: "3.1.4"
version: "4.0.0"
intl:
dependency: transitive
description:
......@@ -181,20 +193,20 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "0.6.3"
json_pointer:
json_class:
dependency: transitive
description:
name: json_pointer
name: json_class
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.0"
json_schema:
version: "2.0.0+1"
json_schema2:
dependency: transitive
description:
name: json_schema
name: json_schema2
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.0"
version: "2.0.0+2"
llswidget:
dependency: "direct main"
description:
......@@ -208,7 +220,7 @@ packages:
name: logging
url: "https://pub.dartlang.org"
source: hosted
version: "0.11.4"
version: "1.0.1"
matcher:
dependency: transitive
description:
......@@ -223,55 +235,55 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.0"
mime:
nested:
dependency: transitive
description:
name: mime
name: nested
url: "https://pub.dartlang.org"
source: hosted
version: "0.9.7"
nested:
version: "1.0.0"
path:
dependency: transitive
description:
name: nested
name: path
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.0"
node_interop:
version: "1.8.0"
path_provider:
dependency: transitive
description:
name: node_interop
name: path_provider
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.1"
node_io:
version: "2.0.2"
path_provider_linux:
dependency: transitive
description:
name: node_io
name: path_provider_linux
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
package_config:
version: "2.0.0"
path_provider_macos:
dependency: transitive
description:
name: package_config
name: path_provider_macos
url: "https://pub.dartlang.org"
source: hosted
version: "1.9.3"
package_resolver:
version: "2.0.0"
path_provider_platform_interface:
dependency: transitive
description:
name: package_resolver
name: path_provider_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.10"
path:
version: "2.0.1"
path_provider_windows:
dependency: transitive
description:
name: path
name: path_provider_windows
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.0"
version: "2.0.1"
pedantic:
dependency: transitive
description:
......@@ -279,6 +291,27 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.11.0"
platform:
dependency: transitive
description:
name: platform
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.0"
plugin_platform_interface:
dependency: transitive
description:
name: plugin_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.0"
process:
dependency: transitive
description:
name: process
url: "https://pub.dartlang.org"
source: hosted
version: "4.2.1"
provider:
dependency: transitive
description:
......@@ -292,7 +325,7 @@ packages:
name: quiver
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.5"
version: "3.0.1"
responsive_framework:
dependency: "direct main"
description:
......@@ -300,41 +333,18 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.0"
sass:
rest_client:
dependency: transitive
description:
name: sass
name: rest_client
url: "https://pub.dartlang.org"
source: hosted
version: "1.32.8"
version: "2.0.1+2"
sky_engine:
dependency: transitive
description: flutter
source: sdk
version: "0.0.99"
sockjs_client:
dependency: transitive
description:
path: "."
ref: "0.3.5"
resolved-ref: "2e8dc8d2fe8486d31b6e220277c94d746ced1691"
url: "git://github.com/Workiva/sockjs-dart-client.git"
source: git
version: "0.3.5"
sockjs_client_wrapper:
dependency: transitive
description:
name: sockjs_client_wrapper
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
source_maps:
dependency: transitive
description:
name: source_maps
url: "https://pub.dartlang.org"
source: hosted
version: "0.10.10"
source_span:
dependency: transitive
description:
......@@ -349,20 +359,20 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.10.0"
stream_channel:
dependency: transitive
states_rebuilder:
dependency: "direct main"
description:
name: stream_channel
name: states_rebuilder
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0"
stream_transform:
version: "4.3.0"
stream_channel:
dependency: transitive
description:
name: stream_transform
name: stream_channel
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.0"
version: "2.1.0"
string_scanner:
dependency: transitive
description:
......@@ -384,13 +394,6 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.19"
tuple:
dependency: transitive
description:
name: tuple
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.3"
typed_data:
dependency: transitive
description:
......@@ -404,42 +407,42 @@ packages:
name: uri
url: "https://pub.dartlang.org"
source: hosted
version: "0.11.4"
vector_math:
version: "1.0.0"
uuid:
dependency: transitive
description:
name: vector_math
name: uuid
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0"
w_common:
version: "3.0.4"
vector_math:
dependency: transitive
description:
name: w_common
name: vector_math
url: "https://pub.dartlang.org"
source: hosted
version: "1.20.4"
w_transport:
version: "2.1.0"
widgetparser:
dependency: "direct main"
description:
path: "../../widgetparser"
relative: true
source: path
version: "0.0.1"
win32:
dependency: transitive
description:
name: w_transport
name: win32
url: "https://pub.dartlang.org"
source: hosted
version: "3.2.8"
watcher:
version: "2.0.5"
xdg_directories:
dependency: transitive
description:
name: watcher
name: xdg_directories
url: "https://pub.dartlang.org"
source: hosted
version: "0.9.7+15"
widgetparser:
dependency: "direct main"
description:
path: "../../widgetparser"
relative: true
source: path
version: "0.0.1"
version: "0.2.0"
sdks:
dart: ">=2.12.0 <3.0.0"
flutter: ">=1.17.0"
flutter: ">=1.20.0"
......@@ -30,8 +30,12 @@ dependencies:
path: ../../widgetparser
flutter_bloc: 7.0.1
equatable: 1.1.1
http: 0.12.2
http: 0.13.0
states_rebuilder: 4.3.0
fluttertoast: 8.0.7
flutter_user_agent: 1.2.2
hive: 2.0.4
hive_flutter: 1.1.0
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
......
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