张萌 4 years ago
commit dceada58f6

@ -1,9 +1,14 @@
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 _Login login = _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:get/get.dart';
extension PageExt on Widget{
Function get to => (){Get.to(this);};
extension PageExt on Widget {
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/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());
@ -50,7 +55,7 @@ class _MyAppState extends State<MyApp> {
primarySwatch: Colors.yellow,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: TabNavigator(),
home: SplashPage(),
//
localizationsDelegates: [
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/painters/user_bottom_bar_painter.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:ani_route/ani_route.dart';
import 'package:flutter/material.dart';
@ -137,8 +137,7 @@ class _PersonalIndexState extends State<PersonalIndex>
),
InkWell(
onTap: () {
if (!userProvider.isSigned)
ARoute.push(context, SignInPage());
if (!userProvider.isSigned) SignInPage().to();
},
child: Container(
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: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/user_authentication_page.dart';
import 'package:akuCommunity/pages/sign/sign_func.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';
@ -17,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 {
@ -51,15 +51,9 @@ 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(
Future<bool> _showLoginVerify() async {
return await showCupertinoDialog(
barrierDismissible: false,
context: context,
builder: (context) {
return CupertinoAlertDialog(
@ -69,49 +63,50 @@ class _SignInPageState extends State<SignInPage> {
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: '账号或密码错误!');
},
);
},
onPressed: () => Get.back(result: true),
),
CupertinoDialogAction(
child: Text('拒绝'),
onPressed: () {
Get.back();
},
onPressed: () => Get.back(result: false),
),
],
);
},
);
}
_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);
}
},
child: Container(
alignment: Alignment.center,
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,
),
);
}
@ -182,9 +177,7 @@ class _SignInPageState extends State<SignInPage> {
return Scaffold(
backgroundColor: Colors.white,
appBar: _appBar,
body: SingleChildScrollView(
child: Container(
child: GestureDetector(
body: GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () {
FocusScope.of(context).requestFocus(FocusNode());
@ -192,13 +185,10 @@ class _SignInPageState extends State<SignInPage> {
child: Container(
color: Colors.white,
child: ListView(
shrinkWrap: true,
children: [
SizedBox(
height: 153.w,
),
153.hb,
_containerImage(),
SizedBox(height: 16.w),
16.hb,
Container(
alignment: Alignment.center,
child: Text(
@ -209,7 +199,7 @@ class _SignInPageState extends State<SignInPage> {
color: ktextPrimary),
),
),
SizedBox(height: 89.w),
89.hb,
_buildTextField(
hint: '请输入手机号',
controller: _phone,
@ -244,6 +234,7 @@ class _SignInPageState extends State<SignInPage> {
),
onPressed: _canGetCode
? () {
SignFunc.sendMessageCode(_phone.text);
startTick();
}
: null,
@ -282,8 +273,6 @@ class _SignInPageState extends State<SignInPage> {
],
)),
),
),
),
);
}
}

@ -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';
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');
}
}

@ -1,4 +1,5 @@
import 'package:akuCommunity/extensions/num_ext.dart';
import 'package:common_utils/common_utils.dart';
import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:velocity_x/velocity_x.dart';
@ -15,6 +16,7 @@ class LoggerDioErr extends StatelessWidget {
color: Colors.red[100],
onPressed: () {},
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
@ -31,6 +33,7 @@ class LoggerDioErr extends StatelessWidget {
),
],
),
error.response.headers['date'].first.toString().text.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/network/base_model.dart';
import 'package:bot_toast/bot_toast.dart';
import 'package:dio/dio.dart';
@ -14,6 +13,8 @@ class NetUtil {
factory NetUtil() => _netUtil;
Dio get dio => _dio;
NetUtil._internal() {
_logger = Logger(
printer: PrettyPrinter(
@ -21,7 +22,7 @@ class NetUtil {
errorMethodCount: 4,
));
BaseOptions options = BaseOptions(
baseUrl: API.host,
baseUrl: '${API.host}/app',
connectTimeout: API.networkTimeOut,
receiveTimeout: API.networkTimeOut,
sendTimeout: API.networkTimeOut,
@ -39,6 +40,7 @@ class NetUtil {
Future<BaseModel> get(
String path, {
Map<String, dynamic> params,
bool showMessage = false,
}) async {
try {
Response res = await _dio.get(path, queryParameters: params);
@ -49,7 +51,33 @@ class NetUtil {
'data': res.data,
});
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) {
_parseErr(e);
}
@ -82,29 +110,10 @@ class NetUtil {
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) {
if (map == null) return null;
return BaseModel(
code: map['code'] ?? 0,
message: map['message'] ?? '',
data: map['data'],
);
_parseRequestError(BaseModel model, {bool showMessage = false}) {
if (!model.status || showMessage) {
BotToast.showText(text: model.message);
}
}
factory BaseModel.fromJson(String source) =>
BaseModel.fromMap(json.decode(source));
}
Loading…
Cancel
Save