Commit dd249077 authored by 林生雨's avatar 林生雨

add User

parent a1979212
......@@ -2,6 +2,8 @@ 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;
/**
......@@ -13,6 +15,8 @@ public final class GeneratedPluginRegistrant {
return;
}
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"));
}
......
......@@ -4,12 +4,16 @@
#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
+ (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"]];
}
......
......@@ -18,5 +18,7 @@ Depends on all your plugins, and provides a function to register them.
s.public_header_files = './Classes/**/*.h'
s.dependency 'Flutter'
s.dependency 'flutter_boost'
s.dependency 'mmkv_flutter'
s.dependency 'shared_preferences'
s.dependency 'xservice_kit'
end
// This is a generated file; do not edit or check into version control.
FLUTTER_ROOT=/Users/apple/Downloads/flutter
FLUTTER_APPLICATION_PATH=/Users/apple/lsy/gmalpha_flutter
FLUTTER_TARGET=/Users/apple/lsy/gmalpha_flutter/lib/main.dart
FLUTTER_TARGET=lib/main.dart
FLUTTER_BUILD_DIR=build
SYMROOT=${SOURCE_ROOT}/../build/ios
FLUTTER_BUILD_NAME=1.0.0
FLUTTER_BUILD_NUMBER=1
TRACK_WIDGET_CREATION=true
......@@ -17,7 +17,6 @@
97C146FC1CF9000F007C117D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FA1CF9000F007C117D /* Main.storyboard */; };
97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FD1CF9000F007C117D /* Assets.xcassets */; };
97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */; };
A7A6122996CF102E7F82F859 /* libPods-Runner.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 878475123B5CDE12FAC05E35 /* libPods-Runner.a */; };
/* End PBXBuildFile section */
/* Begin PBXCopyFilesBuildPhase section */
......@@ -36,9 +35,6 @@
/* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */
3B3FD0A824761CC9C4CD789E /* Pods-Runner.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.debug.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"; sourceTree = "<group>"; };
4320B48CFDC817024282E14A /* Pods-Runner.profile.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.profile.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.profile.xcconfig"; sourceTree = "<group>"; };
55467A5E39D4CD9B334CABBB /* Pods-Runner.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.release.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"; sourceTree = "<group>"; };
741F495E21355F27001E2961 /* Flutter.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Flutter.framework; path = ../.ios/Flutter/engine/Flutter.framework; sourceTree = "<group>"; };
741F496521356807001E2961 /* App.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = App.framework; path = ../.ios/Flutter/App.framework; sourceTree = "<group>"; };
74974046213559DB008C567A /* Release.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = Release.xcconfig; sourceTree = "<group>"; };
......@@ -46,7 +42,6 @@
7497404A213559E7008C567A /* Flutter.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = Flutter.xcconfig; sourceTree = "<group>"; };
7AFFD8ED1D35381100E5BB4D /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; };
878475123B5CDE12FAC05E35 /* libPods-Runner.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-Runner.a"; sourceTree = BUILT_PRODUCTS_DIR; };
9740EEB31CF90195004384FC /* Generated.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Generated.xcconfig; path = ../.ios/Flutter/Generated.xcconfig; sourceTree = "<group>"; };
97C146EE1CF9000F007C117D /* Runner.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Runner.app; sourceTree = BUILT_PRODUCTS_DIR; };
97C146F21CF9000F007C117D /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
......@@ -61,32 +56,12 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
A7A6122996CF102E7F82F859 /* libPods-Runner.a in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
0270612669853706A23ABA01 /* Pods */ = {
isa = PBXGroup;
children = (
3B3FD0A824761CC9C4CD789E /* Pods-Runner.debug.xcconfig */,
55467A5E39D4CD9B334CABBB /* Pods-Runner.release.xcconfig */,
4320B48CFDC817024282E14A /* Pods-Runner.profile.xcconfig */,
);
name = Pods;
path = Pods;
sourceTree = "<group>";
};
4BA141D04B6B878EE05D7845 /* Frameworks */ = {
isa = PBXGroup;
children = (
878475123B5CDE12FAC05E35 /* libPods-Runner.a */,
);
name = Frameworks;
sourceTree = "<group>";
};
741F49642135620F001E2961 /* Config */ = {
isa = PBXGroup;
children = (
......@@ -114,8 +89,6 @@
9740EEB11CF90186004384FC /* Flutter */,
97C146F01CF9000F007C117D /* Runner */,
97C146EF1CF9000F007C117D /* Products */,
0270612669853706A23ABA01 /* Pods */,
4BA141D04B6B878EE05D7845 /* Frameworks */,
);
sourceTree = "<group>";
};
......@@ -156,14 +129,12 @@
isa = PBXNativeTarget;
buildConfigurationList = 97C147051CF9000F007C117D /* Build configuration list for PBXNativeTarget "Runner" */;
buildPhases = (
1B6D00315C3FDE7009CDD3EE /* [CP] Check Pods Manifest.lock */,
9740EEB61CF901F6004384FC /* Run Script */,
97C146EA1CF9000F007C117D /* Sources */,
97C146EB1CF9000F007C117D /* Frameworks */,
97C146EC1CF9000F007C117D /* Resources */,
3B06AD1E1E4923F5004D2608 /* Thin Binary */,
741F496321355F47001E2961 /* Embed Frameworks */,
6448A595DCF7381AC9CE2BA3 /* [CP] Embed Pods Frameworks */,
);
buildRules = (
);
......@@ -223,28 +194,6 @@
/* End PBXResourcesBuildPhase section */
/* Begin PBXShellScriptBuildPhase section */
1B6D00315C3FDE7009CDD3EE /* [CP] Check Pods Manifest.lock */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
);
inputPaths = (
"${PODS_PODFILE_DIR_PATH}/Podfile.lock",
"${PODS_ROOT}/Manifest.lock",
);
name = "[CP] Check Pods Manifest.lock";
outputFileListPaths = (
);
outputPaths = (
"$(DERIVED_FILE_DIR)/Pods-Runner-checkManifestLockResult.txt",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
showEnvVarsInLog = 0;
};
3B06AD1E1E4923F5004D2608 /* Thin Binary */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
......@@ -259,24 +208,6 @@
shellPath = /bin/sh;
shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" thin";
};
6448A595DCF7381AC9CE2BA3 /* [CP] Embed Pods Frameworks */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh",
"${PODS_ROOT}/../Flutter/engine/Flutter.framework",
);
name = "[CP] Embed Pods Frameworks";
outputPaths = (
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Flutter.framework",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh\"\n";
showEnvVarsInLog = 0;
};
9740EEB61CF901F6004384FC /* Run Script */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
......@@ -575,6 +506,7 @@
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
rootObject = 97C146E61CF9000F007C117D /* Project object */;
}
......@@ -4,7 +4,4 @@
<FileRef
location = "group:Runner.xcodeproj">
</FileRef>
<FileRef
location = "group:Pods/Pods.xcodeproj">
</FileRef>
</Workspace>
flutter packages pub run build_runner clean
flutter packages pub run build_runner build
\ No newline at end of file
flutter packages pub run build_runner build --delete-conflicting-outputs
\ No newline at end of file
......@@ -7,8 +7,15 @@ targets:
builders:
user:
import: "package:gmalpha_flutter/Annotations/RouterBuilder.dart"
builder_factories: ["userBuilder"]
build_extensions: {'.dart': ['.user.dart'] }
auto_apply: root_package
build_to: source
Router:
import: "package:gmalpha_flutter/Router/RouterBuilder.dart"
import: "package:gmalpha_flutter/Annotations/RouterBuilder.dart"
builder_factories: ["routerBuilder"]
build_extensions: {'.dart': ['.rout.dart'] }
auto_apply: root_package
......@@ -17,13 +24,19 @@ builders:
routerCenter:
import: "package:gmalpha_flutter/Router/RouterBuilder.dart"
import: "package:gmalpha_flutter/Annotations/RouterBuilder.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"]}
# 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";
}
......@@ -4,11 +4,11 @@
**/
import 'package:analyzer/dart/element/element.dart';
import 'package:build/src/builder/build_step.dart';
import 'package:gmalpha_flutter/Router/RouterBaser.dart';
import 'package:gmalpha_flutter/Router/anno/RouterCenter.dart';
import 'package:gmalpha_flutter/Router/RouterCenterRestore.dart';
import 'package:gmalpha_flutter/Annotations/anno/RouterCenter.dart';
import 'package:source_gen/source_gen.dart';
import '../RouterCenterRestore.dart';
class RouterCenterGenerator extends GeneratorForAnnotation<RouterCenter> {
@override
generateForAnnotatedElement(
......
......@@ -6,12 +6,12 @@ import 'dart:math';
import 'package:analyzer/dart/element/element.dart';
import 'package:build/src/builder/build_step.dart';
import 'package:gmalpha_flutter/Router/base/RouterBuildItem.dart';
import 'package:gmalpha_flutter/Router/anno/Router.dart';
import 'package:gmalpha_flutter/Router/anno/RouterCenter.dart';
import 'package:gmalpha_flutter/Router/RouterCenterRestore.dart';
import 'package:gmalpha_flutter/Annotations/anno/Router.dart';
import 'package:gmalpha_flutter/Annotations/base/RouterBuildItem.dart';
import 'package:source_gen/source_gen.dart';
import '../RouterCenterRestore.dart';
class RouterGenerator extends GeneratorForAnnotation<Router> {
@override
generateForAnnotatedElement(
......
/*
* @author lsy
* @date 2019-09-02
**/
import 'dart:math';
import 'package:analyzer/dart/element/element.dart';
import 'package:build/src/builder/build_step.dart';
import 'package:gmalpha_flutter/Annotations/anno/User.dart';
import 'package:gmalpha_flutter/Annotations/anno/UserCenter.dart';
import 'package:gmalpha_flutter/Annotations/base/RouterBuildItem.dart';
import 'package:source_gen/source_gen.dart';
import '../RouterCenterRestore.dart';
Map<String, String> map = {};
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) {
final metadata = annometadata.computeConstantValue();
// final metadatatype = annometadata.runtimeType;
// print("metadatatype is $metadatatype");
// print("metadataNAME is ${metadata.type.name}");
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}))
.map((value){
if(value){
this._${fieldData.name}=${fieldData.name};
}
return value;
});
}
Observable<String> get${fieldData.name}(){
if(_${fieldData.name}!=null){
return Observable.fromFuture(Future.value("_${fieldData.name}"));
}
return Observable.fromFuture(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}))
.map((value){
if(value){
this._${fieldData.name}=${fieldData.name};
}
return value;
});
}
Observable<int> get${fieldData.name}(){
if(_${fieldData.name}!=null){
return Observable.fromFuture(Future.value(_${fieldData.name}));
}
return Observable.fromFuture(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}))
.map((value){
if(value){
this._${fieldData.name}=${fieldData.name};
}
return value;
});
}
Observable<double> get${fieldData.name}(){
if(_${fieldData.name}!=null){
return Observable.fromFuture(Future.value(_${fieldData.name}));
}
return Observable.fromFuture(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}))
.map((value){
if(value){
this._${fieldData.name}=${fieldData.name};
}
return value;
});
}
Observable<bool> get${fieldData.name}(){
if(_${fieldData.name}!=null){
return Observable.fromFuture(Future.value(_${fieldData.name}));
}
return Observable.fromFuture(getBoolKv("${key}"));
}
""");
}
}
}
}
return """
import 'package:rxdart/rxdart.dart';
import 'package:${buildStep.inputId.package}/commonModel/app_module.dart';
class UserCenterImpl{
factory UserCenterImpl() => _sharedInstance();
static UserCenterImpl _instance;
UserCenterImpl._() {
}
static UserCenterImpl _sharedInstance() {
if (_instance == null) {
_instance = UserCenterImpl._();
}
return _instance;
}
${buffer.toString()}
}
""";
}
}
import 'package:gmalpha_flutter/Router/Generator/RouterGenerator.dart';
import 'package:gmalpha_flutter/Router/Generator/RouterCenterGenerator.dart';
import 'package:gmalpha_flutter/Annotations/Generator/ApiBuilderGenerator.dart';
import 'package:gmalpha_flutter/Annotations/Generator/UserGenerator.dart';
import 'package:source_gen/source_gen.dart';
import 'package:build/src/builder/builder.dart';
import 'Generator/RouterCenterGenerator.dart';
import 'Generator/RouterGenerator.dart';
Builder routerBuilder(BuilderOptions options) =>
LibraryBuilder(RouterGenerator(), generatedExtension: ".rout.dart");
......@@ -10,3 +13,10 @@ Builder routerBuilder(BuilderOptions options) =>
Builder routerCenterBuilder(BuilderOptions options) =>
LibraryBuilder(RouterCenterGenerator(), generatedExtension: ".mark.dart");
Builder userBuilder(BuilderOptions options)=>
LibraryBuilder(UserGenerator(),generatedExtension: ".user.dart");
Builder apiBuilder(BuilderOptions options) {
print("xxxx");
return SharedPartBuilder([ApiBuilderGenerator()], "api_generator");
}
......@@ -2,9 +2,9 @@
* @author lsy
* @date 2019-09-02
**/
import 'package:gmalpha_flutter/Router/base/RouterBuildItem.dart';
import 'package:gmalpha_flutter/Router/RouterBaser.dart';
import 'package:gmalpha_flutter/Router/anno/RouterCenter.dart';
import 'anno/RouterCenter.dart';
import 'base/RouterBuildItem.dart';
@RouterCenter()
class RouterCenterRestore {
......
......@@ -6,9 +6,11 @@
import "package:gmalpha_flutter/messageModel/MessageRouterImpl.dart";
import "package:gmalpha_flutter/messageModel/MessageRouter.dart";
import "package:gmalpha_flutter/userModel/UserRouterImpl.dart";
import "package:gmalpha_flutter/userModel/UserRouter.dart";
import "package:gmalpha_flutter/Router/RouterCenterRestore.dart";
import "package:gmalpha_flutter/Router/RouterBaser.dart";
import "package:gmalpha_flutter/Annotations/RouterCenterRestore.dart";
import "package:gmalpha_flutter/Annotations/RouterBaser.dart";
class RouterCenterImpl {
Map<String, RouterBaser> map;
......@@ -35,6 +37,7 @@ class RouterCenterImpl {
void init() {
map.putIfAbsent("messageModel", () => MessageRouterImpl());
map.putIfAbsent("userModel", () => UserRouterImpl());
}
RouterBaser getModel(String modelName) {
......@@ -47,4 +50,11 @@ class RouterCenterImpl {
}
return map["messageModel"] as MessageRouter;
}
UserRouter findUserRouter() {
if (map["userModel"] == null) {
return null;
}
return map["userModel"] as UserRouter;
}
}
/*
* @author lsy
* @date 2019-09-03
**/
library User;
class User {
final String key;
final Object type;
const User(this.key, this.type);
}
/*
* @author lsy
* @date 2019-09-03
**/
library UserCenter;
class UserCenter {
const UserCenter();
}
import 'package:gmalpha_flutter/userModel/user/UserUtil.user.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:mmkv_flutter/mmkv_flutter.dart';
MmkvFlutter _mmkv;
applicationInit() async {
_mmkv = await MmkvFlutter.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();
}
import 'package:flutter/material.dart';
import 'package:flutter_boost/flutter_boost.dart';
import 'package:gmalpha_flutter/Router/RouterCenterRestore.mark.dart';
import 'package:gmalpha_flutter/Annotations/RouterCenterRestore.mark.dart';
import 'package:gmalpha_flutter/commonModel/app_module.dart';
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';
......
......@@ -4,8 +4,8 @@
**/
import 'package:flutter/cupertino.dart';
import 'package:gmalpha_flutter/Router/RouterBaser.dart';
import 'package:gmalpha_flutter/Router/anno/Router.dart';
import 'package:gmalpha_flutter/Annotations/RouterBaser.dart';
import 'package:gmalpha_flutter/Annotations/anno/Router.dart';
import 'package:gmalpha_flutter/messageModel/MessageRouterImpl.dart';
@Router("messageModel",MessageRouterImpl)
......
/*
* @author lsy
* @date 2019-09-03
**/
import 'package:gmalpha_flutter/Annotations/RouterBaser.dart';
import 'package:gmalpha_flutter/Annotations/anno/Router.dart';
import 'package:gmalpha_flutter/userModel/UserRouterImpl.dart';
@Router("userModel",UserRouterImpl)
abstract class UserRouter implements RouterBaser{
}
\ No newline at end of file
/*
* @author lsy
* @date 2019-09-03
**/
import 'package:gmalpha_flutter/userModel/UserRouter.dart';
class UserRouterImpl implements UserRouter{
}
\ No newline at end of file
/*
* @author lsy
* @date 2019-09-03
**/
import 'package:gmalpha_flutter/Annotations/anno/User.dart';
import 'package:gmalpha_flutter/Annotations/anno/UserCenter.dart';
const String USER_ID = "user_uid";
const String NICKNAME = "username";
const String PORTRAIT = "potrait";
const String GENDER = "gender";
const String PERSONAL_QA = "personal_qa";
const String HAS_SCAN_FACE = "has_scan_face";
const String CURRENT_CITY_ID = "current_city_id";
const String QUESTION_URL = "question_url";
const String DETAIL_SETTED = "detail_setted";
const String BIRTHDAY = "birthday";
const String COUNTRY_ID = "country_id";
const String USER_BIND_MOBILE = "user_bind_mobile";
const String COUNTRY_LANGUAGE = "country_language";
const String COUNTRY_NAME = "country_name";
@UserCenter()
class UserUtil {
/**
* 用户id
*/
@User(USER_ID, "")
String User_id;
/**
* 用户昵称
*/
@User(NICKNAME, "")
String nick_name;
/**
* 用户头像
*/
@User(PORTRAIT,"")
String profile_pic;
/**
* 是否需要答题
*/
@User(PERSONAL_QA,true)
bool has_answered = true;
/**
* 是否扫过脸
*/
@User(HAS_SCAN_FACE,true)
bool has_scan_face = false;
String id;
@User(GENDER,"")
String gender;
@User(CURRENT_CITY_ID,"")
String city_id;
@User(BIRTHDAY,0)
int birth;
@User(COUNTRY_ID,"")
String country_id;
bool logined;
// 用户是否设置过个人信息
@User(DETAIL_SETTED,true)
bool detail_setted = true;
//用户是否选择了标签
bool tag_setted = false;
//注册流程中断后返回之前的登录页面
@User(QUESTION_URL,"")
String question_url;
@User(USER_BIND_MOBILE,true)
bool is_bind;
@User(COUNTRY_NAME,"")
String country_info_name;
@User(COUNTRY_ID,"")
String country_info_id;
@User(COUNTRY_LANGUAGE,"")
String country_info_language;
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 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"));
}
}
......@@ -293,6 +293,13 @@ packages:
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.9.6+3"
mmkv_flutter:
dependency: "direct dev"
description:
name: mmkv_flutter
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.0.10"
package_config:
dependency: transitive
description:
......@@ -363,6 +370,13 @@ 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:
......
......@@ -31,12 +31,15 @@ dependencies:
json_serializable: ^3.0.0 #json to model
build_runner: ^1.6.1
pull_to_refresh: ^1.5.0
shared_preferences: ^0.4.3
# flutter_easyrefresh: ^1.2.7 # 上拉下拉刷新组件
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