# Initialization

Here is how to initialize the Wepin widget flutter SDK.

## Initialize&#x20;

First, create an instance of the Wepin widget. Then, use the <mark style="color:blue;">`BuildContext`</mark> of the app widget, the App ID and App Key assigned after app registration to initialize the instance.

```dart
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 <mark style="color:blue;">`WepinOptions`</mark> class, which is used as a parameter for initialization, is as follows.

```dart
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 <mark style="color:blue;">`ko`</mark>. The currently supported languages are <mark style="color:blue;">`en`</mark> and <mark style="color:blue;">`ko`</mark>.
  * **`defaultCurrency`:** *String*\
    The currency to be displayed on the widget. The default value is <mark style="color:blue;">`KRW`</mark>. The currently supported currencies are <mark style="color:blue;">`USD`</mark> and <mark style="color:blue;">`KRW`</mark>.<br>

## `isInitialized`

You can use the <mark style="color:blue;">`isInitialized`</mark> method to check if the Wepin instance has been initialized successfully.

The returned value is as follows.

* *boolean*\
  init result; <mark style="color:orange;">`true`</mark> if Wepin SDK is already initialized, otherwise <mark style="color:orange;">`false`</mark>.

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

## Handle DeepLink / Universal Link

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.

```dart
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');
      });
    }
  }
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.wepin.io/en/deprecated/flutter-sdk/init.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
