张萌 4 years ago
commit dceada58f6

@ -1,9 +1,14 @@
class API { class API {
static const String host = 'http://192.168.31.129:9001/app'; static const String host = 'http://192.168.2.201:8804/IntelligentCommunity';
static String get resource => '$host/static';
static const int networkTimeOut = 10000; static const int networkTimeOut = 10000;
static _Login login = _Login(); static _Login login = _Login();
} }
class _Login { class _Login {
String get a => ''; ///
String get sendSMSCode => '/login/sendMMSLogin';
///
String get loginBySMS => '/login/loginSMSUser';
} }

@ -1,7 +1,6 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
extension PageExt on Widget{ extension PageExt on Widget {
Function get to => (){Get.to(this);}; Function get to => () => Get.to(this);
} }

@ -1,22 +1,27 @@
import 'package:akuCommunity/pages/tab_navigator.dart'; import 'package:akuCommunity/pages/splash/splash_page.dart';
import 'package:akuCommunity/provider/user_provider.dart'; import 'package:akuCommunity/provider/user_provider.dart';
import 'package:akuCommunity/utils/developer_util.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:ani_route/ani_route.dart';
import 'package:bot_toast/bot_toast.dart'; import 'package:bot_toast/bot_toast.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:fluwx/fluwx.dart'; import 'package:fluwx/fluwx.dart';
import 'package:get/get.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:provider/provider.dart';
import 'package:akuCommunity/provider/cart.dart'; import 'package:akuCommunity/provider/cart.dart';
import 'package:flutter_picker/flutter_picker.dart'; import 'package:flutter_picker/flutter_picker.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart'; import 'package:pull_to_refresh/pull_to_refresh.dart';
import 'package:flutter_localizations/flutter_localizations.dart'; import 'package:flutter_localizations/flutter_localizations.dart';
void main() { void main() async {
WidgetsFlutterBinding.ensureInitialized(); WidgetsFlutterBinding.ensureInitialized();
ARoute.init(true); ARoute.init(true);
await Hive.initFlutter();
await HiveStore.init();
AmapLocation.instance.init(iosKey: 'ios key'); AmapLocation.instance.init(iosKey: 'ios key');
DeveloperUtil.setDev(true); DeveloperUtil.setDev(true);
runApp(MyApp()); runApp(MyApp());
@ -50,7 +55,7 @@ class _MyAppState extends State<MyApp> {
primarySwatch: Colors.yellow, primarySwatch: Colors.yellow,
visualDensity: VisualDensity.adaptivePlatformDensity, visualDensity: VisualDensity.adaptivePlatformDensity,
), ),
home: TabNavigator(), home: SplashPage(),
// //
localizationsDelegates: [ localizationsDelegates: [
PickerLocalizationsDelegate.delegate, PickerLocalizationsDelegate.delegate,

@ -0,0 +1,64 @@
class UserInfoModel {
Data data;
String message;
bool status;
UserInfoModel({this.data, this.message, this.status});
UserInfoModel.fromJson(Map<String, dynamic> json) {
data = json['data'] != null ? new Data.fromJson(json['data']) : null;
message = json['message'];
status = json['status'];
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
if (this.data != null) {
data['data'] = this.data.toJson();
}
data['message'] = this.message;
data['status'] = this.status;
return data;
}
}
class Data {
int id;
List<String> imgUrls;
String name;
String nickName;
String tel;
int sex;
String birthday;
Data(
{this.id,
this.imgUrls,
this.name,
this.nickName,
this.tel,
this.sex,
this.birthday});
Data.fromJson(Map<String, dynamic> json) {
id = json['id'];
imgUrls = json['imgUrls'].cast<String>();
name = json['name'];
nickName = json['nickName'];
tel = json['tel'];
sex = json['sex'];
birthday = json['birthday'];
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['id'] = this.id;
data['imgUrls'] = this.imgUrls;
data['name'] = this.name;
data['nickName'] = this.nickName;
data['tel'] = this.tel;
data['sex'] = this.sex;
data['birthday'] = this.birthday;
return data;
}
}

@ -11,7 +11,7 @@ import 'package:akuCommunity/pages/things_page/fixed_submit_page.dart';
import 'package:akuCommunity/pages/visitor_access_page/visitor_access_page.dart'; import 'package:akuCommunity/pages/visitor_access_page/visitor_access_page.dart';
import 'package:akuCommunity/painters/user_bottom_bar_painter.dart'; import 'package:akuCommunity/painters/user_bottom_bar_painter.dart';
import 'package:akuCommunity/provider/user_provider.dart'; import 'package:akuCommunity/provider/user_provider.dart';
import 'package:akuCommunity/utils/net_util.dart'; import 'package:akuCommunity/utils/network/net_util.dart';
import 'package:akuCommunity/widget/grid_buttons.dart'; import 'package:akuCommunity/widget/grid_buttons.dart';
import 'package:ani_route/ani_route.dart'; import 'package:ani_route/ani_route.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
@ -137,8 +137,7 @@ class _PersonalIndexState extends State<PersonalIndex>
), ),
InkWell( InkWell(
onTap: () { onTap: () {
if (!userProvider.isSigned) if (!userProvider.isSigned) SignInPage().to();
ARoute.push(context, SignInPage());
}, },
child: Container( child: Container(
margin: EdgeInsets.only(left: 16.w), margin: EdgeInsets.only(left: 16.w),

@ -0,0 +1,24 @@
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 {
static Future sendMessageCode(String phone) async {
BaseModel baseModel = await NetUtil().post(
API.login.sendSMSCode,
params: {'tel': phone},
showMessage: true,
);
return baseModel;
}
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;
}
}

@ -1,15 +1,15 @@
import 'dart:async'; import 'dart:async';
import 'dart:math';
import 'dart:ui'; import 'dart:ui';
import 'package:akuCommunity/pages/setting_page/agreement_page/agreement_page.dart'; 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/setting_page/agreement_page/privacy_page.dart';
import 'package:akuCommunity/pages/sign/user_authentication_page.dart'; import 'package:akuCommunity/pages/sign/sign_func.dart';
import 'package:akuCommunity/extensions/num_ext.dart'; import 'package:akuCommunity/extensions/num_ext.dart';
import 'package:akuCommunity/const/resource.dart'; import 'package:akuCommunity/const/resource.dart';
import 'package:ani_route/ani_route.dart'; import 'package:ani_route/ani_route.dart';
import 'package:bot_toast/bot_toast.dart'; import 'package:bot_toast/bot_toast.dart';
import 'package:common_utils/common_utils.dart'; import 'package:common_utils/common_utils.dart';
import 'package:dio/dio.dart';
import 'package:flustars/flustars.dart' show TextUtil; import 'package:flustars/flustars.dart' show TextUtil;
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
@ -17,7 +17,7 @@ import 'package:akuCommunity/utils/headers.dart';
import 'package:akuCommunity/base/base_style.dart'; import 'package:akuCommunity/base/base_style.dart';
import 'package:akuCommunity/base/assets_image.dart'; import 'package:akuCommunity/base/assets_image.dart';
import 'package:flutter_screenutil/flutter_screenutil.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'; import 'package:velocity_x/velocity_x.dart';
class SignInPage extends StatefulWidget { class SignInPage extends StatefulWidget {
@ -51,67 +51,62 @@ class _SignInPageState extends State<SignInPage> {
); );
} }
InkWell _inkWellLogin() { Future<bool> _showLoginVerify() async {
return InkWell( return await showCupertinoDialog(
onTap: () { barrierDismissible: false,
if (TextUtil.isEmpty(_phone.text)) context: context,
BotToast.showText(text: '手机号不能为空'); builder: (context) {
else if (TextUtil.isEmpty(_code.text)) return CupertinoAlertDialog(
BotToast.showText(text: '验证码不能为空'); title: Text('点击登录即表示您已阅读并同意'),
else { content: Text(
showCupertinoDialog( '''点击登录即表示您已阅读并同意《小蜜蜂用户协议》《小蜜蜂隐私政策》(特别是免除或限制责任、管辖等粗体下划线标注的条款)。如您不同意上述协议的任何条款,您应立即停止登录及使用本软件及服务。'''),
context: context, actions: [
builder: (context) { CupertinoDialogAction(
return CupertinoAlertDialog( child: Text('同意'),
title: Text('点击登录即表示您已阅读并同意'), onPressed: () => Get.back(result: true),
content: Text( ),
'''点击登录即表示您已阅读并同意《小蜜蜂用户协议》《小蜜蜂隐私政策》(特别是免除或限制责任、管辖等粗体下划线标注的条款)。如您不同意上述协议的任何条款,您应立即停止登录及使用本软件及服务。'''), CupertinoDialogAction(
actions: [ child: Text('拒绝'),
CupertinoDialogAction( onPressed: () => Get.back(result: false),
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();
},
),
],
);
},
);
}
}, },
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, height: 89.w,
width: 586.w, shape: StadiumBorder(),
padding: EdgeInsets.only(top: 25.w, bottom: 24.w), elevation: 0,
margin: EdgeInsets.symmetric(horizontal: 82.w), materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
decoration: BoxDecoration( child: '登陆'.text.bold.size(28.sp).color(ktextPrimary).make(),
color: Color(0xffffc40c), color: kPrimaryColor,
borderRadius: BorderRadius.all(Radius.circular(36)),
),
child: Text(
'登录',
style: TextStyle(
fontWeight: FontWeight.w600,
fontSize: BaseStyle.fontSize28,
color: ktextPrimary,
),
),
), ),
); );
} }
@ -182,107 +177,101 @@ class _SignInPageState extends State<SignInPage> {
return Scaffold( return Scaffold(
backgroundColor: Colors.white, backgroundColor: Colors.white,
appBar: _appBar, appBar: _appBar,
body: SingleChildScrollView( body: GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () {
FocusScope.of(context).requestFocus(FocusNode());
},
child: Container( child: Container(
child: GestureDetector( color: Colors.white,
behavior: HitTestBehavior.opaque, child: ListView(
onTap: () { children: [
FocusScope.of(context).requestFocus(FocusNode()); 153.hb,
}, _containerImage(),
child: Container( 16.hb,
color: Colors.white, Container(
child: ListView( alignment: Alignment.center,
shrinkWrap: true, child: Text(
children: [ '欢迎登录小蜜蜂',
SizedBox( style: TextStyle(
height: 153.w, fontWeight: FontWeight.w600,
), fontSize: BaseStyle.fontSize38,
_containerImage(), color: ktextPrimary),
SizedBox(height: 16.w), ),
Container( ),
alignment: Alignment.center, 89.hb,
child: Text( _buildTextField(
'欢迎登录小蜜蜂', hint: '请输入手机号',
style: TextStyle( controller: _phone,
fontWeight: FontWeight.w600, prefix: Image.asset(
fontSize: BaseStyle.fontSize38, R.ASSETS_IMAGES_PHONE_LOGO_PNG,
color: ktextPrimary), height: 50.w,
), width: 50.w,
), ),
SizedBox(height: 89.w), ),
_buildTextField( 26.hb,
hint: '请输入手机号', _buildTextField(
controller: _phone, prefix: Image.asset(
prefix: Image.asset( R.ASSETS_IMAGES_CODE_LOGO_PNG,
R.ASSETS_IMAGES_PHONE_LOGO_PNG, height: 50.w,
height: 50.w, width: 50.w,
width: 50.w, ),
hint: '请输入验证码',
controller: _code,
suffix: MaterialButton(
height: 82.w,
shape: StadiumBorder(),
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
child: Text(
_timer?.isActive ?? false
? '${60 - _timer.tick}'
: '获取验证码',
style: TextStyle(
color: BaseStyle.color999999,
fontSize: BaseStyle.fontSize28,
fontWeight: FontWeight.w500,
), ),
), ),
26.hb, onPressed: _canGetCode
_buildTextField( ? () {
prefix: Image.asset( SignFunc.sendMessageCode(_phone.text);
R.ASSETS_IMAGES_CODE_LOGO_PNG, startTick();
height: 50.w, }
width: 50.w, : null,
), ),
hint: '请输入验证码', ),
controller: _code, SizedBox(height: 59.w),
suffix: MaterialButton( _inkWellLogin(),
height: 82.w, Row(
shape: StadiumBorder(), mainAxisAlignment: MainAxisAlignment.center,
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap, children: [
FlatButton(
padding: EdgeInsets.zero,
onPressed: () {
ARoute.push(context, AgreementPage());
},
child: Text( child: Text(
_timer?.isActive ?? false '《小蜜蜂用户协议》',
? '${60 - _timer.tick}'
: '获取验证码',
style: TextStyle( style: TextStyle(
color: BaseStyle.color999999, color: Colors.lightBlue,
fontSize: BaseStyle.fontSize28,
fontWeight: FontWeight.w500,
), ),
), )),
onPressed: _canGetCode SizedBox(width: 15.w),
? () { FlatButton(
startTick(); padding: EdgeInsets.zero,
} onPressed: () {
: null, ARoute.push(context, PrivacyPage());
), },
), child: Text(
SizedBox(height: 59.w), '《小蜜蜂隐私政策》',
_inkWellLogin(), style: TextStyle(
Row( color: Colors.lightBlue,
mainAxisAlignment: MainAxisAlignment.center, ),
children: [ ))
FlatButton(
padding: EdgeInsets.zero,
onPressed: () {
ARoute.push(context, AgreementPage());
},
child: Text(
'《小蜜蜂用户协议》',
style: TextStyle(
color: Colors.lightBlue,
),
)),
SizedBox(width: 15.w),
FlatButton(
padding: EdgeInsets.zero,
onPressed: () {
ARoute.push(context, PrivacyPage());
},
child: Text(
'《小蜜蜂隐私政策》',
style: TextStyle(
color: Colors.lightBlue,
),
))
],
),
], ],
)), ),
), ],
), )),
), ),
); );
} }

@ -0,0 +1,39 @@
import 'package:akuCommunity/pages/tab_navigator.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:velocity_x/velocity_x.dart';
//TODO splashPage
class SplashPage extends StatefulWidget {
SplashPage({Key key}) : super(key: key);
@override
_SplashPageState createState() => _SplashPageState();
}
class _SplashPageState extends State<SplashPage> {
Future _initOp() async {
await Future.delayed(Duration(seconds: 2));
}
@override
void initState() {
super.initState();
_initOp().then((value) => Get.offAll(TabNavigator()));
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: SizedBox(
height: 80,
width: 80,
child: Placeholder(),
).centered(),
bottomNavigationBar: SizedBox(
child: CircularProgressIndicator().centered(),
height: 100,
),
);
}
}

@ -1,10 +1,30 @@
import 'package:akuCommunity/utils/hive_store.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
class UserProvider extends ChangeNotifier{
class UserProvider extends ChangeNotifier {
// //
bool _isSigned =false; bool _isSigned = false;
get isSigned => _isSigned; get isSigned => _isSigned;
setisSigned(bool state){ setisSigned(bool state) {
_isSigned=state; _isSigned = state;
notifyListeners(); 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');
}
}

@ -1,4 +1,5 @@
import 'package:akuCommunity/extensions/num_ext.dart'; import 'package:akuCommunity/extensions/num_ext.dart';
import 'package:common_utils/common_utils.dart';
import 'package:dio/dio.dart'; import 'package:dio/dio.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:velocity_x/velocity_x.dart'; import 'package:velocity_x/velocity_x.dart';
@ -15,6 +16,7 @@ class LoggerDioErr extends StatelessWidget {
color: Colors.red[100], color: Colors.red[100],
onPressed: () {}, onPressed: () {},
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Row( Row(
children: [ children: [
@ -31,6 +33,7 @@ class LoggerDioErr extends StatelessWidget {
), ),
], ],
), ),
error.response.headers['date'].first.toString().text.make(),
error.message.text.sm.light.make(), error.message.text.sm.light.make(),
], ],
), ),

@ -0,0 +1,20 @@
class BaseModel {
int code;
String message;
bool status;
dynamic data;
BaseModel({
this.code,
this.message,
this.data,
this.status,
});
BaseModel.err({this.message = '未知错误', this.status = false});
BaseModel.fromJson(Map<String, dynamic> json) {
message = json['message'] ?? '';
data = json['data'] ?? null;
status = json['status'] ?? false;
}
}

@ -0,0 +1,21 @@
class LoginModel {
String message;
String token;
bool status;
LoginModel({this.message, this.token, this.status});
LoginModel.fromJson(Map<String, dynamic> json) {
message = json['message'];
token = json['token'];
status = json['status'];
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['message'] = this.message;
data['token'] = this.token;
data['status'] = this.status;
return data;
}
}

@ -1,6 +1,5 @@
import 'dart:convert';
import 'package:akuCommunity/utils/logger/logger_data.dart'; import 'package:akuCommunity/utils/logger/logger_data.dart';
import 'package:akuCommunity/utils/network/base_model.dart';
import 'package:bot_toast/bot_toast.dart'; import 'package:bot_toast/bot_toast.dart';
import 'package:dio/dio.dart'; import 'package:dio/dio.dart';
@ -14,6 +13,8 @@ class NetUtil {
factory NetUtil() => _netUtil; factory NetUtil() => _netUtil;
Dio get dio => _dio;
NetUtil._internal() { NetUtil._internal() {
_logger = Logger( _logger = Logger(
printer: PrettyPrinter( printer: PrettyPrinter(
@ -21,7 +22,7 @@ class NetUtil {
errorMethodCount: 4, errorMethodCount: 4,
)); ));
BaseOptions options = BaseOptions( BaseOptions options = BaseOptions(
baseUrl: API.host, baseUrl: '${API.host}/app',
connectTimeout: API.networkTimeOut, connectTimeout: API.networkTimeOut,
receiveTimeout: API.networkTimeOut, receiveTimeout: API.networkTimeOut,
sendTimeout: API.networkTimeOut, sendTimeout: API.networkTimeOut,
@ -39,6 +40,7 @@ class NetUtil {
Future<BaseModel> get( Future<BaseModel> get(
String path, { String path, {
Map<String, dynamic> params, Map<String, dynamic> params,
bool showMessage = false,
}) async { }) async {
try { try {
Response res = await _dio.get(path, queryParameters: params); Response res = await _dio.get(path, queryParameters: params);
@ -49,7 +51,33 @@ class NetUtil {
'data': res.data, 'data': res.data,
}); });
LoggerData.addData(res); LoggerData.addData(res);
return BaseModel.fromJson(res.data); BaseModel baseModel = BaseModel.fromJson(res.data);
_parseRequestError(baseModel, showMessage: showMessage);
return baseModel;
} on DioError catch (e) {
_parseErr(e);
}
return BaseModel.err();
}
Future<BaseModel> post(
String path, {
Map<String, dynamic> params,
bool showMessage = false,
}) async {
try {
Response res = await _dio.post(path, data: params);
_logger.v({
'path': res.request.path,
'header': res.request.headers,
'params': res.request.queryParameters,
'data': res.data,
});
LoggerData.addData(res);
BaseModel baseModel = BaseModel.fromJson(res.data);
_parseRequestError(baseModel, showMessage: showMessage);
return baseModel;
} on DioError catch (e) { } on DioError catch (e) {
_parseErr(e); _parseErr(e);
} }
@ -82,29 +110,10 @@ class NetUtil {
break; break;
} }
} }
}
class BaseModel {
int code;
String message;
dynamic data;
BaseModel({
this.code,
this.message,
this.data,
});
BaseModel.err({this.message = '未知错误', this.code = 0});
factory BaseModel.fromMap(Map<String, dynamic> map) { _parseRequestError(BaseModel model, {bool showMessage = false}) {
if (map == null) return null; if (!model.status || showMessage) {
return BaseModel( BotToast.showText(text: model.message);
code: map['code'] ?? 0, }
message: map['message'] ?? '',
data: map['data'],
);
} }
factory BaseModel.fromJson(String source) =>
BaseModel.fromMap(json.decode(source));
} }
Loading…
Cancel
Save