Commit 2c0efeea authored by 林生雨's avatar 林生雨

commit

parent 29e28e7c
......@@ -3,7 +3,6 @@ package io.flutter.plugins;
import io.flutter.plugin.common.PluginRegistry;
import com.taobao.idlefish.flutterboost.FlutterBoostPlugin;
import com.bigbug.mmkvflutter.MmkvFlutterPlugin;
import io.flutter.plugins.sharedpreferences.SharedPreferencesPlugin;
import fleamarket.taobao.com.xservicekit.XserviceKitPlugin;
/**
......@@ -16,7 +15,6 @@ public final class GeneratedPluginRegistrant {
}
FlutterBoostPlugin.registerWith(registry.registrarFor("com.taobao.idlefish.flutterboost.FlutterBoostPlugin"));
MmkvFlutterPlugin.registerWith(registry.registrarFor("com.bigbug.mmkvflutter.MmkvFlutterPlugin"));
SharedPreferencesPlugin.registerWith(registry.registrarFor("io.flutter.plugins.sharedpreferences.SharedPreferencesPlugin"));
XserviceKitPlugin.registerWith(registry.registrarFor("fleamarket.taobao.com.xservicekit.XserviceKitPlugin"));
}
......
......@@ -35,9 +35,9 @@ buildDir = new File(rootProject.projectDir, "../build/host")
dependencies {
implementation project(':flutter')
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support:design:27.1.1'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
testImplementation 'junit:junit:4.12'
......
sdk.dir=/Users/apple/Library/Android/sdk
flutter.sdk=/Users/apple/Downloads/flutter
flutter.buildMode=debug
flutter.versionName=1.0.0
flutter.versionCode=1
\ No newline at end of file
flutter.sdk=/Users/apple/Downloads/flutter
\ No newline at end of file
......@@ -5,7 +5,6 @@
#import "GeneratedPluginRegistrant.h"
#import <flutter_boost/FlutterBoostPlugin.h>
#import <mmkv_flutter/MmkvFlutterPlugin.h>
#import <shared_preferences/SharedPreferencesPlugin.h>
#import <xservice_kit/XserviceKitPlugin.h>
@implementation GeneratedPluginRegistrant
......@@ -13,7 +12,6 @@
+ (void)registerWithRegistry:(NSObject<FlutterPluginRegistry>*)registry {
[FlutterBoostPlugin registerWithRegistrar:[registry registrarForPlugin:@"FlutterBoostPlugin"]];
[MmkvFlutterPlugin registerWithRegistrar:[registry registrarForPlugin:@"MmkvFlutterPlugin"]];
[FLTSharedPreferencesPlugin registerWithRegistrar:[registry registrarForPlugin:@"FLTSharedPreferencesPlugin"]];
[XserviceKitPlugin registerWithRegistrar:[registry registrarForPlugin:@"XserviceKitPlugin"]];
}
......
......@@ -19,6 +19,5 @@ Depends on all your plugins, and provides a function to register them.
s.dependency 'Flutter'
s.dependency 'flutter_boost'
s.dependency 'mmkv_flutter'
s.dependency 'shared_preferences'
s.dependency 'xservice_kit'
end
......@@ -8,14 +8,14 @@ targets:
builders:
user:
import: "package:gmalpha_flutter/Annotations/RouterBuilder.dart"
import: "package:gmalpha_flutter/Annotations/ServiceGenerator.dart"
builder_factories: ["userBuilder"]
build_extensions: {'.dart': ['.user.dart'] }
auto_apply: root_package
build_to: source
Router:
import: "package:gmalpha_flutter/Annotations/RouterBuilder.dart"
import: "package:gmalpha_flutter/Annotations/ServiceGenerator.dart"
builder_factories: ["routerBuilder"]
build_extensions: {'.dart': ['.rout.dart'] }
auto_apply: root_package
......@@ -24,16 +24,24 @@ builders:
routerCenter:
import: "package:gmalpha_flutter/Annotations/RouterBuilder.dart"
import: "package:gmalpha_flutter/Annotations/ServiceGenerator.dart"
builder_factories: ["routerCenterBuilder"]
build_extensions: {'.dart': ['.mark.dart'] }
auto_apply: root_package
build_to: source
# api_generator:
# import: "package:gmalpha_flutter/Annotations/RouterBuilder.dart"
# builder_factories: ["apiBuilder"]
# build_extensions: {".dart": ["api_generator.g.part"]}
api_generator:
import: "package:gmalpha_flutter/Annotations/ServiceGenerator.dart"
builder_factories: ["apiBuilder"]
build_extensions: {".dart": [".serv.dart"]}
auto_apply: all_packages
build_to: source
applies_builders: ["source_gen|combining_builder"]
#
# json:
# import: "package:gmalpha_flutter/Annotations/ServiceGenerator.dart"
# builder_factories: ["jsonBuilder"]
# build_extensions: {".dart": [".json.dart"]}
# auto_apply: all_packages
# build_to: source
# applies_builders: ["source_gen|combining_builder"]
......
/*
* @author lsy
* @date 2019-09-03
**/
import 'dart:convert';
import 'package:analyzer/dart/element/element.dart';
import 'package:build/src/builder/build_step.dart';
import 'package:gmalpha_flutter/Annotations/anno/RouterCenter.dart';
import 'package:source_gen/source_gen.dart';
import '../RouterCenterRestore.dart';
class ApiBuilderGenerator extends GeneratorForAnnotation<Request> {
@override
generateForAnnotatedElement(
Element element, ConstantReader annotation, BuildStep buildStep) {
print("element is $element");
if (element is! ClassElement) {
throw InvalidGenerationSourceError(
"Request class is not ok for ${element.displayName}");
}
StringBuffer stringBuffer=StringBuffer("");
for (var methodElement in (element as ClassElement).methods) {
for (var annometadata in methodElement.metadata) {
final metadata = annometadata.computeConstantValue();
final metadatatype = annometadata.runtimeType;
print("metadatatype is $metadatatype");
print("metadata type is ${metadata.type.runtimeType}");
if (metadata.type.name == "ApiMethod") {
String method = metadata.getField("method").toStringValue();
String url = metadata.getField("url").toStringValue();
var headerfield = metadata.getField("head");
var head = {};
if (headerfield != null) {
print("headerfield:${headerfield.toMapValue()}");
head = headerfield.toMapValue().map((key, value) =>
MapEntry(key.toStringValue(), value.toStringValue()));
}
if (head == null) {
head = {};
}
head["Content-Type"] = "application/json";
print("genertor is ${method}");
print("bool is ${method == "get"}");
if ("get" == method) {
print("get");
stringBuffer.write( _genGetAnnotation(url, methodElement, head));
stringBuffer.writeln();
} else if ("post" == method) {
print("post");
stringBuffer.write( _genPostAnnotation(url, methodElement, head));
stringBuffer.writeln();
}
}
}
}
return stringBuffer.toString();
}
String _genGetAnnotation(String url, MethodElement element, Map head) {
return """
Future _\$get_${element.name}() {
${_getHeadMapString(head)}
return http.get("$url",headers:header);
}
""";
}
String _genPostAnnotation(String url, MethodElement element, Map head) {
return """
Future _\$post_${element.name}() {
${_getHeadMapString(head)}
return http.post("${url}",headers:header);
}
""";
}
String _getHeadMapString(Map head) {
return """
var header =${jsonEncode(head)};
""";
}
}
class Request {
const Request();
}
class ApiMethod{
final String url;
final String method;
final Map head;
const ApiMethod(this.url, this.method,{this.head});
}
class HttpRequestType {
static const String GET = "get";
static const String POST = "post";
}
/*
* @author lsy
* @date 2019-09-03
**/
import 'dart:convert';
import 'dart:core';
import 'dart:math';
import 'package:analyzer/dart/element/element.dart';
import 'package:build/src/builder/build_step.dart';
import 'package:gmalpha_flutter/Annotations/anno/ServiceCenter.dart';
import 'package:source_gen/source_gen.dart';
import '../RouterCenterRestore.dart';
class ServiceGenerator extends GeneratorForAnnotation<ServiceCenter> {
@override
generateForAnnotatedElement(
Element element, ConstantReader annotation, BuildStep buildStep) {
print("element is $element");
if (element is! ClassElement) {
throw InvalidGenerationSourceError(
"Request class is not ok for ${element.displayName}");
}
StringBuffer improtBuffer = new StringBuffer();
StringBuffer methodBuffer = StringBuffer("");
StringBuffer mapBuffer = new StringBuffer();
List<String> differentList = [];
for (var methodElement in (element as ClassElement).methods) {
for (var annometadata in methodElement.metadata) {
final metadata = annometadata.computeConstantValue();
if (metadata.type.name == "Post" || metadata.type.name == "Get") {
if (!differentList.contains(methodElement.returnType.name)) {
var pathSegments = buildStep.inputId.pathSegments;
StringBuffer path = new StringBuffer();
for (int i = 0; i < pathSegments.length; i++) {
if (i < pathSegments.length - 2&& pathSegments[i] != "lib") {
path.write("${pathSegments[i]}/");
}
}
improtBuffer.write(
"import 'package:${buildStep.inputId.package}/${path.toString()}entity/${methodElement.returnType.name}.dart\';\n");
differentList.add(methodElement.returnType.name);
}
String tempParams;
String sendType = metadata.type.name == "Post" ? "post" : "get";
mapBuffer.write("""
return Observable.fromFuture(DioUtil().${sendType}(\'${metadata.getField("sufUrl").toStringValue()}\',data:{
""");
bool needMap = false;
for (int i = 0; i < methodElement.parameters.length; i++) {
var paramsMeta = methodElement.parameters[i];
for (int j = 0; j < paramsMeta.metadata.length; j++) {
var parameter = paramsMeta.metadata[j];
final queryAnno = parameter.computeConstantValue();
if (queryAnno.type.name == "Query") {
needMap = true;
if (tempParams == null) {
tempParams = "${paramsMeta}";
} else {
tempParams = "${tempParams},${paramsMeta}";
}
if (i == methodElement.parameters.length - 1) {
mapBuffer.write(
"\'${queryAnno.getField("params").toStringValue()}\':${paramsMeta.name}");
} else {
mapBuffer.write(
"\'${queryAnno.getField("params").toStringValue()}\':${paramsMeta.name},");
}
}
}
}
mapBuffer.write("}))");
mapBuffer.write("""
.map((value){
if(value.statusCode==200){
Map map = json.decode(value.toString());
return ${methodElement.returnType.name}.fromJson(map);
}else{
throw HttpException("statusCode error :\${value.statusCode}");
}
});
""");
methodBuffer.write("""
Observable<${methodElement.returnType.name}> ${methodElement.name}(${tempParams == null ? "" : tempParams}){
${mapBuffer.toString()}
}
""");
mapBuffer.clear();
}
}
}
return """
import 'dart:convert';\n
import 'dart:io';\n
import 'package:rxdart/rxdart.dart';\n
${improtBuffer.toString()}
import 'package:gmalpha_flutter/commonModel/net/DioUtil.dart';\n
class ${element.displayName}Impl{
${methodBuffer.toString()}
}
""";
}
}
......@@ -19,6 +19,7 @@ class UserGenerator extends GeneratorForAnnotation<UserCenter> {
@override
generateForAnnotatedElement(
Element element, ConstantReader annotation, BuildStep buildStep) {
StringBuffer buffer = new StringBuffer();
for (var fieldData in (element as ClassElement).fields) {
for (var annometadata in fieldData.metadata) {
......@@ -26,17 +27,21 @@ class UserGenerator extends GeneratorForAnnotation<UserCenter> {
// final metadatatype = annometadata.runtimeType;
// print("metadatatype is $metadatatype");
// print("metadataNAME is ${metadata.type.name}");
// print("element is $element");
if (element is! ClassElement) {
throw InvalidGenerationSourceError(
"Request class is not ok for ${element.displayName}");
}
if (metadata.type.name == "User") {
String key = metadata.getField("key").toStringValue();
var field = metadata.getField("type");
var type = field.type.name;
var runtimeType = field.runtimeType;
if (type == "String") {
buffer.write("""
String _${fieldData.name};
Observable<bool> save${fieldData.name}(String ${fieldData.name}){
return Observable.fromFuture(saveStringKv("${key}",${fieldData.name}))
return Observable.fromFuture(mmKvUtil.saveStringKv("${key}",${fieldData.name}))
.map((value){
if(value){
this._${fieldData.name}=${fieldData.name};
......@@ -48,14 +53,14 @@ class UserGenerator extends GeneratorForAnnotation<UserCenter> {
if(_${fieldData.name}!=null){
return Observable.fromFuture(Future.value(_${fieldData.name}));
}
return Observable.fromFuture(getStringKv("${key}"));
return Observable.fromFuture(mmKvUtil.getStringKv("${key}"));
}
""");
} else if (type == "int") {
buffer.write("""
int _${fieldData.name};
Observable<bool> save${fieldData.name}(int ${fieldData.name}){
return Observable.fromFuture(saveIntKv("${key}",${fieldData.name}))
return Observable.fromFuture(mmKvUtil.saveIntKv("${key}",${fieldData.name}))
.map((value){
if(value){
this._${fieldData.name}=${fieldData.name};
......@@ -67,14 +72,14 @@ class UserGenerator extends GeneratorForAnnotation<UserCenter> {
if(_${fieldData.name}!=null){
return Observable.fromFuture(Future.value(_${fieldData.name}));
}
return Observable.fromFuture(getIntKv("${key}"));
return Observable.fromFuture(mmKvUtil.getIntKv("${key}"));
}
""");
} else if (type == "double") {
buffer.write("""
double _${fieldData.name};
Observable<bool> save${fieldData.name}(double ${fieldData.name}){
return Observable.fromFuture(saveDoubleKv("${key}",${fieldData.name}))
return Observable.fromFuture(mmKvUtil.saveDoubleKv("${key}",${fieldData.name}))
.map((value){
if(value){
this._${fieldData.name}=${fieldData.name};
......@@ -86,14 +91,14 @@ class UserGenerator extends GeneratorForAnnotation<UserCenter> {
if(_${fieldData.name}!=null){
return Observable.fromFuture(Future.value(_${fieldData.name}));
}
return Observable.fromFuture(getDoubleKv("${key}"));
return Observable.fromFuture(mmKvUtil.getDoubleKv("${key}"));
}
""");
} else if (type == "bool") {
buffer.write("""
bool _${fieldData.name};
Observable<bool> save${fieldData.name}(bool ${fieldData.name}){
return Observable.fromFuture(saveBoolKv("${key}",${fieldData.name}))
return Observable.fromFuture(mmKvUtil.saveBoolKv("${key}",${fieldData.name}))
.map((value){
if(value){
this._${fieldData.name}=${fieldData.name};
......@@ -105,7 +110,7 @@ class UserGenerator extends GeneratorForAnnotation<UserCenter> {
if(_${fieldData.name}!=null){
return Observable.fromFuture(Future.value(_${fieldData.name}));
}
return Observable.fromFuture(getBoolKv("${key}"));
return Observable.fromFuture(mmKvUtil.getBoolKv("${key}"));
}
""");
}
......@@ -117,18 +122,18 @@ class UserGenerator extends GeneratorForAnnotation<UserCenter> {
import 'package:rxdart/rxdart.dart';
import 'package:${buildStep.inputId.package}/commonModel/app_module.dart';
class UserCenterImpl{
class ${element.displayName}Impl{
factory UserCenterImpl() => _sharedInstance();
factory ${element.displayName}Impl() => _sharedInstance();
static UserCenterImpl _instance;
static ${element.displayName}Impl _instance;
UserCenterImpl._() {
${element.displayName}Impl._() {
}
static UserCenterImpl _sharedInstance() {
static ${element.displayName}Impl _sharedInstance() {
if (_instance == null) {
_instance = UserCenterImpl._();
_instance = ${element.displayName}Impl._();
}
return _instance;
}
......
import 'package:gmalpha_flutter/Annotations/Generator/ApiBuilderGenerator.dart';
import 'package:gmalpha_flutter/Annotations/Generator/ServiceGenerator.dart';
import 'package:gmalpha_flutter/Annotations/Generator/UserGenerator.dart';
import 'package:source_gen/source_gen.dart';
import 'package:build/src/builder/builder.dart';
......@@ -16,7 +16,9 @@ Builder routerCenterBuilder(BuilderOptions options) =>
Builder userBuilder(BuilderOptions options)=>
LibraryBuilder(UserGenerator(),generatedExtension: ".user.dart");
Builder apiBuilder(BuilderOptions options) {
print("xxxx");
return SharedPartBuilder([ApiBuilderGenerator()], "api_generator");
}
Builder apiBuilder(BuilderOptions options)=>
LibraryBuilder(ServiceGenerator(),generatedExtension: ".serv.dart");
//Builder jsonBuilder(BuilderOptions options)=>
// LibraryBuilder(JsonSerializableGenerator(),generatedExtension: ".json.dart");
\ No newline at end of file
/*
* @author lsy
* @date 2019-09-04
**/
library Get;
class Get {
final String sufUrl;
const Get(this.sufUrl);
}
/*
* @author lsy
* @date 2019-09-04
**/
library Post;
class Post {
final String sufUrl;
const Post(this.sufUrl);
}
/*
* @author lsy
* @date 2019-09-04
**/
library Query;
class Query {
final String params;
const Query(this.params);
}
/*
* @author lsy
* @date 2019-09-04
**/
library ServiceCenter;
class ServiceCenter{
const ServiceCenter();
}
\ No newline at end of file
import 'package:gmalpha_flutter/userModel/user/UserUtil.user.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:mmkv_flutter/mmkv_flutter.dart';
import 'package:gmalpha_flutter/commonModel/mmkv/MmkvUtil.dart';
MmkvFlutter _mmkv;
MmKvUtil mmKvUtil;
applicationInit() async {
_mmkv = await MmkvFlutter.getInstance();
mmKvUtil = await MmKvUtil.getInstance();
}
Future saveBoolKv(String key, bool value) async {
return await _mmkv.setBool(key, value);
}
Future saveStringKv(String key, String value) async {
return await _mmkv.setString(key, value);
}
Future saveDoubleKv(String key, double value) async {
return await _mmkv.setDouble(key, value);
}
Future<bool> saveIntKv(String key, int value) async {
return await _mmkv.setInt(key, value);
}
Future<String> getStringKv(String key) async {
return await _mmkv.getString(key);
}
Future<bool> getBoolKv(String key) async {
return await _mmkv.getBool(key);
}
Future<int> getIntKv(String key) async {
return await _mmkv.getInt(key);
}
Future<double> getDoubleKv(String key) async {
return await _mmkv.getDouble(key);
}
Future<bool> clearKv() async{
return await _mmkv.clear();
}
abstract class BlocBase {
void dispose();
}
import 'package:flutter/widgets.dart';
import 'bloc_base.dart';
Type _typeOf<T>() => T;
class BlocProvider<T extends BlocBase> extends StatefulWidget {
BlocProvider({
Key key,
@required this.child,
@required this.blocs,
}) : super(key: key);
final Widget child;
final List<T> blocs;
@override
_BlocProviderState<T> createState() => _BlocProviderState<T>();
static List<T> of<T extends BlocBase>(BuildContext context) {
final type = _typeOf<_BlocProviderInherited<T>>();
_BlocProviderInherited<T> provider =
context.ancestorInheritedElementForWidgetOfExactType(type)?.widget;
return provider?.blocs;
}
}
class _BlocProviderState<T extends BlocBase> extends State<BlocProvider<T>> {
@override
void dispose() {
widget.blocs.map((bloc) {
bloc.dispose();
});
super.dispose();
}
@override
Widget build(BuildContext context) {
return _BlocProviderInherited<T>(
blocs: widget.blocs,
child: widget.child,
);
}
}
class _BlocProviderInherited<T> extends InheritedWidget {
_BlocProviderInherited({
Key key,
@required Widget child,
@required this.blocs,
}) : super(key: key, child: child);
final List<T> blocs;
@override
bool updateShouldNotify(_BlocProviderInherited oldWidget) => false;
}
/*
* @author lsy
* @date 2019-09-04
**/
import 'package:mmkv_flutter/mmkv_flutter.dart';
class MmKvUtil {
static MmkvFlutter _mmkv;
static MmKvUtil mmKvUtil;
MmKvUtil._(MmkvFlutter mmkv) {
_mmkv = mmkv;
}
static Future<MmKvUtil> getInstance() async {
if (mmKvUtil == null) {
final MmkvFlutter _mmkv = await MmkvFlutter.getInstance();
mmKvUtil = new MmKvUtil._(_mmkv);
}
return mmKvUtil;
}
Future saveBoolKv(String key, bool value) async {
return await _mmkv.setBool(key, value);
}
Future saveStringKv(String key, String value) async {
return await _mmkv.setString(key, value);
}
Future saveDoubleKv(String key, double value) async {
return await _mmkv.setDouble(key, value);
}
Future<bool> saveIntKv(String key, int value) async {
return await _mmkv.setInt(key, value);
}
Future<String> getStringKv(String key) async {
return await _mmkv.getString(key);
}
Future<bool> getBoolKv(String key) async {
return await _mmkv.getBool(key);
}
Future<int> getIntKv(String key) async {
return await _mmkv.getInt(key);
}
Future<double> getDoubleKv(String key) async {
return await _mmkv.getDouble(key);
}
Future<bool> clearKv() async {
return await _mmkv.clear();
}
}
This diff is collapsed.
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:flutter_boost/flutter_boost.dart';
import 'package:gmalpha_flutter/Annotations/RouterCenterRestore.mark.dart';
......@@ -6,7 +8,6 @@ import 'package:gmalpha_flutter/commonModel/ui/ALColors.dart';
import 'package:gmalpha_flutter/commonModel/net/DioUtil.dart';
import 'package:dio/dio.dart';
import 'package:gmalpha_flutter/messageModel/home/message_home.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'comment_suggest.dart';
......@@ -43,6 +44,8 @@ class _MyAppState extends State<MyApp> {
DioUtil().setConfig(config);
}
@override
Widget build(BuildContext context) {
return MaterialApp(
......
......@@ -10,6 +10,4 @@ import 'package:gmalpha_flutter/userModel/UserRouterImpl.dart';
@Router("userModel",UserRouterImpl)
abstract class UserRouter implements RouterBaser{
}
\ No newline at end of file
......@@ -6,6 +6,4 @@ import 'package:gmalpha_flutter/userModel/UserRouter.dart';
class UserRouterImpl implements UserRouter{
}
\ No newline at end of file
/*
* @author lsy
* @date 2019-09-04
**/
\ No newline at end of file
/*
* @author lsy
* @date 2019-09-04
**/
import 'package:flutter/material.dart';
import 'package:gmalpha_flutter/userModel/page/user/UserPageModel.dart';
class UserWidget extends StatefulWidget {
@override
State<StatefulWidget> createState() => UserState();
}
class UserState extends State<UserWidget> {
UserPageModel _model;
@override
void initState() {
super.initState();
_model = new UserPageModel();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: ALRootInheritWideget(
model: _model,
child: Center(
child: Text(_model.text),
),
));
}
}
/*
* @author lsy
* @date 2019-09-04
**/
class UserPageModel {
String text;
}
/*
* @author lsy
* @date 2019-09-04
**/
import 'package:gmalpha_flutter/userModel/service/local/UserLocal.dart';
import 'package:gmalpha_flutter/userModel/service/remote/UserRemote.dart';
class UserRepository {
UserRemote _remote;
UserLocal _local;
static UserRepository _userRepository;
UserRepository._() {
_remote = UserRemote.getInstance();
_local = UserLocal.getInstance();
}
static UserRepository getInstance() {
if (_userRepository == null) {
_userRepository = UserRepository._();
}
return _userRepository;
}
}
/*
* @author lsy
* @date 2019-09-04
**/
class UserLocal {
static UserLocal _userRemote;
UserLocal._() {}
static UserLocal getInstance() {
if (_userRemote == null) {
_userRemote = new UserLocal._();
}
return _userRemote;
}
}
/*
* @author lsy
* @date 2019-09-04
**/
class UserRemote {
static UserRemote _userRemote;
UserRemote._() {}
static UserRemote getInstance() {
if (_userRemote == null) {
_userRemote = new UserRemote._();
}
return _userRemote;
}
}
/*
* @author lsy
* @date 2019-09-04
**/
import 'package:gmalpha_flutter/Annotations/anno/Get.dart';
import 'package:gmalpha_flutter/Annotations/anno/Post.dart';
import 'package:gmalpha_flutter/Annotations/anno/Query.dart';
import 'package:gmalpha_flutter/Annotations/anno/ServiceCenter.dart';
import 'package:gmalpha_flutter/userModel/service/remote/entity/UserEntity.dart';
@ServiceCenter()
abstract class UserLoginApi {
@Post("user/login")
UserEntity login(@Query("name") String name, @Query("word") String word);
@Get("user/info")
UserEntity getUserInfo(@Query("token") String token);
}
// GENERATED CODE - DO NOT MODIFY BY HAND
// **************************************************************************
// ServiceGenerator
// **************************************************************************
import 'dart:convert';
import 'dart:io';
import 'package:rxdart/rxdart.dart';
import 'package:gmalpha_flutter/userModel/service/remote/entity/UserEntity.dart';
import 'package:gmalpha_flutter/commonModel/net/DioUtil.dart';
class UserLoginApiImpl {
Observable<UserEntity> login(String name, String word) {
return Observable.fromFuture(
DioUtil().post('user/login', data: {'name': name, 'word': word}))
.map((value) {
if (value.statusCode == 200) {
Map map = json.decode(value.toString());
return UserEntity.fromJson(map);
} else {
throw HttpException("statusCode error :${value.statusCode}");
}
});
}
Observable<UserEntity> getUserInfo(String token) {
return Observable.fromFuture(
DioUtil().get('user/info', data: {'token': token})).map((value) {
if (value.statusCode == 200) {
Map map = json.decode(value.toString());
return UserEntity.fromJson(map);
} else {
throw HttpException("statusCode error :${value.statusCode}");
}
});
}
}
/*
* @author lsy
* @date 2019-09-03
**/
import 'package:gmalpha_flutter/Annotations/anno/User.dart';
import 'package:gmalpha_flutter/Annotations/anno/UserCenter.dart';
import 'package:json_annotation/json_annotation.dart';
const String USER_ID = "user_uid";
const String NICKNAME = "username";
......@@ -21,72 +18,143 @@ const String COUNTRY_LANGUAGE = "country_language";
const String COUNTRY_NAME = "country_name";
@UserCenter()
class UserUtil {
class UserEntity {
/**
* 用户id
*/
@User(USER_ID, "")
String User_id;
String userId;
/**
* 用户昵称
*/
@User(NICKNAME, "")
String nick_name;
String nickName;
/**
* 用户头像
*/
@User(PORTRAIT,"")
String profile_pic;
String profilePic;
/**
* 是否需要答题
*/
@User(PERSONAL_QA,true)
bool has_answered = true;
bool hasAnswered = true;
/**
* 是否扫过脸
*/
@User(HAS_SCAN_FACE,true)
bool has_scan_face = false;
bool hasScanFace = false;
String id;
@User(GENDER,"")
String gender;
@User(CURRENT_CITY_ID,"")
String city_id;
String cityId;
@User(BIRTHDAY,0)
int birth;
@User(COUNTRY_ID,"")
String country_id;
String countryId;
bool logined;
// 用户是否设置过个人信息
@User(DETAIL_SETTED,true)
bool detail_setted = true;
bool detailSetted = true;
//用户是否选择了标签
bool tag_setted = false;
bool tagSetted = false;
//注册流程中断后返回之前的登录页面
@User(QUESTION_URL,"")
String question_url;
String questionUrl;
@User(USER_BIND_MOBILE,true)
bool is_bind;
bool isBind;
@User(COUNTRY_NAME,"")
String country_info_name;
String countryInfoName;
@User(COUNTRY_ID,"")
String country_info_id;
String countryInfoId;
@User(COUNTRY_LANGUAGE,"")
String country_info_language;
String countryInfoLanguage;
String insBindId;
String registerTime;
UserEntity(
{this.userId,
this.nickName,
this.profilePic,
this.hasAnswered,
this.hasScanFace,
this.id,
this.gender,
this.cityId,
this.birth,
this.countryId,
this.logined,
this.detailSetted,
this.tagSetted,
this.questionUrl,
this.isBind,
this.countryInfoName,
this.countryInfoId,
this.countryInfoLanguage,
this.insBindId,
this.registerTime});
UserEntity.fromJson(Map<String, dynamic> json) {
userId = json['user_id'];
nickName = json['nick_name'];
profilePic = json['profile_pic'];
hasAnswered = json['has_answered'];
hasScanFace = json['has_scan_face'];
id = json['id'];
gender = json['gender'];
cityId = json['city_id'];
birth = json['birth'];
countryId = json['country_id'];
logined = json['logined'];
detailSetted = json['detail_setted'];
tagSetted = json['tag_setted'];
questionUrl = json['question_url'];
isBind = json['is_bind'];
countryInfoName = json['country_info_name'];
countryInfoId = json['country_info_id'];
countryInfoLanguage = json['country_info_language'];
insBindId = json['ins_bind_id'];
registerTime = json['register_time'];
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['user_id'] = this.userId;
data['nick_name'] = this.nickName;
data['profile_pic'] = this.profilePic;
data['has_answered'] = this.hasAnswered;
data['has_scan_face'] = this.hasScanFace;
data['id'] = this.id;
data['gender'] = this.gender;
data['city_id'] = this.cityId;
data['birth'] = this.birth;
data['country_id'] = this.countryId;
data['logined'] = this.logined;
data['detail_setted'] = this.detailSetted;
data['tag_setted'] = this.tagSetted;
data['question_url'] = this.questionUrl;
data['is_bind'] = this.isBind;
data['country_info_name'] = this.countryInfoName;
data['country_info_id'] = this.countryInfoId;
data['country_info_language'] = this.countryInfoLanguage;
data['ins_bind_id'] = this.insBindId;
data['register_time'] = this.registerTime;
return data;
}
String ins_bind_id;
String register_time;
}
// GENERATED CODE - DO NOT MODIFY BY HAND
// **************************************************************************
// UserGenerator
// **************************************************************************
import 'package:rxdart/rxdart.dart';
import 'package:gmalpha_flutter/commonModel/app_module.dart';
class UserEntityImpl {
factory UserEntityImpl() => _sharedInstance();
static UserEntityImpl _instance;
UserEntityImpl._() {}
static UserEntityImpl _sharedInstance() {
if (_instance == null) {
_instance = UserEntityImpl._();
}
return _instance;
}
String _userId;
Observable<bool> saveuserId(String userId) {
return Observable.fromFuture(mmKvUtil.saveStringKv("user_uid", userId))
.map((value) {
if (value) {
this._userId = userId;
}
return value;
});
}
Observable<String> getuserId() {
if (_userId != null) {
return Observable.fromFuture(Future.value(_userId));
}
return Observable.fromFuture(mmKvUtil.getStringKv("user_uid"));
}
String _nickName;
Observable<bool> savenickName(String nickName) {
return Observable.fromFuture(mmKvUtil.saveStringKv("username", nickName))
.map((value) {
if (value) {
this._nickName = nickName;
}
return value;
});
}
Observable<String> getnickName() {
if (_nickName != null) {
return Observable.fromFuture(Future.value(_nickName));
}
return Observable.fromFuture(mmKvUtil.getStringKv("username"));
}
String _profilePic;
Observable<bool> saveprofilePic(String profilePic) {
return Observable.fromFuture(mmKvUtil.saveStringKv("potrait", profilePic))
.map((value) {
if (value) {
this._profilePic = profilePic;
}
return value;
});
}
Observable<String> getprofilePic() {
if (_profilePic != null) {
return Observable.fromFuture(Future.value(_profilePic));
}
return Observable.fromFuture(mmKvUtil.getStringKv("potrait"));
}
bool _hasAnswered;
Observable<bool> savehasAnswered(bool hasAnswered) {
return Observable.fromFuture(
mmKvUtil.saveBoolKv("personal_qa", hasAnswered))
.map((value) {
if (value) {
this._hasAnswered = hasAnswered;
}
return value;
});
}
Observable<bool> gethasAnswered() {
if (_hasAnswered != null) {
return Observable.fromFuture(Future.value(_hasAnswered));
}
return Observable.fromFuture(mmKvUtil.getBoolKv("personal_qa"));
}
bool _hasScanFace;
Observable<bool> savehasScanFace(bool hasScanFace) {
return Observable.fromFuture(
mmKvUtil.saveBoolKv("has_scan_face", hasScanFace))
.map((value) {
if (value) {
this._hasScanFace = hasScanFace;
}
return value;
});
}
Observable<bool> gethasScanFace() {
if (_hasScanFace != null) {
return Observable.fromFuture(Future.value(_hasScanFace));
}
return Observable.fromFuture(mmKvUtil.getBoolKv("has_scan_face"));
}
String _gender;
Observable<bool> savegender(String gender) {
return Observable.fromFuture(mmKvUtil.saveStringKv("gender", gender))
.map((value) {
if (value) {
this._gender = gender;
}
return value;
});
}
Observable<String> getgender() {
if (_gender != null) {
return Observable.fromFuture(Future.value(_gender));
}
return Observable.fromFuture(mmKvUtil.getStringKv("gender"));
}
String _cityId;
Observable<bool> savecityId(String cityId) {
return Observable.fromFuture(
mmKvUtil.saveStringKv("current_city_id", cityId))
.map((value) {
if (value) {
this._cityId = cityId;
}
return value;
});
}
Observable<String> getcityId() {
if (_cityId != null) {
return Observable.fromFuture(Future.value(_cityId));
}
return Observable.fromFuture(mmKvUtil.getStringKv("current_city_id"));
}
int _birth;
Observable<bool> savebirth(int birth) {
return Observable.fromFuture(mmKvUtil.saveIntKv("birthday", birth))
.map((value) {
if (value) {
this._birth = birth;
}
return value;
});
}
Observable<int> getbirth() {
if (_birth != null) {
return Observable.fromFuture(Future.value(_birth));
}
return Observable.fromFuture(mmKvUtil.getIntKv("birthday"));
}
String _countryId;
Observable<bool> savecountryId(String countryId) {
return Observable.fromFuture(mmKvUtil.saveStringKv("country_id", countryId))
.map((value) {
if (value) {
this._countryId = countryId;
}
return value;
});
}
Observable<String> getcountryId() {
if (_countryId != null) {
return Observable.fromFuture(Future.value(_countryId));
}
return Observable.fromFuture(mmKvUtil.getStringKv("country_id"));
}
bool _detailSetted;
Observable<bool> savedetailSetted(bool detailSetted) {
return Observable.fromFuture(
mmKvUtil.saveBoolKv("detail_setted", detailSetted))
.map((value) {
if (value) {
this._detailSetted = detailSetted;
}
return value;
});
}
Observable<bool> getdetailSetted() {
if (_detailSetted != null) {
return Observable.fromFuture(Future.value(_detailSetted));
}
return Observable.fromFuture(mmKvUtil.getBoolKv("detail_setted"));
}
String _questionUrl;
Observable<bool> savequestionUrl(String questionUrl) {
return Observable.fromFuture(
mmKvUtil.saveStringKv("question_url", questionUrl))
.map((value) {
if (value) {
this._questionUrl = questionUrl;
}
return value;
});
}
Observable<String> getquestionUrl() {
if (_questionUrl != null) {
return Observable.fromFuture(Future.value(_questionUrl));
}
return Observable.fromFuture(mmKvUtil.getStringKv("question_url"));
}
bool _isBind;
Observable<bool> saveisBind(bool isBind) {
return Observable.fromFuture(
mmKvUtil.saveBoolKv("user_bind_mobile", isBind))
.map((value) {
if (value) {
this._isBind = isBind;
}
return value;
});
}
Observable<bool> getisBind() {
if (_isBind != null) {
return Observable.fromFuture(Future.value(_isBind));
}
return Observable.fromFuture(mmKvUtil.getBoolKv("user_bind_mobile"));
}
String _countryInfoName;
Observable<bool> savecountryInfoName(String countryInfoName) {
return Observable.fromFuture(
mmKvUtil.saveStringKv("country_name", countryInfoName))
.map((value) {
if (value) {
this._countryInfoName = countryInfoName;
}
return value;
});
}
Observable<String> getcountryInfoName() {
if (_countryInfoName != null) {
return Observable.fromFuture(Future.value(_countryInfoName));
}
return Observable.fromFuture(mmKvUtil.getStringKv("country_name"));
}
String _countryInfoId;
Observable<bool> savecountryInfoId(String countryInfoId) {
return Observable.fromFuture(
mmKvUtil.saveStringKv("country_id", countryInfoId))
.map((value) {
if (value) {
this._countryInfoId = countryInfoId;
}
return value;
});
}
Observable<String> getcountryInfoId() {
if (_countryInfoId != null) {
return Observable.fromFuture(Future.value(_countryInfoId));
}
return Observable.fromFuture(mmKvUtil.getStringKv("country_id"));
}
String _countryInfoLanguage;
Observable<bool> savecountryInfoLanguage(String countryInfoLanguage) {
return Observable.fromFuture(
mmKvUtil.saveStringKv("country_language", countryInfoLanguage))
.map((value) {
if (value) {
this._countryInfoLanguage = countryInfoLanguage;
}
return value;
});
}
Observable<String> getcountryInfoLanguage() {
if (_countryInfoLanguage != null) {
return Observable.fromFuture(Future.value(_countryInfoLanguage));
}
return Observable.fromFuture(mmKvUtil.getStringKv("country_language"));
}
}
// GENERATED CODE - DO NOT MODIFY BY HAND
// **************************************************************************
// UserGenerator
// **************************************************************************
import 'package:rxdart/rxdart.dart';
import 'package:gmalpha_flutter/commonModel/app_module.dart';
class UserCenterImpl {
factory UserCenterImpl() => _sharedInstance();
static UserCenterImpl _instance;
UserCenterImpl._() {}
static UserCenterImpl _sharedInstance() {
if (_instance == null) {
_instance = UserCenterImpl._();
}
return _instance;
}
String _User_id;
Observable<bool> saveUser_id(String User_id) {
return Observable.fromFuture(saveStringKv("user_uid", User_id))
.map((value) {
if (value) {
this._User_id = User_id;
}
return value;
});
}
Observable<String> getUser_id() {
if (_User_id != null) {
return Observable.fromFuture(Future.value(_User_id));
}
return Observable.fromFuture(getStringKv("user_uid"));
}
String _nick_name;
Observable<bool> savenick_name(String nick_name) {
return Observable.fromFuture(saveStringKv("username", nick_name))
.map((value) {
if (value) {
this._nick_name = nick_name;
}
return value;
});
}
Observable<String> getnick_name() {
if (_nick_name != null) {
return Observable.fromFuture(Future.value(_nick_name));
}
return Observable.fromFuture(getStringKv("username"));
}
String _profile_pic;
Observable<bool> saveprofile_pic(String profile_pic) {
return Observable.fromFuture(saveStringKv("potrait", profile_pic))
.map((value) {
if (value) {
this._profile_pic = profile_pic;
}
return value;
});
}
Observable<String> getprofile_pic() {
if (_profile_pic != null) {
return Observable.fromFuture(Future.value(_profile_pic));
}
return Observable.fromFuture(getStringKv("potrait"));
}
bool _has_answered;
Observable<bool> savehas_answered(bool has_answered) {
return Observable.fromFuture(saveBoolKv("personal_qa", has_answered))
.map((value) {
if (value) {
this._has_answered = has_answered;
}
return value;
});
}
Observable<bool> gethas_answered() {
if (_has_answered != null) {
return Observable.fromFuture(Future.value(_has_answered));
}
return Observable.fromFuture(getBoolKv("personal_qa"));
}
bool _has_scan_face;
Observable<bool> savehas_scan_face(bool has_scan_face) {
return Observable.fromFuture(saveBoolKv("has_scan_face", has_scan_face))
.map((value) {
if (value) {
this._has_scan_face = has_scan_face;
}
return value;
});
}
Observable<bool> gethas_scan_face() {
if (_has_scan_face != null) {
return Observable.fromFuture(Future.value(_has_scan_face));
}
return Observable.fromFuture(getBoolKv("has_scan_face"));
}
String _gender;
Observable<bool> savegender(String gender) {
return Observable.fromFuture(saveStringKv("gender", gender)).map((value) {
if (value) {
this._gender = gender;
}
return value;
});
}
Observable<String> getgender() {
if (_gender != null) {
return Observable.fromFuture(Future.value(_gender));
}
return Observable.fromFuture(getStringKv("gender"));
}
String _city_id;
Observable<bool> savecity_id(String city_id) {
return Observable.fromFuture(saveStringKv("current_city_id", city_id))
.map((value) {
if (value) {
this._city_id = city_id;
}
return value;
});
}
Observable<String> getcity_id() {
if (_city_id != null) {
return Observable.fromFuture(Future.value(_city_id));
}
return Observable.fromFuture(getStringKv("current_city_id"));
}
int _birth;
Observable<bool> savebirth(int birth) {
return Observable.fromFuture(saveIntKv("birthday", birth)).map((value) {
if (value) {
this._birth = birth;
}
return value;
});
}
Observable<int> getbirth() {
if (_birth != null) {
return Observable.fromFuture(Future.value(_birth));
}
return Observable.fromFuture(getIntKv("birthday"));
}
String _country_id;
Observable<bool> savecountry_id(String country_id) {
return Observable.fromFuture(saveStringKv("country_id", country_id))
.map((value) {
if (value) {
this._country_id = country_id;
}
return value;
});
}
Observable<String> getcountry_id() {
if (_country_id != null) {
return Observable.fromFuture(Future.value(_country_id));
}
return Observable.fromFuture(getStringKv("country_id"));
}
bool _detail_setted;
Observable<bool> savedetail_setted(bool detail_setted) {
return Observable.fromFuture(saveBoolKv("detail_setted", detail_setted))
.map((value) {
if (value) {
this._detail_setted = detail_setted;
}
return value;
});
}
Observable<bool> getdetail_setted() {
if (_detail_setted != null) {
return Observable.fromFuture(Future.value(_detail_setted));
}
return Observable.fromFuture(getBoolKv("detail_setted"));
}
String _question_url;
Observable<bool> savequestion_url(String question_url) {
return Observable.fromFuture(saveStringKv("question_url", question_url))
.map((value) {
if (value) {
this._question_url = question_url;
}
return value;
});
}
Observable<String> getquestion_url() {
if (_question_url != null) {
return Observable.fromFuture(Future.value(_question_url));
}
return Observable.fromFuture(getStringKv("question_url"));
}
bool _is_bind;
Observable<bool> saveis_bind(bool is_bind) {
return Observable.fromFuture(saveBoolKv("user_bind_mobile", is_bind))
.map((value) {
if (value) {
this._is_bind = is_bind;
}
return value;
});
}
Observable<bool> getis_bind() {
if (_is_bind != null) {
return Observable.fromFuture(Future.value(_is_bind));
}
return Observable.fromFuture(getBoolKv("user_bind_mobile"));
}
String _country_info_name;
Observable<bool> savecountry_info_name(String country_info_name) {
return Observable.fromFuture(
saveStringKv("country_name", country_info_name))
.map((value) {
if (value) {
this._country_info_name = country_info_name;
}
return value;
});
}
Observable<String> getcountry_info_name() {
if (_country_info_name != null) {
return Observable.fromFuture(Future.value(_country_info_name));
}
return Observable.fromFuture(getStringKv("country_name"));
}
String _country_info_id;
Observable<bool> savecountry_info_id(String country_info_id) {
return Observable.fromFuture(saveStringKv("country_id", country_info_id))
.map((value) {
if (value) {
this._country_info_id = country_info_id;
}
return value;
});
}
Observable<String> getcountry_info_id() {
if (_country_info_id != null) {
return Observable.fromFuture(Future.value(_country_info_id));
}
return Observable.fromFuture(getStringKv("country_id"));
}
String _country_info_language;
Observable<bool> savecountry_info_language(String country_info_language) {
return Observable.fromFuture(
saveStringKv("country_language", country_info_language))
.map((value) {
if (value) {
this._country_info_language = country_info_language;
}
return value;
});
}
Observable<String> getcountry_info_language() {
if (_country_info_language != null) {
return Observable.fromFuture(Future.value(_country_info_language));
}
return Observable.fromFuture(getStringKv("country_language"));
}
}
......@@ -58,7 +58,7 @@ packages:
source: hosted
version: "1.0.5"
build_runner:
dependency: "direct main"
dependency: "direct dev"
description:
name: build_runner
url: "https://pub.flutter-io.cn"
......@@ -250,14 +250,7 @@ packages:
name: json_annotation
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.4.0"
json_serializable:
dependency: "direct main"
description:
name: json_serializable
url: "https://pub.flutter-io.cn"
source: hosted
version: "3.0.0"
version: "2.3.0"
kernel:
dependency: transitive
description:
......@@ -294,7 +287,7 @@ packages:
source: hosted
version: "0.9.6+3"
mmkv_flutter:
dependency: "direct dev"
dependency: "direct main"
description:
name: mmkv_flutter
url: "https://pub.flutter-io.cn"
......@@ -370,13 +363,6 @@ packages:
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.22.0"
shared_preferences:
dependency: "direct main"
description:
name: shared_preferences
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.4.3"
shelf:
dependency: transitive
description:
......
......@@ -28,18 +28,19 @@ dependencies:
cupertino_icons: ^0.1.2
dio: ^2.1.0
rxdart: ^0.22.0 #链式编程
json_serializable: ^3.0.0 #json to model
build_runner: ^1.6.1
# json_serializable: ^3.0.0 #json to model
pull_to_refresh: ^1.5.0
shared_preferences: ^0.4.3
# shared_preferences: ^0.4.3
# flutter_easyrefresh: ^1.2.7 # 上拉下拉刷新组件
mmkv_flutter: ^1.0.10
dev_dependencies:
source_gen: '>=0.8.0'
build_runner: ^1.6.1
mmkv_flutter:
flutter_test:
sdk: flutter
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment