张萌 4 years ago
commit d1d811b19e

@ -3,6 +3,7 @@ class API {
static String get resource => '$host/static'; static String get resource => '$host/static';
static const int networkTimeOut = 10000; static const int networkTimeOut = 10000;
static _Login login = _Login(); static _Login login = _Login();
static _User user = _User();
} }
class _Login { class _Login {
@ -17,4 +18,12 @@ class _Login {
///ID ///ID
String get unitInfo => '/login/findEstateIANByBuilding'; String get unitInfo => '/login/findEstateIANByBuilding';
/// app
String get signUp => '/login/register';
}
class _User {
///
String get userProfile => '/user/personalData/findPersonalData';
} }

@ -1,28 +1,4 @@
class UserInfoModel { 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; int id;
List<String> imgUrls; List<String> imgUrls;
String name; String name;
@ -31,7 +7,7 @@ class Data {
int sex; int sex;
String birthday; String birthday;
Data( UserInfoModel(
{this.id, {this.id,
this.imgUrls, this.imgUrls,
this.name, this.name,
@ -40,7 +16,7 @@ class Data {
this.sex, this.sex,
this.birthday}); this.birthday});
Data.fromJson(Map<String, dynamic> json) { UserInfoModel.fromJson(Map<String, dynamic> json) {
id = json['id']; id = json['id'];
imgUrls = json['imgUrls'].cast<String>(); imgUrls = json['imgUrls'].cast<String>();
name = json['name']; name = json['name'];

@ -136,13 +136,13 @@ class _PersonalIndexState extends State<PersonalIndex>
), ),
InkWell( InkWell(
onTap: () { onTap: () {
if (!userProvider.isSigned) SignInPage().to(); if (!userProvider.isLogin) SignInPage().to();
}, },
child: Container( child: Container(
margin: EdgeInsets.only(left: 16.w), margin: EdgeInsets.only(left: 16.w),
child: userProvider.isLogin child: userProvider.isLogin
? Text( ? Text(
'Cheailune', userProvider.userInfoModel.nickName,
style: TextStyle( style: TextStyle(
fontSize: 32.sp, fontSize: 32.sp,
color: Color(0xffad8940), color: Color(0xffad8940),

@ -54,12 +54,16 @@ class _SettingsPageState extends State<SettingsPage> {
); );
} }
Widget _containerQuit() { Widget _quitButton() {
final userProvider = Provider.of<UserProvider>(context); final userProvider = Provider.of<UserProvider>(context);
return InkWell( return userProvider.isLogin
onTap: () { ? MaterialButton(
userProvider.isSigned elevation: 0,
? showCupertinoModalPopup( color: Colors.white,
height: 96.w,
child: '退出当前账号'.text.color(ktextPrimary).size(32.sp).bold.make(),
onPressed: () {
showCupertinoModalPopup(
context: context, context: context,
builder: (context) { builder: (context) {
return CupertinoActionSheet( return CupertinoActionSheet(
@ -73,8 +77,8 @@ class _SettingsPageState extends State<SettingsPage> {
), ),
), ),
onPressed: () { onPressed: () {
userProvider.setisSigned(false); userProvider.logout();
Get.back(); Get.offAll(SignInPage());
}, },
), ),
], ],
@ -86,47 +90,10 @@ class _SettingsPageState extends State<SettingsPage> {
), ),
); );
}, },
) );
: SignInPage().to(); },
}, )
child: userProvider.isSigned : SizedBox();
? Container(
color: Colors.white,
height: 96.w,
padding: EdgeInsets.only(
top: 26.w,
bottom: 25.w,
),
alignment: Alignment.center,
child: Text(
'退出当前帐号',
style: TextStyle(
fontWeight: FontWeight.w600,
fontSize: BaseStyle.fontSize32,
color: ktextPrimary,
),
),
)
: 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,
),
),
),
);
} }
@override @override
@ -210,8 +177,8 @@ class _SettingsPageState extends State<SettingsPage> {
thickness: 1.w, thickness: 1.w,
height: 1.w, height: 1.w,
)), )),
50.hb, 53.hb,
_containerQuit(), _quitButton(),
], ],
), ),
); );

@ -1,8 +1,14 @@
import 'package:akuCommunity/constants/api.dart'; import 'package:akuCommunity/constants/api.dart';
import 'package:akuCommunity/model/user/pick_building_model.dart'; import 'package:akuCommunity/model/user/pick_building_model.dart';
import 'package:akuCommunity/model/user/user_info_model.dart';
import 'package:akuCommunity/provider/sign_up_provider.dart';
import 'package:akuCommunity/provider/user_provider.dart';
import 'package:akuCommunity/utils/network/base_model.dart'; import 'package:akuCommunity/utils/network/base_model.dart';
import 'package:akuCommunity/utils/network/net_util.dart'; import 'package:akuCommunity/utils/network/net_util.dart';
import 'package:bot_toast/bot_toast.dart';
import 'package:dio/dio.dart'; import 'package:dio/dio.dart';
import 'package:get/get.dart' hide Response;
import 'package:provider/provider.dart';
class SignFunc { class SignFunc {
static Future sendMessageCode(String phone) async { static Future sendMessageCode(String phone) async {
@ -38,4 +44,26 @@ class SignFunc {
.map((e) => PickBuildingModel.fromJson(e)) .map((e) => PickBuildingModel.fromJson(e))
.toList(); .toList();
} }
///
static Future<bool> signUp() async {
final signUpProvider =
Provider.of<SignUpProvider>(Get.context, listen: false);
final userProvider = Provider.of<UserProvider>(Get.context, listen: false);
Response response = await NetUtil().dio.post(
API.login.signUp,
data: signUpProvider.toMap,
);
BotToast.showText(text: response.data['message']);
if (response.data['status']) {
userProvider.setLogin(response.data['token']);
return true;
} else
return false;
}
static Future<UserInfoModel> getUserInfo() async {
BaseModel baseModel = await NetUtil().get(API.user.userProfile);
return UserInfoModel.fromJson(baseModel.data);
}
} }

@ -35,7 +35,6 @@ class SignInPage extends StatefulWidget {
class _SignInPageState extends State<SignInPage> { class _SignInPageState extends State<SignInPage> {
TextEditingController _phone = new TextEditingController(); TextEditingController _phone = new TextEditingController();
TextEditingController _code = new TextEditingController(); TextEditingController _code = new TextEditingController();
AppBar get _appBar => AppBar(elevation: 0, backgroundColor: Colors.white);
Timer _timer; Timer _timer;
bool get validPhone => RegexUtil.isMobileSimple(_phone.text); bool get validPhone => RegexUtil.isMobileSimple(_phone.text);
@ -90,8 +89,7 @@ class _SignInPageState extends State<SignInPage> {
if (response.data['status']) { if (response.data['status']) {
if (response.data['choose'] == 1) { if (response.data['choose'] == 1) {
userProvider.setLogin(response.data['token'] as String); userProvider.setLogin(response.data['token']);
Get.offAll(TabNavigator()); Get.offAll(TabNavigator());
} else { } else {
cancel(); cancel();
@ -195,7 +193,6 @@ class _SignInPageState extends State<SignInPage> {
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
backgroundColor: Colors.white, backgroundColor: Colors.white,
appBar: _appBar,
body: GestureDetector( body: GestureDetector(
behavior: HitTestBehavior.opaque, behavior: HitTestBehavior.opaque,
onTap: () { onTap: () {

@ -28,8 +28,6 @@ class _SignUpPickRolePageState extends State<SignUpPickRolePage> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final signUpProvider = Provider.of<SignUpProvider>(context);
return Scaffold( return Scaffold(
body: ListView( body: ListView(
padding: EdgeInsets.symmetric(horizontal: 32.w), padding: EdgeInsets.symmetric(horizontal: 32.w),

@ -1,7 +1,12 @@
import 'package:akuCommunity/base/base_style.dart'; import 'package:akuCommunity/base/base_style.dart';
import 'package:akuCommunity/pages/sign/sign_up/sign_up_common_widget.dart'; import 'package:akuCommunity/pages/sign/sign_up/sign_up_common_widget.dart';
import 'package:akuCommunity/pages/sign/sign_up/sign_up_verify_page.dart';
import 'package:akuCommunity/provider/sign_up_provider.dart';
import 'package:akuCommunity/utils/headers.dart'; import 'package:akuCommunity/utils/headers.dart';
import 'package:flustars/flustars.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:provider/provider.dart';
import 'package:velocity_x/velocity_x.dart'; import 'package:velocity_x/velocity_x.dart';
class SignUpSetNicknamePage extends StatefulWidget { class SignUpSetNicknamePage extends StatefulWidget {
@ -12,6 +17,14 @@ class SignUpSetNicknamePage extends StatefulWidget {
} }
class _SignUpSetNicknamePageState extends State<SignUpSetNicknamePage> { class _SignUpSetNicknamePageState extends State<SignUpSetNicknamePage> {
GlobalKey<FormState> _globalKey = GlobalKey<FormState>();
TextEditingController _textEditingController = TextEditingController();
@override
void dispose() {
_textEditingController?.dispose();
super.dispose();
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
@ -22,12 +35,22 @@ class _SignUpSetNicknamePageState extends State<SignUpSetNicknamePage> {
signUpTitle('设置昵称'), signUpTitle('设置昵称'),
190.hb, 190.hb,
'请输入您的昵称'.text.size(32.sp).color(ktextPrimary).make(), '请输入您的昵称'.text.size(32.sp).color(ktextPrimary).make(),
TextField( Form(
decoration: InputDecoration( key: _globalKey,
border: UnderlineInputBorder( child: TextFormField(
borderSide: BorderSide(color: Color(0xFFD8D8D8)), controller: _textEditingController,
validator: (value) {
if (TextUtil.isEmpty(value))
return '昵称不能为空';
else
return null;
},
decoration: InputDecoration(
border: UnderlineInputBorder(
borderSide: BorderSide(color: Color(0xFFD8D8D8)),
),
hintText: '为保护个人隐私,在与邻居交流时将显示昵称',
), ),
hintText: '为保护个人隐私,在与邻居交流时将显示昵称',
), ),
), ),
], ],
@ -42,7 +65,14 @@ class _SignUpSetNicknamePageState extends State<SignUpSetNicknamePage> {
height: 89.w, height: 89.w,
child: '保存'.text.make(), child: '保存'.text.make(),
shape: StadiumBorder(), shape: StadiumBorder(),
onPressed: () {}, onPressed: () {
if (_globalKey.currentState.validate()) {
final signUpProvider =
Provider.of<SignUpProvider>(context, listen: false);
signUpProvider.setNickName(_textEditingController.text);
Get.to(SignUpVerifyPage());
}
},
), ),
MaterialButton( MaterialButton(
elevation: 0, elevation: 0,

@ -0,0 +1,94 @@
import 'package:akuCommunity/base/base_style.dart';
import 'package:akuCommunity/pages/sign/sign_func.dart';
import 'package:akuCommunity/pages/sign/sign_up/sign_up_common_widget.dart';
import 'package:akuCommunity/pages/tab_navigator.dart';
import 'package:akuCommunity/provider/sign_up_provider.dart';
import 'package:akuCommunity/utils/headers.dart';
import 'package:common_utils/common_utils.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:provider/provider.dart';
import 'package:velocity_x/velocity_x.dart';
class SignUpVerifyPage extends StatefulWidget {
SignUpVerifyPage({Key key}) : super(key: key);
@override
_SignUpVerifyPageState createState() => _SignUpVerifyPageState();
}
class _SignUpVerifyPageState extends State<SignUpVerifyPage> {
TextEditingController _nameController = TextEditingController();
TextEditingController _idNumberController = TextEditingController();
GlobalKey<FormState> _formKey = GlobalKey<FormState>();
@override
Widget build(BuildContext context) {
return Scaffold(
body: Form(
key: _formKey,
child: ListView(
padding: EdgeInsets.symmetric(horizontal: 32.w),
children: [
148.hb,
signUpTitle('设置昵称'),
190.hb,
'请输入您的姓名'.text.size(32.sp).color(ktextPrimary).make(),
TextFormField(
controller: _nameController,
validator: (value) {
if (TextUtil.isEmpty(value))
return '姓名不能为空';
else
return null;
},
decoration: InputDecoration(
border: UnderlineInputBorder(
borderSide: BorderSide(color: Color(0xFFD8D8D8)),
),
// hintText: '',
),
),
40.hb,
'请输入您的身份证号'.text.size(32.sp).color(ktextPrimary).make(),
TextFormField(
controller: _idNumberController,
validator: (value) {
if (TextUtil.isEmpty(value)) return '身份证号不能为空';
if (!RegexUtil.isIDCard(value))
return '身份证格式错误';
else
return null;
},
decoration: InputDecoration(
border: UnderlineInputBorder(
borderSide: BorderSide(color: Color(0xFFD8D8D8)),
),
// hintText: '',
),
),
],
),
),
bottomNavigationBar: MaterialButton(
height: 89.w,
color: kPrimaryColor,
shape: StadiumBorder(),
disabledColor: kPrimaryColor.withOpacity(0.3),
child: '登录'.text.bold.make(),
onPressed: () async {
final signUpProvider =
Provider.of<SignUpProvider>(context, listen: false);
if (_formKey.currentState.validate()) {
signUpProvider.setName(_nameController.text);
signUpProvider.setIdNumber(_idNumberController.text);
bool result = await SignFunc.signUp();
if (result) Get.offAll(TabNavigator());
}
},
elevation: 0,
).pLTRB(82.w, 0, 82.w, 155.w),
);
}
}

@ -11,11 +11,36 @@ class SignUpProvider extends ChangeNotifier {
String get name => _name; String get name => _name;
String _tel; String _tel;
String get tel => _tel; String get tel => _tel;
int _idType;
///default is 1
///
///
///1.
///2.
///3.
int _idType = 1;
///default is 1
///
///
///1.
///2.
///3.
int get idType => _idType; int get idType => _idType;
String _idNumber; String _idNumber;
String get idNumber => _idNumber; String get idNumber => _idNumber;
Map<String, dynamic> get toMap => {
'estateId': _estateId,
'type': _type,
'nickName': _nickName,
'name': _name,
'tel': _tel,
'idType': _idType,
'idNumber': _idNumber,
};
setEstateId(int id) { setEstateId(int id) {
_estateId = id; _estateId = id;
notifyListeners(); notifyListeners();
@ -26,6 +51,11 @@ class SignUpProvider extends ChangeNotifier {
notifyListeners(); notifyListeners();
} }
setNickName(String name) {
_nickName = name;
notifyListeners();
}
setName(String name) { setName(String name) {
_name = name; _name = name;
notifyListeners(); notifyListeners();
@ -36,7 +66,7 @@ class SignUpProvider extends ChangeNotifier {
notifyListeners(); notifyListeners();
} }
setidType(int idType) { setIdType(int idType) {
_idType = idType; _idType = idType;
notifyListeners(); notifyListeners();
} }

@ -1,3 +1,5 @@
import 'package:akuCommunity/model/user/user_info_model.dart';
import 'package:akuCommunity/pages/sign/sign_func.dart';
import 'package:akuCommunity/utils/hive_store.dart'; import 'package:akuCommunity/utils/hive_store.dart';
import 'package:akuCommunity/utils/network/net_util.dart'; import 'package:akuCommunity/utils/network/net_util.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
@ -13,25 +15,31 @@ class UserProvider extends ChangeNotifier {
bool _isLogin = false; bool _isLogin = false;
bool get isLogin => _isLogin; bool get isLogin => _isLogin;
setLogin(String token) { Future setLogin(int token) async {
_isLogin = true; _isLogin = true;
NetUtil().dio.options.headers.putIfAbsent('App-Admin-Token', () => token); NetUtil().dio.options.headers.putIfAbsent('App-Admin-Token', () => token);
HiveStore.appBox.put('token', token); HiveStore.appBox.put('token', token);
await updateProfile();
notifyListeners(); notifyListeners();
} }
logout() { logout() {
_isLogin = false; _isLogin = false;
_token = null; _token = null;
_userInfoModel = null;
NetUtil().dio.options.headers.remove('App-Admin-Token'); NetUtil().dio.options.headers.remove('App-Admin-Token');
HiveStore.appBox.delete('token'); HiveStore.appBox.delete('token');
notifyListeners(); notifyListeners();
} }
updateProfile() async { Future updateProfile() async {
// await _userInfoModel = await SignFunc.getUserInfo();
notifyListeners();
} }
String _token; String _token;
String get token => _token ?? ''; String get token => _token ?? '';
UserInfoModel _userInfoModel;
UserInfoModel get userInfoModel => _userInfoModel;
} }

@ -1,4 +1,5 @@
import 'package:akuCommunity/utils/logger/logger_dio_err.dart'; import 'package:akuCommunity/utils/logger/logger_dio_err.dart';
import 'package:akuCommunity/utils/logger/logger_dio_success.dart';
import 'package:dio/dio.dart'; import 'package:dio/dio.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
@ -13,13 +14,7 @@ class LoggerCard extends StatelessWidget {
Widget _buildResponse() { Widget _buildResponse() {
Response response = data; Response response = data;
return Card( return LoggerDioSuccess(response: response);
child: Column(
children: [
Text(response.statusCode.toString()),
],
),
);
} }
Widget _getLoggerView() { Widget _getLoggerView() {

@ -0,0 +1,40 @@
import 'package:akuCommunity/extensions/num_ext.dart';
import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:velocity_x/velocity_x.dart';
class LoggerDioSuccess extends StatelessWidget {
final Response response;
const LoggerDioSuccess({Key key, this.response}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialButton(
elevation: 10,
highlightElevation: 1,
color: Colors.white,
onPressed: () {},
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
5.wb,
response.request.path.text.bold.make().expand(),
Chip(
backgroundColor: Colors.redAccent,
label: Text(response?.statusCode?.toString() ?? 'UNKNOW'),
),
5.wb,
Chip(
backgroundColor: Colors.greenAccent,
label: Text(response.request.method),
),
],
),
response.headers['date'].first.toString().text.make(),
],
),
);
}
}
Loading…
Cancel
Save