部分登录
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
17
lib/common/manager/hive_manager.dart
Normal file
17
lib/common/manager/hive_manager.dart
Normal file
@@ -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
|
||||
|
||||
119
lib/login/login_view.dart
Normal file
119
lib/login/login_view.dart
Normal file
@@ -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: [
|
||||
|
||||
Reference in New Issue
Block a user