Skip to main content
Version: 4.6.1-saas

Flutter Agent

Overview

The NetFUNNEL Flutter agent is a dedicated client that communicates with the NetFUNNEL server.

Minimum Requirements

  • Flutter 3.0.0 or later
  • Dart 3.0.0 or later

Agent Operation Flow

Before Waiting

  • Before waiting, configuration is initialized. This involves fetching configuration from the NetFUNNEL server and initializing objects from that data.
  • Use the "initialization function" to initialize NetFUNNEL configuration.

While Waiting

  • This is the process of showing the virtual waiting room and applying traffic waiting on the screen (Screen) where you want it.
  • Use the "wait start function" to apply the virtual waiting room.

After Waiting

  • This is handling after waiting ends. Situations where an end-user's wait ends are:
    • Entry success after waiting
    • Entry failure due to server or network error during waiting
    • End-user cancels waiting during wait
  • Use the "callback function" and "wait stop function" to implement logic after waiting ends.

Agent Installation

The NetFUNNEL Flutter agent is provided as a tar.gz package. You must install it by adding the provided archive to your project directly; it is not published on a public repository (pub.dev).

Install Agent

Copy the tar.gz file to the project root or your desired location, then add the dependency to your Flutter project's pubspec.yaml to install the package.

warning

pubspec.yaml is interpreted as a hierarchy by indentation, so be careful with indentation.

pubspec.yaml

dependencies:
netfunnel_flutter:
path: ./netfunnel_flutter-{{latest}} # Path where you copied the tar.gz file

Terminal

flutter pub get

Network Permissions

On Android, add internet permission for communication with the NetFUNNEL server.

android/app/src/main/AndroidManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<!-- Internet permission -->
<uses-permission android:name="android.permission.INTERNET" />

</manifest>

Agent Initialization

The NetFUNNEL Flutter agent must be initialized when the app starts.

info

Perform initialization at the start of the main() function in main.dart.

import 'package:netfunnel_flutter/netfunnel_flutter.dart';

void main() async {
// NetFUNNEL agent initialization
await Netfunnel.instance.initialize(
clientId: '{{CLIENT_ID}}',
serverUrl: '{{SERVER_URL}}',
errorUrl: '{{ERROR_URL}}',
networkTimeout: 3000,
retryCount: 0,
printLog: false,
errorBypass: false,
useNetfunnelTemplate: true,
userId: '{{USER_ID}}',
useNetworkRecoveryMode: true,
profile: 'prod_tokyo',
);

runApp(MyApp());
}
ParameterTypeDescriptionRequiredCondition
clientIdStringUser unique identifierOCannot be empty string
serverUrlStringNetFUNNEL server addressXNone (default address used)
errorUrlStringNetFUNNEL error page HTML addressXNone (default address used)
networkTimeoutintMaximum time to wait for network responseXDefault: 3,000ms<br/>Max: 10,000ms<br/>Min: 100ms
retryCountintNumber of retries on network request failureXDefault: 0<br/>Max: 10<br/>Min: 0
printLogboolWhether to output logs for debuggingXDefault: false
errorBypassboolWhether to bypass on errorXDefault: false
useNetfunnelTemplateboolWhether to use the custom NetFUNNEL waiting room from the consoleXDefault: true
userIdStringEnd-user unique identifier for blacklist/whitelistXDefault: null
useNetworkRecoveryModeboolWhether to keep the waiting room and retry when the connection is lostXDefault: false
profileStringUser environment (prod_tokyo, prod_us_east)XDefault: prod_tokyo

Agent Application

You can apply the waiting room to specific screens using the functions provided by the NetFUNNEL Flutter agent.

info

Project key and segment key for the start and stop functions can be found in the Console project tab.

Callback Function

To use the NetFUNNEL Flutter agent, you must provide a callback to the start and stop functions.

The waiting room can end in various situations (wait success, cancel, block, error, network error, etc.). Implement handling for each case in the callback.

abstract class: NetfunnelCallback

CallbackRequired
onSuccessRequired
onErrorRequired
onNetworkErrorRequired
onBlockOptional
onCloseOptional
onContinueOptional
CallbackStatus codeScenario
onSuccess200Passed queue and service access allowed
onSuccess300Subscription/license expired; project/segment deactivated; agent errorBypass=true and error occurred
onSuccess303Request from IP or ID on console whitelist (admin bypass)
onError500Start called without init; invalid project/segment key; segment deleted; partial server response
onNetworkError1001Network connection blocked (Wi‑Fi, cellular)
onNetworkError1002Network timeout; invalid HTML URL; server down (502, etc.)
onBlock301Segment block (voluntary entry block)
onBlock302Request from IP or ID on blacklist (admin block); BotManager Basic enabled
onClose495Post-waiting room close button clicked
onClose496Pre-waiting room close button clicked
onClose497Macro block room close button clicked
onClose498Block room close button clicked
onClose499Default waiting room cancel button clicked
onContinue201Agent useNetfunnelTemplate=false and default wait
import 'package:netfunnel_flutter/netfunnel_flutter.dart';

class NetfunnelHandler extends NetfunnelCallback {
static const String _tag = "[APP]";

@override
void onSuccess(int statusCode, String message) {
print('$_tag onSuccess: $statusCode $message');
/// Logic when queue is passed (e.g. navigate to service screen)
}

@override
void onError(int statusCode, String message) {
print('$_tag onError: $statusCode $message');
/// Logic on error (e.g. show error or bypass)
}

@override
void onNetworkError(int statusCode, String message) {
print('$_tag onNetworkError: $statusCode $message');
/// Logic on network error (e.g. guide to reconnect or retry screen)
}

@override
void onBlock(int statusCode, String message) {
print('$_tag onBlock: $statusCode $message');
/// Logic when entry is blocked (e.g. show access denied)
}

@override
void onClose(int statusCode, String message) {
print('$_tag onClose: $statusCode $message');
/// Logic when user cancels wait (e.g. show exit message)
}

@override
void onContinue(int statusCode, String message, int aheadWait, int behindWait, String waitTime, int progressRate) {
print('$_tag onContinue: $statusCode $message');
/// UI update while waiting (only when using custom waiting room)
}
}

Basic Control

Start Function

To apply the waiting room on a specific screen (Widget or Page), use the "wait start function" to show the virtual waiting room. Basic control is useful to apply waiting when an end-user enters a specific screen, to manage server load and end-user experience.

await Netfunnel.instance.nfStart(
projectKey: '{{PROJECT_KEY}}',
segmentKey: '{{SEGMENT_KEY}}',
callback: callback,
context: context,
);
ParameterTypeDescriptionRequired
projectKeyStringNetFUNNEL console Basic Control project keyO
segmentKeyStringNetFUNNEL console Basic Control segment keyO
callbackFunctionUser-defined callback for waiting room eventsO
contextBuildContextBuildContext of the screen where the waiting room is appliedO

Stop Function

When basic control wait completes successfully, implement both of the following:

  • Code to enter the service after waiting (navigate to the target page)
  • Code that calls the "wait stop function" after business logic to return the entry key to the NetFUNNEL server
await Netfunnel.instance.nfStop(
projectKey: '{{PROJECT_KEY}}',
segmentKey: '{{SEGMENT_KEY}}',
);
ParameterTypeDescriptionRequired
projectKeyStringNetFUNNEL console Basic Control project keyO
segmentKeyStringNetFUNNEL console Basic Control segment keyO

Section Control

Section control applies a waiting state between entry and exit of a specific page. With section control, users can maintain a smooth flow in a specific section of the page.

  • After entering an event page, purchasing a product, and clicking the payment complete button
  • From end-user login until logout

To start section control, use the "section start function" to define the start of the control section. This keeps the waiting state in that section's flow.

await Netfunnel.instance.nfStartSection(
projectKey: '{{PROJECT_KEY}}',
segmentKey: '{{SEGMENT_KEY}}',
callback: callback,
context: context,
);
ParameterTypeDescriptionRequired
projectKeyStringNetFUNNEL console Section Control project keyO
segmentKeyStringNetFUNNEL console Section Control segment keyO
callbackFunctionUser-defined callback for waiting room eventsO
contextBuildContextBuildContext of the screen where the waiting room is appliedO

Stop Function

When section control wait completes successfully, you can implement:

  • Code to enter the service after waiting (navigate to the target page)

To end section control, use the "section stop function" to define the end of the section. This ends the end-user's section control and allows the next end-user to enter.

await Netfunnel.instance.nfStopSection(
projectKey: '{{PROJECT_KEY}}',
segmentKey: '{{SEGMENT_KEY}}',
);
ParameterTypeDescriptionRequired
projectKeyStringNetFUNNEL console Section Control project keyO
segmentKeyStringNetFUNNEL console Section Control segment keyO