Flutter end-to-end demonstration
The purpose of this demonstration is to explain an end-to-end flow:
- A sample application that is pre-bundled with the PMF client SDK is registered and downloaded from the PMF Operations Console.
- A new or provided adapter is deployed to the PMF Operations Console.
- The application logic is changed to make a resource request.
End result
- Successfully ping the PMF.
- Successfully retrieve data using an adapter.
Prerequisites
- Xcode for iOS. For more information on the supported version, see Software Development Kits in the System requirements.
- Android Studio for Android. For more information on the supported version, see Software Development Kits in the System requirements.
- Flutter CLI
- Optional. PMF CLI (download)
- Optional. Stand-alone PMF (download)
Start PMF
Make sure you have created a Persistent Mobile Foundation instance, or if you are using the PMF Developer Kit, navigate to the server’s folder and run the command: ./run.sh
in Mac and Linux or run.cmd
in Windows.
Create and register an application
Open the PMF Operations Console by loading the URL: http://your-server-host:server-port/mfpconsole
in the browser. If the server is running locally, use http://localhost:9080/mfpconsole
. The username/password is admin/admin.
-
Click New next to Applications.
a. Select a platform: Android, iOS.
b. Enter com.persistent.mobilefoundation.pmf_example as the application identifier.
c. Enter 1.0.0 as the version.
d. Click Register application.
-
Download the Flutter sample application from GitHub.
Edit application logic
-
Open the Flutter project in your code editor of choice.
-
Select the
home_page.dart
file, which is located underlib
folder and paste the following code snippet insidegetPackageInfo()
:MFAuthorizationManager authManager = MFAuthorizationManager(); authManager .obtainAccessToken() .then((accessToken) { MFResourceRequest request = MFResourceRequest( "/adapters/javaAdapter/resource/greet/", MFResourceRequest.GET, ); request.setQueryParameters( paramName: "name", paramValue: "world"); request .send() .then((response) { debugPrint(“$response”); }) .catchError((error) { debugPrint(“$error”); }); }) .catchError((error) { debugPrint( "Error in obtain access token" ); });
Deploy an adapter
-
Download the adapter artifact and deploy it from the PMF Operations Console using the Actions → Deploy adapter action.
OR
-
Click New next to Adapters.
-
Select the Actions → Download sample option. Download the Hello World Java adapter sample.
Note: If Maven and PMF CLI are not installed, follow the on-screen Set up your development environment instructions.
-
From a Command-line window, navigate to the adapter’s Maven project root folder and run the command:
pmfdev adapter build
-
When the build finishes, deploy it from the PMF Operations Console using the Actions → Deploy adapter action. The adapter can be found in the
[adapter]/target
folder.
Test the application
-
Make sure that you have installed the PMF CLI, then navigate to the particular platform’s (iOS or Android)
root
folder and run the following command.pmfdev app register
If a remote PMF is used, first run the following command to add the server.
pmfdev server add
For more information, see Add a new server instance.
Then run the following command register the app.
pmfdev app register <myIBMCloudServer>
-
Run the following command, to run the application:
flutter run
If a device is connected, the application will be installed and launched in the device. Otherwise, the simulator or emulator will be used.
Results
- Clicking the Ping PMF button displays Connected to PMF.
- If the application was able to connect to the PMF, a resource request call using the deployed Java adapter takes place. The adapter response is then displayed in an alert.
Further reading
Learn more on using adapters in applications, and how to integrate additional services such as Push Notifications, using the PMF security framework and more:
- Review the Application development tutorials.
- Review the Adapters development tutorials.
- Review the Authentication and security tutorials.
- Review the Notifications tutorials.