# Flutter Integration

Integration Sample Code

We provide a DEMO project. Developers can obtain the integration sample code from Github (International) (opens new window) or Gitee (China) (opens new window).

Minimum Version

The minimum version required to integrate the FinClip Mini-Program SDK in Flutter is 2.2.3. Versions lower than this will not support Mini-Program functionality.

# 1. Obtain Credentials

Please Note

To integrate the SDK, you must first create an application and bind a Mini-Program in the FinClip platform. After obtaining the application-specific SDK KEY and SDK SECRET, you can then fill in the corresponding parameters during SDK integration. When opening a Mini-Program, the SDK will automatically initialize and verify whether the SDK KEY, SDK SECRET, and BundleID (Application ID) are correct.

You can 【Click Here】 to view how to obtain the required SDK KEY and SDK SECRET. Please ensure the parameters filled in during SDK integration are correct; otherwise, the Mini-Program will fail to open.

# 2. Integrate Plugin

# 2.1 Integration

Add the dependency in the project's pubspec.yaml file.

mop: latest.version

If your computer uses an M1 chip Mac, then you need to add the following 3 lines of code to the Podfile in the ios folder.

config.build_settings['ENABLE_BITCODE'] = 'NO'
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '9.0'
config.build_settings['EXCLUDED_ARCHS[sdk=iphonesimulator*]'] = 'arm64 i386'

Example:

post_install do |installer|
  installer.pods_project.targets.each do |target|
    flutter_additional_ios_build_settings(target)
    target.build_configurations.each do |config|
      config.build_settings['ENABLE_BITCODE'] = 'NO'
      config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '9.0'
      config.build_settings['EXCLUDED_ARCHS[sdk=iphonesimulator*]'] = 'arm64 i386'
    end
  end
end

# 2.2 Example

import 'package:flutter/material.dart';
import 'dart:async';
import 'dart:io';
import 'package:mop/mop.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  void initState() {
    super.initState();
    init();
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> init() async {
    if (Platform.isIOS) {
      //com.finogeeks.mopExample
      final res = await Mop.instance.initialize(
          '22LyZEib0gLTQdU3MUauARlLry7JL/2fRpscC9kpGZQA', // SDK Key
          '1c11d7252c53e0b6', // SDK Secret
          apiServer: 'https://api.finclip.com', // Server Address
           apiPrefix: '/api/v1/mop' // Server API Request Route Prefix
           );
      print(res);
    } else if (Platform.isAndroid) {
      //com.finogeeks.mopexample
      final res = await Mop.instance.initialize(
          '22LyZEib0gLTQdU3MUauARjmmp6QmYgjGb3uHueys1oA', // SDK Key
          '98c49f97a031b555',process // SDK Secret
          apiServer: 'https://api.finclip.com', // Server Address
           apiPrefix: '/api/v1/mop' // Server API Request Route Prefix
           );
      print(res);
    }
    if (!mounted) return;
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text(' FinClip Mini-Program Flutter Plugin'),
        ),
        body: Center(
          child: Container(
            padding: EdgeInsets.only(
              top: 20,
            ),
            child: Column(
              children: <Widget>[
                Container(
                  decoration: BoxDecoration(
                    borderRadius: BorderRadius.all(Radius.circular(5)),
                    gradient: LinearGradient(
                      colors: const [Color(0xFF12767e), Color(0xFF0dabb8)],
                      stops: const [0.0, 1.0],
                      begin: Alignment.topCenter,
                      end: Alignment.bottomCenter,
                    ),
                  ),
                  child: FlatButton(
                    onPressed: () {
                      Mop.instance.openApplet('5e3c147a188211000141e9b1'); // Mini-Program AppID
                    },
                    child: Text(
                      'Open Sample Mini-Program',
                      style: TextStyle(color: Colors.white),
                    ),
                  ),
                ),
                SizedBox(height: 30),
                Container(
                  decoration: BoxDecoration(
                    borderRadius: BorderRadius.all(Radius.circular(5)),
                    gradient: LinearGradient(
                      colors: const [Color(0xFF12767e), Color(0xFF0dabb8)],
                      stops: const [0.0, 1.0],
                     begin: Alignment.topCenter,
                      end: Alignment.bottomCenter,
                    ),
                  ),
                  child: FlatButton(
                    onPressed: () {
                      Mop.instance.openApplet('5e4d123647edd60001055df1', sequence: 1); // Mini-Program AppID
                    },
                    child: Text(
                      'Open Official Mini-Program',
                      style: TextStyle(color: Colors.white),
                    ),
                  ),
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }
}
© FinClip with ❤ , Since 2017