add hive support

hmxc
小赖 4 years ago
parent 0653eb1625
commit 74a592a150

@ -10,5 +10,5 @@ class _Login {
String get sendSMSCode => '/login/sendMMSLogin';
///
String get loginBySMS => 'login/loginSMSUser';
String get loginBySMS => '/login/loginSMSUser';
}

@ -1,23 +1,27 @@
import 'package:akuCommunity/pages/splash/splash_page.dart';
import 'package:akuCommunity/pages/tab_navigator.dart';
import 'package:akuCommunity/provider/user_provider.dart';
import 'package:akuCommunity/utils/developer_util.dart';
import 'package:amap_map_fluttify/amap_map_fluttify.dart';
import 'package:akuCommunity/utils/hive_store.dart';
import 'package:amap_location_fluttify/amap_location_fluttify.dart';
import 'package:ani_route/ani_route.dart';
import 'package:bot_toast/bot_toast.dart';
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
import 'package:fluwx/fluwx.dart';
import 'package:get/get.dart';
import 'package:hive/hive.dart';
import 'package:hive_flutter/hive_flutter.dart';
import 'package:provider/provider.dart';
import 'package:akuCommunity/provider/cart.dart';
import 'package:flutter_picker/flutter_picker.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
void main() {
void main() async {
WidgetsFlutterBinding.ensureInitialized();
ARoute.init(true);
await Hive.initFlutter();
await HiveStore.init();
AmapLocation.instance.init(iosKey: 'ios key');
DeveloperUtil.setDev(true);
runApp(MyApp());

@ -1,6 +1,7 @@
import 'package:akuCommunity/constants/api.dart';
import 'package:akuCommunity/utils/network/base_model.dart';
import 'package:akuCommunity/utils/network/net_util.dart';
import 'package:bot_toast/bot_toast.dart';
import 'package:dio/dio.dart';
class SignFunc {
@ -13,11 +14,11 @@ class SignFunc {
return baseModel;
}
static Future<String> login(String phone, String code) async {
static Future<Response> login(String phone, String code) async {
Response response = await NetUtil().dio.post(
API.login.loginBySMS,
data: {'tel': phone, 'code': code},
);
return response.data['token'];
return response;
}
}

@ -1,16 +1,15 @@
import 'dart:async';
import 'dart:math';
import 'dart:ui';
import 'package:akuCommunity/pages/setting_page/agreement_page/agreement_page.dart';
import 'package:akuCommunity/pages/setting_page/agreement_page/privacy_page.dart';
import 'package:akuCommunity/pages/sign/sign_func.dart';
import 'package:akuCommunity/pages/sign/user_authentication_page.dart';
import 'package:akuCommunity/extensions/num_ext.dart';
import 'package:akuCommunity/const/resource.dart';
import 'package:ani_route/ani_route.dart';
import 'package:bot_toast/bot_toast.dart';
import 'package:common_utils/common_utils.dart';
import 'package:dio/dio.dart';
import 'package:flustars/flustars.dart' show TextUtil;
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
@ -18,7 +17,7 @@ import 'package:akuCommunity/utils/headers.dart';
import 'package:akuCommunity/base/base_style.dart';
import 'package:akuCommunity/base/assets_image.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:get/get.dart' hide Response;
import 'package:velocity_x/velocity_x.dart';
class SignInPage extends StatefulWidget {
@ -52,67 +51,62 @@ class _SignInPageState extends State<SignInPage> {
);
}
InkWell _inkWellLogin() {
return InkWell(
onTap: () {
if (TextUtil.isEmpty(_phone.text))
BotToast.showText(text: '手机号不能为空');
else if (TextUtil.isEmpty(_code.text))
BotToast.showText(text: '验证码不能为空');
else {
showCupertinoDialog(
context: context,
builder: (context) {
return CupertinoAlertDialog(
title: Text('点击登录即表示您已阅读并同意'),
content: Text(
'''点击登录即表示您已阅读并同意《小蜜蜂用户协议》《小蜜蜂隐私政策》(特别是免除或限制责任、管辖等粗体下划线标注的条款)。如您不同意上述协议的任何条款,您应立即停止登录及使用本软件及服务。'''),
actions: [
CupertinoDialogAction(
child: Text('同意'),
onPressed: () {
Future.delayed(
Duration(milliseconds: 1000 + Random().nextInt(500)),
() {
Get.back();
(_phone.text == '18067170899') &&
(_code.text == '123456')
? ARoute.push(context, UserAuthenticationPage())
: BotToast.showText(text: '账号或密码错误!');
},
);
},
),
CupertinoDialogAction(
child: Text('拒绝'),
onPressed: () {
Get.back();
},
),
],
);
},
);
}
Future<bool> _showLoginVerify() async {
return await showCupertinoDialog(
barrierDismissible: false,
context: context,
builder: (context) {
return CupertinoAlertDialog(
title: Text('点击登录即表示您已阅读并同意'),
content: Text(
'''点击登录即表示您已阅读并同意《小蜜蜂用户协议》《小蜜蜂隐私政策》(特别是免除或限制责任、管辖等粗体下划线标注的条款)。如您不同意上述协议的任何条款,您应立即停止登录及使用本软件及服务。'''),
actions: [
CupertinoDialogAction(
child: Text('同意'),
onPressed: () => Get.back(result: true),
),
CupertinoDialogAction(
child: Text('拒绝'),
onPressed: () => Get.back(result: false),
),
],
);
},
child: Container(
alignment: Alignment.center,
);
}
_parseLogin(bool result) async {
if (!result) return;
BotToast.showLoading();
Response response = await SignFunc.login(_phone.text, _code.text);
BotToast.cleanAll();
if (response.data['status']) {
} else {
BotToast.showText(text: response.data['message']);
}
}
Widget _inkWellLogin() {
return Padding(
padding: EdgeInsets.symmetric(horizontal: 80.w),
child: MaterialButton(
onPressed: () async {
if (TextUtil.isEmpty(_phone.text))
BotToast.showText(text: '手机号不能为空');
else if (TextUtil.isEmpty(_code.text))
BotToast.showText(text: '验证码不能为空');
else {
bool result = await _showLoginVerify();
_parseLogin(result);
}
},
height: 89.w,
width: 586.w,
padding: EdgeInsets.only(top: 25.w, bottom: 24.w),
margin: EdgeInsets.symmetric(horizontal: 82.w),
decoration: BoxDecoration(
color: Color(0xffffc40c),
borderRadius: BorderRadius.all(Radius.circular(36)),
),
child: Text(
'登录',
style: TextStyle(
fontWeight: FontWeight.w600,
fontSize: BaseStyle.fontSize28,
color: ktextPrimary,
),
),
shape: StadiumBorder(),
elevation: 0,
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
child: '登陆'.text.bold.size(28.sp).color(ktextPrimary).make(),
color: kPrimaryColor,
),
);
}

@ -1,10 +1,30 @@
import 'package:akuCommunity/utils/hive_store.dart';
import 'package:flutter/material.dart';
class UserProvider extends ChangeNotifier{
class UserProvider extends ChangeNotifier {
//
bool _isSigned =false;
bool _isSigned = false;
get isSigned => _isSigned;
setisSigned(bool state){
_isSigned=state;
setisSigned(bool state) {
_isSigned = state;
notifyListeners();
}
}
bool _isLogin = false;
bool get isLogin => _isLogin;
setLogin(bool state, String token) {
_isLogin = state;
HiveStore.appBox.put('token', token);
notifyListeners();
}
logout() {
_isLogin = false;
_token = null;
HiveStore.appBox.delete('token');
notifyListeners();
}
String _token;
String get token => _token ?? '';
}

@ -0,0 +1,9 @@
import 'package:hive/hive.dart';
class HiveStore {
static Box _appBox;
static Box get appBox => _appBox;
static init() async {
_appBox = await Hive.openBox('app');
}
}
Loading…
Cancel
Save