部分登录
This commit is contained in:
parent
0f3e728a79
commit
b84d8477c0
|
|
@ -1,10 +1,57 @@
|
|||
import 'package:cashier_reserve/login/login_view.dart';
|
||||
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
import '../base/ui.dart';
|
||||
import '../channel/channel_event.dart';
|
||||
import '../utils/func_tools.dart';
|
||||
import 'hive_manager.dart';
|
||||
|
||||
class AppManager {
|
||||
static BuildContext? globalContext;
|
||||
static bool _isAlertLogin = false;
|
||||
|
||||
static Future<void> initThirdPackage() async {
|
||||
MyEventChannel.startListener();
|
||||
|
||||
await HiveManager.initHive();
|
||||
}
|
||||
}
|
||||
|
||||
static void setGlobalContext(BuildContext context) {
|
||||
globalContext = context;
|
||||
}
|
||||
|
||||
static bool isLogin() {
|
||||
String token = HiveManager.getUserToken();
|
||||
if (isEmptyString(token)) {
|
||||
gotoLogin();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static void gotoLogin() {
|
||||
if (_isAlertLogin) {
|
||||
return;
|
||||
}
|
||||
_isAlertLogin = true;
|
||||
|
||||
while (Navigator.of(globalContext!).canPop()) {
|
||||
Navigator.of(globalContext!).pop();
|
||||
}
|
||||
|
||||
showDialog(
|
||||
context: globalContext!,
|
||||
barrierDismissible: false,
|
||||
builder: (BuildContext context) {
|
||||
return WillPopScope(
|
||||
onWillPop: () => Future.value(false), child: const LoginView());
|
||||
});
|
||||
}
|
||||
|
||||
static void disposeLoginWidget() {
|
||||
_isAlertLogin = false;
|
||||
}
|
||||
|
||||
static bool isShowLoginView() {
|
||||
return _isAlertLogin;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,17 @@
|
|||
import 'package:hive/hive.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
|
||||
class HiveManager {
|
||||
static Box? _userInfoBox;
|
||||
|
||||
static Future<void> initHive() async {
|
||||
final dir = await getApplicationDocumentsDirectory();
|
||||
Hive.defaultDirectory = dir.path;
|
||||
|
||||
_userInfoBox = Hive.box();
|
||||
}
|
||||
|
||||
static String getUserToken() {
|
||||
return _userInfoBox?.get('token') ?? '';
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,7 @@
|
|||
import 'package:cashier_reserve/common/base/ui.dart';
|
||||
import 'package:cashier_reserve/common/base/ui_model.dart';
|
||||
import 'package:cashier_reserve/common/manager/app_manager.dart';
|
||||
import 'package:cashier_reserve/common/print/print.dart';
|
||||
|
||||
class HomeViewModel extends BaseUIModel {
|
||||
int _currentIndex = 0;
|
||||
|
|
@ -37,6 +39,15 @@ class HomeViewModel extends BaseUIModel {
|
|||
|
||||
HomeViewModel() {
|
||||
_pageController = PageController(initialPage: 0);
|
||||
|
||||
Future.delayed(const Duration(milliseconds: 700), () {
|
||||
_checkLogin();
|
||||
});
|
||||
}
|
||||
|
||||
_checkLogin() {
|
||||
bool flag = AppManager.isLogin();
|
||||
yjPrint("is login $flag");
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
|
|||
|
|
@ -0,0 +1,119 @@
|
|||
import 'package:cashier_reserve/common/print/print.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class LoginView extends StatefulWidget {
|
||||
const LoginView({super.key});
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() {
|
||||
return _LoginViewState();
|
||||
}
|
||||
}
|
||||
|
||||
class _LoginViewState extends State<LoginView> {
|
||||
String loginType = "merchant";
|
||||
int segmentIndex = 0;
|
||||
|
||||
TextEditingController merchantText = TextEditingController();
|
||||
TextEditingController accountText = TextEditingController();
|
||||
TextEditingController passwordText = TextEditingController();
|
||||
TextEditingController codeText = TextEditingController();
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
merchantText.dispose();
|
||||
accountText.dispose();
|
||||
passwordText.dispose();
|
||||
codeText.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
width: MediaQuery.of(context).size.width,
|
||||
height: MediaQuery.of(context).size.height,
|
||||
color: const Color(0x55000000),
|
||||
child: Center(
|
||||
child: Container(
|
||||
padding: const EdgeInsets.fromLTRB(30, 30, 30, 30),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
width: 400,
|
||||
height: 400,
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text(
|
||||
"银收客订餐系统",
|
||||
style: TextStyle(
|
||||
fontSize: 25,
|
||||
color: Color(0xff333333),
|
||||
decoration: TextDecoration.none),
|
||||
)
|
||||
],
|
||||
),
|
||||
const SizedBox(
|
||||
height: 30,
|
||||
),
|
||||
CupertinoSegmentedControl(
|
||||
//子标签
|
||||
children: {
|
||||
0: Container(
|
||||
width: 60,
|
||||
height: 30,
|
||||
alignment: Alignment.center,
|
||||
child: const Text(
|
||||
"商户",
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
// color: Color(0xff333333),
|
||||
decoration: TextDecoration.none),
|
||||
),
|
||||
),
|
||||
1: Container(
|
||||
width: 60,
|
||||
height: 30,
|
||||
alignment: Alignment.center,
|
||||
child: const Text(
|
||||
"员工",
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
// color: Color(0xff333333),
|
||||
decoration: TextDecoration.none),
|
||||
),
|
||||
),
|
||||
},
|
||||
//当前选中的索引
|
||||
groupValue: segmentIndex,
|
||||
//点击回调
|
||||
onValueChanged: (int index) {
|
||||
setState(() {
|
||||
segmentIndex = index;
|
||||
loginType = index == 0 ? "merchant" : "staff";
|
||||
});
|
||||
},
|
||||
selectedColor: Colors.blue,
|
||||
borderColor: Colors.blue,
|
||||
unselectedColor: Colors.white,
|
||||
),
|
||||
const SizedBox(
|
||||
height: 5,
|
||||
),
|
||||
// TextField(
|
||||
// controller: merchantText,
|
||||
// )
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
import 'package:cashier_reserve/common/manager/app_manager.dart';
|
||||
import 'package:cashier_reserve/home/home_view.dart';
|
||||
import 'package:cashier_reserve/home/home_view_model.dart';
|
||||
|
||||
|
|
@ -23,6 +24,7 @@ class _RootView extends State<RootView>
|
|||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
AppManager.setGlobalContext(context);
|
||||
super.build(context);
|
||||
return MultiProvider(
|
||||
providers: [
|
||||
|
|
|
|||
151
pubspec.lock
151
pubspec.lock
|
|
@ -1,6 +1,35 @@
|
|||
# Generated by pub
|
||||
# See https://dart.dev/tools/pub/glossary#lockfile
|
||||
packages:
|
||||
_fe_analyzer_shared:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: _fe_analyzer_shared
|
||||
sha256: f256b0c0ba6c7577c15e2e4e114755640a875e885099367bf6e012b19314c834
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "72.0.0"
|
||||
_macros:
|
||||
dependency: transitive
|
||||
description: dart
|
||||
source: sdk
|
||||
version: "0.3.2"
|
||||
analyzer:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: analyzer
|
||||
sha256: b652861553cd3990d8ed361f7979dc6d7053a9ac8843fa73820ab68ce5410139
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "6.7.0"
|
||||
args:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: args
|
||||
sha256: bf9f5caeea8d8fe6721a9c358dd8a5c1947b27f1cfaa18b39c301273594919e6
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "2.6.0"
|
||||
async:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
@ -17,6 +46,14 @@ packages:
|
|||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "2.1.1"
|
||||
build:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: build
|
||||
sha256: "80184af8b6cb3e5c1c4ec6d8544d27711700bc3e6d2efad04238c7b5290889f0"
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "2.4.1"
|
||||
cached_network_image:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
|
|
@ -65,6 +102,14 @@ packages:
|
|||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "1.18.0"
|
||||
convert:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: convert
|
||||
sha256: b30acd5944035672bc15c6b7a8b47d773e41e2f17de064350988c5d02adb1c68
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "3.1.2"
|
||||
crypto:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
@ -81,6 +126,14 @@ packages:
|
|||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "1.0.8"
|
||||
dart_style:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: dart_style
|
||||
sha256: "7856d364b589d1f08986e140938578ed36ed948581fbc3bc9aef1805039ac5ab"
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "2.3.7"
|
||||
dio:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
|
|
@ -168,6 +221,22 @@ packages:
|
|||
description: flutter
|
||||
source: sdk
|
||||
version: "0.0.0"
|
||||
glob:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: glob
|
||||
sha256: "0e7014b3b7d4dac1ca4d6114f82bf1782ee86745b9b42a92c9289c23d8a0ab63"
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "2.1.2"
|
||||
hive:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: hive
|
||||
sha256: "10819524df282842ebae12870e2e0e9ebc3e5c4637bec741ad39b919c589cb20"
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "4.0.0-dev.2"
|
||||
http:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
@ -192,6 +261,30 @@ packages:
|
|||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "0.19.0"
|
||||
isar:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: isar
|
||||
sha256: ebf74d87c400bd9f7da14acb31932b50c2407edbbd40930da3a6c2a8143f85a8
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "4.0.0-dev.14"
|
||||
isar_flutter_libs:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: isar_flutter_libs
|
||||
sha256: "04a3f4035e213ddb6e78d0132a7c80296a085c2088c2a761b4a42ee5add36983"
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "4.0.0-dev.14"
|
||||
js:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: js
|
||||
sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "0.6.7"
|
||||
leak_tracker:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
@ -224,6 +317,22 @@ packages:
|
|||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "4.0.0"
|
||||
logging:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: logging
|
||||
sha256: c8245ada5f1717ed44271ed1c26b8ce85ca3228fd2ffdb75468ab01979309d61
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "1.3.0"
|
||||
macros:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: macros
|
||||
sha256: "0acaed5d6b7eab89f63350bccd82119e6c602df0f391260d0e32b5e23db79536"
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "0.1.2-main.4"
|
||||
matcher:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
@ -264,6 +373,14 @@ packages:
|
|||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "2.1.0"
|
||||
package_config:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: package_config
|
||||
sha256: "1c5b77ccc91e4823a5af61ee74e6b972db1ef98c2ff5a18d3161c982a55448bd"
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "2.1.0"
|
||||
path:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
@ -273,7 +390,7 @@ packages:
|
|||
source: hosted
|
||||
version: "1.9.0"
|
||||
path_provider:
|
||||
dependency: transitive
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: path_provider
|
||||
sha256: "50c5dd5b6e1aaf6fb3a78b33f6aa3afca52bf903a8a5298f53101fdaee55bbcd"
|
||||
|
|
@ -352,6 +469,14 @@ packages:
|
|||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "6.1.2"
|
||||
pub_semver:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: pub_semver
|
||||
sha256: "40d3ab1bbd474c4c2328c91e3a7df8c6dd629b79ece4c4bd04bee496a224fb0c"
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "2.1.4"
|
||||
rxdart:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
@ -365,6 +490,14 @@ packages:
|
|||
description: flutter
|
||||
source: sdk
|
||||
version: "0.0.99"
|
||||
source_gen:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: source_gen
|
||||
sha256: "14658ba5f669685cd3d63701d01b31ea748310f7ab854e471962670abcf57832"
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "1.5.0"
|
||||
source_span:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
@ -509,6 +642,14 @@ packages:
|
|||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "14.2.5"
|
||||
watcher:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: watcher
|
||||
sha256: "3d2ad6751b3c16cf07c7fca317a1413b3f26530319181b37e3b9039b84fc01d8"
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "1.1.0"
|
||||
web:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
@ -525,6 +666,14 @@ packages:
|
|||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "1.1.0"
|
||||
yaml:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: yaml
|
||||
sha256: "75769501ea3489fca56601ff33454fe45507ea3bfb014161abc3b43ae25989d5"
|
||||
url: "https://pub.flutter-io.cn"
|
||||
source: hosted
|
||||
version: "3.1.2"
|
||||
sdks:
|
||||
dart: ">=3.5.4 <4.0.0"
|
||||
flutter: ">=3.24.0"
|
||||
|
|
|
|||
|
|
@ -42,6 +42,9 @@ dependencies:
|
|||
timeago: ^3.7.0
|
||||
percent_indicator: ^4.0.1
|
||||
event_bus: ^2.0.1
|
||||
hive: ^4.0.0-dev.2
|
||||
isar_flutter_libs: ^4.0.0-dev.13
|
||||
path_provider: ^2.1.0
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
|
|
|
|||
Loading…
Reference in New Issue