Browse Source

UI

null_safety
fmk 3 years ago
parent
commit
4ef178ff6e
  1. 14
      android/app/src/main/kotlin/com/zsw/huixiang/MainActivity.kt
  2. 17
      ios/Runner/AppDelegate.mm
  3. 84
      lib/base_state.dart
  4. 26
      lib/main_page.dart
  5. 111
      lib/union/store_details_page.dart
  6. 13
      lib/view_widget/custom_image.dart
  7. 8
      lib/view_widget/like_widget.dart

14
android/app/src/main/kotlin/com/zsw/huixiang/MainActivity.kt

@ -10,20 +10,28 @@ import io.flutter.embedding.android.FlutterActivity
class MainActivity: FlutterActivity() {
lateinit var bridgePlugin : BridgePlugin
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Log.e("intentUrl:", "url: ${intent.data}" )
flutterEngine?.plugins?.add(MinPlugin())
flutterEngine?.plugins?.add(BridgePlugin().apply {
intentAction = intent.data
})
bridgePlugin = BridgePlugin()
if (intent.data != null) {
bridgePlugin.intentAction = intent.data
}
flutterEngine?.plugins?.add(bridgePlugin)
}
override fun onNewIntent(intent: Intent) {
super.onNewIntent(intent)
Log.e("intentUrl:", "onNewIntent: ${intent.data}" )
if (bridgePlugin != null && intent.data != null) {
bridgePlugin.intentAction = intent.data
}
}
override fun onDestroy() {

17
ios/Runner/AppDelegate.mm

@ -92,6 +92,23 @@
}
- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray<id<UIUserActivityRestoring>> * _Nullable))restorationHandler {
NSLog(@"%@", userActivity.webpageURL);
NSLog(@"%@", [userActivity.webpageURL.query componentsSeparatedByString:@"="][0]);
NSLog(@"%@", [userActivity.webpageURL.query componentsSeparatedByString:@"="][1]);
__block NSString *custom = [userActivity.webpageURL.query componentsSeparatedByString:@"="][1];
FlutterViewController* controller = (FlutterViewController*)self.window.rootViewController;
FlutterMethodChannel* bridgeAppChannel = [FlutterMethodChannel methodChannelWithName:@"bridge" binaryMessenger:(NSObject<FlutterBinaryMessenger> *)controller];
[bridgeAppChannel setMethodCallHandler:^(FlutterMethodCall * _Nonnull call, FlutterResult _Nonnull result) {
NSString * method = call.method;
if ([method isEqual:@"action"]) {
if (custom != NULL) {
result(custom);
custom = @"";
}
result(@"");
}
//result(FlutterMethodNotImplemented);
}];
// 通过通用链接唤起 App
[DCUniMPSDKEngine application:application continueUserActivity:userActivity];
return YES;

84
lib/base_state.dart

@ -0,0 +1,84 @@
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:huixiang/utils/bridge.dart';
import 'package:shared_preferences/shared_preferences.dart';
abstract class BaseState<T extends StatefulWidget> extends State<T> with WidgetsBindingObserver {
@override
void dispose() {
super.dispose();
WidgetsBinding.instance.removeObserver(this);
}
@override
void didChangeAppLifecycleState(AppLifecycleState state) {
print("-didChangeAppLifecycleState-" + state.toString());
switch (state) {
case AppLifecycleState.inactive: //
break;
case AppLifecycleState.resumed: //
pushRoute();
break;
case AppLifecycleState.paused: //
break;
case AppLifecycleState.detached: // APP结束时调用
break;
}
}
@override
void initState() {
super.initState();
WidgetsBinding.instance.addObserver(this);
}
pushRoute() async {
String startIntent = await Bridge.getStartIntent();
SharedPreferences sharedPreferences = await SharedPreferences.getInstance();
print("intent:$startIntent");
String pushData = "";
if (startIntent != null && startIntent != "") {
pushData = startIntent;
} else {
pushData = sharedPreferences.getString("pushData");
}
if (pushData == null || pushData == "") return;
Map<String, dynamic> pushMap = jsonDecode(pushData);
if (pushMap != null) {
String routeName = "";
Map<String, dynamic> params = {};
switch (pushMap["typed"]) {
case 1:
routeName = "/router/store_detail_page";
params["articleId"] = pushMap["info"];
break;
case 2:
routeName = "/router/store_detail_page";
params["activityId"] = pushMap["info"];
break;
case 3:
routeName = "/router/union_detail_page";
params["id"] = pushMap["info"];
break;
case 4:
routeName = "/router/integral_store_page";
params["goodsId"] = pushMap["info"];
break;
case 5:
routeName = "/router/order_details";
params["id"] = pushMap["info"];
break;
}
sharedPreferences.setString("pushData", "");
print("xgPushClickAction: routeName: $routeName");
if (routeName != "") {
Navigator.of(context).pushNamed(routeName, arguments: params);
}
}
}
}

26
lib/main_page.dart

@ -24,15 +24,38 @@ class MainPage extends StatefulWidget {
}
}
class _MainPage extends State<MainPage> {
class _MainPage extends State<MainPage> with WidgetsBindingObserver {
List<Widget> _widgetOptions;
List<String> icons;
List<String> iconn;
@override
void dispose() {
super.dispose();
WidgetsBinding.instance.removeObserver(this);
}
@override
void didChangeAppLifecycleState(AppLifecycleState state) {
print("-didChangeAppLifecycleState-" + state.toString());
switch (state) {
case AppLifecycleState.inactive: //
break;
case AppLifecycleState.resumed: //
pushRoute();
break;
case AppLifecycleState.paused: //
break;
case AppLifecycleState.detached: // APP结束时调用
break;
}
}
@override
void initState() {
super.initState();
WidgetsBinding.instance.addObserver(this);
pushRoute();
@ -108,7 +131,6 @@ class _MainPage extends State<MainPage> {
}
pushRoute() async {
String startIntent = await Bridge.getStartIntent();
SharedPreferences sharedPreferences = await SharedPreferences.getInstance();
print("intent:$startIntent");

111
lib/union/store_details_page.dart

@ -113,35 +113,36 @@ class _StoreDetailsPage extends State<StoreDetailsPage>
share() async {
SSDKMap params = SSDKMap()
..setGeneral(
activity != null
? activity.mainTitle
: article != null
? article.mainTitle
: "",
activity != null
? activity.viceTitle
: article != null
? article.viceTitle
: "",
[
activity != null
? activity.coverImg
: article != null
? article.coverImg
: "",
],
activity != null
? activity.mainTitle
: article != null
? article.mainTitle
: "",
activity != null
? activity.viceTitle
: article != null
? article.viceTitle
: "",
[
activity != null
? activity.coverImg
: article != null
? article.coverImg
: "",
"",
"http://hx.lotus-wallet.com/index.html?id=${widget.arguments["activityId"] ?? widget.arguments["articleId"]}",
"",
"",
"",
"",
SSDKContentTypes.webpage);
],
activity != null
? activity.coverImg
: article != null
? article.coverImg
: "",
"",
"https://hx.lotus-wallet.com/index.html?id=${widget.arguments["activityId"] ?? widget.arguments["articleId"]}",
"",
"",
"",
"",
SSDKContentTypes.webpage,
);
debugPrint(activity != null
? activity.coverImg
@ -560,24 +561,20 @@ class _StoreDetailsPage extends State<StoreDetailsPage>
),
),
),
// GestureDetector(
// onTap: () {
// if (isLiked) return;
// queryInformationLikes();
// },
// child: Image.asset(
// isLiked
// ? "assets/image/icon_like.png"
// : "assets/image/icon_like_h.png",
// fit: BoxFit.fill,
// width: 24,
// height: 24,
// ),
// )
LikeWidget(isLiked, () {
if (isLiked) return;
queryInformationLikes();
}),
GestureDetector(
onTap: () {
if (isLiked) return;
queryInformationLikes();
},
child: Image.asset(
isLiked
? "assets/image/icon_like.png"
: "assets/image/icon_like_h.png",
fit: BoxFit.fill,
width: 24,
height: 24,
),
)
],
),
);
@ -698,19 +695,23 @@ class _StoreDetailsPage extends State<StoreDetailsPage>
alignment: Alignment.topRight,
child: Row(
children: [
GestureDetector(
onTap: () {
if (memberList.liked ?? false) return;
queryCommentLike(memberList.id);
},
child: Image.asset(
!(memberList.liked ?? false)
? "assets/image/icon_like_h.png"
: "assets/image/icon_like.png",
width: 16,
height: 16,
),
),
// GestureDetector(
// onTap: () {
// if (memberList.liked ?? false) return;
// queryCommentLike(memberList.id);
// },
// child: Image.asset(
// !(memberList.liked ?? false)
// ? "assets/image/icon_like_h.png"
// : "assets/image/icon_like.png",
// width: 16,
// height: 16,
// ),
// ),
LikeWidget(isLiked, (isLike) {
if (memberList.liked ?? false) return;
queryCommentLike(memberList.id);
}),
Text(
memberList.likes.toString(),
style: TextStyle(

13
lib/view_widget/custom_image.dart

@ -13,7 +13,8 @@ class MImage extends StatelessWidget {
final BoxFit fit;
final bool isCircle;
MImage(this.src, {
MImage(
this.src, {
this.errorSrc = "assets/image/default_2_1.png",
this.fadeSrc = "assets/image/default_2_1.png",
this.aspectRatio,
@ -29,9 +30,8 @@ class MImage extends StatelessWidget {
Widget image = LayoutBuilder(builder: (context, constraints) {
String imageUrl = "";
if (src != null && src != "") {
imageUrl = "$src?imageMogr2/thumbnail/${constraints.constrainWidth() *
2}x${constraints.constrainHeight() *
2}/format/webp/blur/1x0/quality/75";
imageUrl = "$src?imageMogr2/thumbnail/${constraints.constrainWidth() * 2}"
"x${constraints.constrainHeight() * 2}/format/webp/blur/1x0/quality/75";
}
print("imageUrl: $imageUrl");
return CachedNetworkImage(
@ -62,10 +62,7 @@ class MImage extends StatelessWidget {
var clipRRect;
if (isCircle) {
clipRRect = ClipOval(
clipBehavior: Clip.antiAlias,
child: image
);
clipRRect = ClipOval(clipBehavior: Clip.antiAlias, child: image);
} else {
clipRRect = ClipRRect(
borderRadius: radius,

8
lib/view_widget/like_widget.dart

@ -3,7 +3,7 @@ import 'package:flutter/material.dart';
class LikeWidget extends StatefulWidget {
bool like;
final Function() click;
final Function(bool isLike) click;
LikeWidget(this.like, this.click);
@ -46,15 +46,18 @@ class _LikeWidget extends State<LikeWidget>
scale: _iconAnimation,
child: InkWell(
onTap: () {
widget.click();
_clickIcon();
},
child: widget.like
? Image.asset(
_likeIcon,
width: 16,
height: 16,
)
: Image.asset(
_unLikeIcon,
width: 16,
height: 16,
),
),
);
@ -68,6 +71,7 @@ class _LikeWidget extends State<LikeWidget>
setState(() {
widget.like = !widget.like;
});
widget.click(widget.like);
if (_iconAnimation.status == AnimationStatus.dismissed) {
_animationController.forward();
} else if (_iconAnimation.status == AnimationStatus.completed) {

Loading…
Cancel
Save