FinClip为企业提供小程序生态圈技术产品,开发者可在FinClip小程序开发帮助中心找到相关FinClip小程序指引

# Flutter 常见问题

# 1. 小程序右上角的更多按钮里的菜单支持自定义吗?如果支持,要怎么实现?

答:支持。 不过,iOS和android里的实现不太一样,需要分别处理。

iOS

首先,创建一个flutter向原生工程通信的channel。

const toAppMessageChannel = MethodChannel("com.message.flutter_to_app");

然后,创建一个继承自AppletHandler的实现类。

class MyAppletHandler extends AppletHandler {

...

 
bool customCapsuleMoreButtonClick(String appId) {
    // 返回true,代表要自定义更多视图;返回false,代表使用默认的更多视图
    // 注意该代理方法仅针对iOS端生效,安卓端见常见问题列表。
    
    // 这里通过channel发送事件给iOS工程的原生代码。
    toAppMessageChannel.invokeMethod("showCustomMoreView", {"appId": appId});
    return true;
}

...

}

然后,注册代理实现对象。

Mop.instance.registerAppletHandler(MyAppletHandler());

最后,在iOS原生工程里监听channel里的事件,处理弹出自定义更多视图的逻辑。

_channel = [FlutterMethodChannel methodChannelWithName:@"com.message.flutter_to_app" binaryMessenger:messenger];
    
[_channel setMethodCallHandler:^(FlutterMethodCall * _Nonnull call, FlutterResult  _Nonnull result) {
    NSLog(@"收到Flutter消息:%@", call.method);
    if ([call.method isEqualToString:@"showCustomMoreView"]) {
        NSString *appId = call.arguments[@"appId"];
        // 弹出自定义的更多视图
        UIViewController *viewController = [[UIApplication sharedApplication] fat_topViewController];
        
        UIAlertController *alertViewController = [UIAlertController alertControllerWithTitle:@"更多视图" message:appId preferredStyle:UIAlertControllerStyleActionSheet];
        [alertViewController addAction:[UIAlertAction actionWithTitle:@"转发" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            
        }]];
        [alertViewController addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
            
        }]];
        [viewController presentViewController:alertViewController animated:YES completion:nil];
    }
}];

android

  • 首先,在安卓工程里新建一个application。
  • 然后,AndroidManifest.xml里配置application的name。
  • 再然后,在application的onCreate方法里注册实现代理的对象。
  • 最后,重写更多按钮点击事件的方法即可。
public class MainApplication extends Application {

    @Override
    public void onCreate() {
        super.onCreate();

        initProcessHandler();
    }

    private void initProcessHandler() {
        if (!FinAppClient.INSTANCE.isFinAppProcess(this)) {
            return;
        }

        FinAppProcessClient.INSTANCE.getAppletProcessApiManager().setAppletProcessHandler(new IAppletProcessHandler(){
            @Override
            public boolean onNavigationBarMoreButtonClicked(@NonNull Context context, @NonNull String appId) {
                // 在这里弹出自定义的更多视图
                new AlertDialog.Builder(context)
                        .setTitle("更多视图")
                        .setMessage(appId)
                        .setPositiveButton("菜单", null)
                        .setNegativeButton("取消", null)
                        .show();

                // 返回true表示要自行处理更多视图;返回false表示使用默认的更多视图
                return true;
            }
        });
    }
}

# 2.公共UI如何支持英文?

需要在初始化SDK时,配置Config对象里的language参数为LanguageType.English

//多服务器配置
FinStoreConfig storeConfigA = FinStoreConfig(
  "SDK key",
  "SDK secret",
  "服务器地址",
  cryptType: "SM",
);
List<FinStoreConfig> storeConfigs = [storeConfigA];
Config config = Config(storeConfigs);
config.language = LanguageType.English;

# 3.如果自定义小程序的loading页面?

首先,需要分别在iOS和安卓工程创建一个自定义的的loading视图,分别需要继承或实现自FATBaseLoadingViewIFinAppletLoadingPage。 这里可以参考设置加载页UI

然后,在flutter-sdk初始化时配置各自的自定义loading视图的class。

注意

两端设置自定义的loading视图的配置项不一样!!

// iOS
...
Config config = Config(storeConfigs);
config.baseLoadingViewClass = "LoadingView";
...

// android
...
UIConfig uiconfig = UIConfig();
uiconfig.loadingLayoutCls = "com.finogeeks.mop_example.CustomLoadingPage";

© 2022 FinClip with ❤

👋🏻 嘿,你好!

「FinClip」是一套基于云原生框架设计的小程序容器。能够让任何移动应用在集成小程序SDK之后,获得可用、安全的小程序运行能力。

>> 点我免费注册体验

查看产品文档
了解与 FinClip 相关的一切信息

产品博客 👈  了解产品更新与核心功能介绍
资源下载 👈  获取小程序 SDK 与开发工具
文档中心 👈  查询 FinClip 小程序开发指南与答疑

商务咨询热线
预约 FinClip 产品介绍,咨询商务报价或私有化部署事宜

0755-86967467

获取产品帮助
联系 FinClip 技术顾问,获取产品资料或加入开发者社群

联系线上
人工客服

或 👉  点击这里,提交咨询工单