padmanto
3 years ago
10 changed files with 200 additions and 135 deletions
@ -0,0 +1,34 @@
|
||||
# lib/provider/local_auth_provider.dart |
||||
provider for accessing current token |
||||
```dart |
||||
void redirectToHome() { |
||||
html.window.location.href = "/one-ui/"; |
||||
} |
||||
|
||||
final localAuthProvider = Provider<OneLocalUserModel?>((ref) { |
||||
try { |
||||
String? user = getUser(); |
||||
String? token = getToken(); |
||||
if (user != null) { |
||||
final localUser = OneLocalUserModel.fromJson(jsonDecode(user)); |
||||
localUser.token = token; |
||||
return localUser; |
||||
} |
||||
} catch (_) {} |
||||
return null; |
||||
}); |
||||
``` |
||||
|
||||
```dart |
||||
import 'package:js/js.dart'; |
||||
// ignore: avoid_web_libraries_in_flutter |
||||
import 'dart:html' as html; |
||||
|
||||
String? getToken() { |
||||
return html.window.localStorage['token']; |
||||
} |
||||
String? getUser() { |
||||
return html.window.localStorage['user']; |
||||
} |
||||
``` |
||||
|
@ -1,4 +1,14 @@
|
||||
import 'package:js/js.dart'; |
||||
// ignore: avoid_web_libraries_in_flutter |
||||
import 'dart:html' as html; |
||||
|
||||
@JS('fx_initial_route') |
||||
external String fxInitialRoute(); |
||||
|
||||
String? getToken() { |
||||
return html.window.localStorage['token']; |
||||
} |
||||
|
||||
String? getUser() { |
||||
return html.window.localStorage['user']; |
||||
} |
||||
|
@ -0,0 +1,58 @@
|
||||
class OneLocalUserModel { |
||||
late String mUserID; |
||||
late String mUserUsername; |
||||
late String mUserGroupDashboard; |
||||
late String mUserDefaultTSampleStationID; |
||||
late String mStaffName; |
||||
late String isCourier; |
||||
late String ip; |
||||
late String agent; |
||||
late String version; |
||||
late String lastLogin; |
||||
late int? mSatelliteID; |
||||
String? token; |
||||
|
||||
OneLocalUserModel({ |
||||
required this.mUserID, |
||||
required this.mUserUsername, |
||||
required this.mUserGroupDashboard, |
||||
required this.mUserDefaultTSampleStationID, |
||||
required this.mStaffName, |
||||
required this.isCourier, |
||||
required this.ip, |
||||
required this.agent, |
||||
required this.version, |
||||
required this.lastLogin, |
||||
this.mSatelliteID, |
||||
}); |
||||
|
||||
OneLocalUserModel.fromJson(Map<String, dynamic> json) { |
||||
mUserID = json['M_UserID']; |
||||
mUserUsername = json['M_UserUsername']; |
||||
mUserGroupDashboard = json['M_UserGroupDashboard']; |
||||
mUserDefaultTSampleStationID = json['M_UserDefaultT_SampleStationID']; |
||||
mStaffName = json['M_StaffName']; |
||||
isCourier = json['is_courier']; |
||||
ip = json['ip']; |
||||
agent = json['agent']; |
||||
version = json['version']; |
||||
lastLogin = json['last-login']; |
||||
mSatelliteID = json['M_SatelliteID']; |
||||
} |
||||
|
||||
Map<String, dynamic> toJson() { |
||||
final Map<String, dynamic> data = <String, dynamic>{}; |
||||
data['M_UserID'] = mUserID; |
||||
data['M_UserUsername'] = mUserUsername; |
||||
data['M_UserGroupDashboard'] = mUserGroupDashboard; |
||||
data['M_UserDefaultT_SampleStationID'] = mUserDefaultTSampleStationID; |
||||
data['M_StaffName'] = mStaffName; |
||||
data['is_courier'] = isCourier; |
||||
data['ip'] = ip; |
||||
data['agent'] = agent; |
||||
data['version'] = version; |
||||
data['last-login'] = lastLogin; |
||||
data['M_SatelliteID'] = mSatelliteID; |
||||
return data; |
||||
} |
||||
} |
@ -0,0 +1,25 @@
|
||||
import 'dart:convert'; |
||||
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart'; |
||||
|
||||
import '../js/initial_route.dart'; |
||||
import '../model/one_user_model.dart'; |
||||
// ignore: avoid_web_libraries_in_flutter |
||||
import 'dart:html' as html; |
||||
|
||||
void redirectToHome() { |
||||
html.window.location.href = "/one-ui/"; |
||||
} |
||||
|
||||
final localAuthProvider = Provider<OneLocalUserModel?>((ref) { |
||||
try { |
||||
String? user = getUser(); |
||||
String? token = getToken(); |
||||
if (user != null) { |
||||
final localUser = OneLocalUserModel.fromJson(jsonDecode(user)); |
||||
localUser.token = token; |
||||
return localUser; |
||||
} |
||||
} catch (_) {} |
||||
return null; |
||||
}); |
Loading…
Reference in new issue