Initialization

Here is how to initialize the Wepin widget flutter SDK.

Initialize

First, create an instance of the Wepin widget. Then, use the BuildContext of the app widget, the App ID and App Key assigned after app registration to initialize the instance.

import 'package:wepin_flutter/wepin.dart';
import 'package:wepin_flutter/wepin_delegate.dart';
import 'package:wepin_flutter/wepin_inputs.dart';
import 'package:wepin_flutter/wepin_outputs.dart';

final String _appId = "app_id_eg12sf3491azgs520";
final String _appKey = "ak_test_ghq1D5s1sfG234sbnhdsw24mnovk313";
late Wepin _wepin;

@override
void initState() {
  super.initState();
  _wepin = Wepin();
	_handleDeepLink() // Deep Link Handling Function
}

@override
Widget build(BuildContext context) {
  print('SampleApp_build');
  return MaterialApp(
    home: Scaffold(
      appBar: AppBar(
        title: const Text('Wepin Flutter Example'),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            ElevatedButton(
                onPressed: () => _initialize(context),
                child: const Text('initialize')),
					],
        ),
      ),
    ),
  );
}


void _initialize(BuildContext context) {
    WidgetAttributes widgetAttributes = WidgetAttributes('ko', 'krw');
    WepinOptions wepinOptions =
        WepinOptions(_appId, _appSdkKey, widgetAttributes);
    _wepin.initialize(context, wepinOptions);
  }

WepinOptions

The interface of the WepinOptions class, which is used as a parameter for initialization, is as follows.

public class WepinOptions {
	final String _appId; // App ID
  final String _appKey; // App Key
  final WidgetAttributes _widgetAttributes; // Widget Attributes
}

public class WidgetAttributes {
final String _defaultLanguage;
  final String _defaultCurrency;
}
  • appId: String App ID assigned during registration

  • appKey: String App Key assigned during registration

  • attributes: Object (optional)

    Properties of the Wepin Widget

    • defaultLanguage: String The language to be displayed on the widget. The default value is ko. The currently supported languages are en and ko.

    • defaultCurrency: String The currency to be displayed on the widget. The default value is KRW. The currently supported currencies are USD and KRW.

isInitialized

You can use the isInitialized method to check if the Wepin instance has been initialized successfully.

The returned value is as follows.

  • boolean init result; true if Wepin SDK is already initialized, otherwise false.

if(_wepin.isInitialized()) {
    // Success to initialize wepin
}

To handle the URL schemes added to the app's Info file or AndroidManifest for use with Wepin, add the following code to the app using Wepin.

import 'package:uni_links/uni_links.dart';

StreamSubscription? _sub;

// Handle incoming links - the ones that the app will recieve from the OS
// while already started.

  void _handleDeepLink() {
    if (!kIsWeb) {
      // It will handle app links while the app is already started - be it in
      // the foreground or in the background.
      _sub = uriLinkStream.listen((Uri? uri) {
        if (!mounted) return;
        print('got_uri: $uri');
        _wepin.handleWepinLink(uri!);
      }, onError: (Object err) {
        if (!mounted) return;
        print('got_err: $err');
      });
    }
  }

Last updated