Alan Flutter Framework¶
Available on: Android iOS
The Alan Flutter plugin helps you to integrate your voice experience and Alan Studio script into your Flutter app.
Note
The alan_voice
package version 3.0.0 supports null safety. If your app does not use null safety yet, upgrade the Dart version to 2.12 or higher or use a previous version of the alan_voice
package.
Integrating with Alan¶
To integrate a Flutter app with Alan:
In the
pubspec.yaml
file of your Flutter project, add the Alan voice dependency:pubspec.yaml¶... dependencies: flutter: sdk: flutter ... alan_voice: 2.4.0
Open the
main.dart
file and at the top of it, add thealan_voice
package dependency:main.dart¶import 'package:alan_voice/alan_voice.dart';
In the
_MyHomePageState
class, add the method for initializing the Alan button:main.dart¶... class _MyHomePageState extends State<MyHomePage> { ... _MyHomePageState() { /// Initializing Alan with sample project id AlanVoice.addButton( "", buttonAlign: AlanVoice.BUTTON_ALIGN_LEFT); } ...
In Alan Studio, go to Integrations, copy the value from the Alan SDK Key field and insert this value in the quotes.
main.dart¶... class _MyHomePageState extends State<MyHomePage> { ... _MyHomePageState() { /// Initializing Alan with sample project id AlanVoice.addButton( "314203787ccd9370974f1bf6b6929c1b2e956eca572e1d8b807a3e2338fdd0dc/prod", buttonAlign: AlanVoice.BUTTON_ALIGN_LEFT); } ...
That’s it. Now you can run the app, tap the Alan button and start interacting with Alan.
Specifying the Alan button parameters¶
You can specify the following parameters for the Alan button added to your app:
Name |
Type |
Description |
---|---|---|
|
string |
The Alan SDK key for a project in Alan Studio. |
|
JSON object |
The authentication or configuration data to be sent to the voice script. For details, see authData. |
|
Int |
The Alan button position in the app. Use one of the two constants: |
Using the Alan button methods¶
For details on methods exposed by the Alan Flutter SDK, see Client API methods.
Handling events¶
When you run an app with Alan voice, multiple events come from the Alan backend. You can handle the following events:
onCommand: this callback is invoked when the app receives a command from the voice script. For details, see onCommand handler.
onButtonState: this callback is invoked when the Alan button state changes. For details, see onButtonState handler.
onEvent: this callback is invoked on Alan events. For details, see onEvent handler.
Switching between logging levels¶
By default, Alan does not log its system events such as change of the Alan button state to the IDE console. If you want to see messages from Alan, switch to the all
logging level:
AlanVoice.setLogLevel("all");
To disable logs, either remove the line above or switch to the none
logging level:
AlanVoice.setLogLevel("none");
Troubleshooting¶
To troubleshoot problems you may have with your Flutter app, check the solutions below:
The minimum possible Android SDK version required by the Alan SDK is 21. If the version in your project is lower, you may encounter the following error:
AndroidManifest.xml Error: uses-sdk:minSdkVersion 16 cannot be smaller than version 21 declared in library [:alan_voice]
. Open the./android/app/build.gradle
file, underdefaultConfig
, locateminSdkVersion
and change the version to 21.Starting from version 3.0.0, the
alan_voice
package supports null safety. If you encounter the following error:Cannot run with sound null safety because dependencies don't support null safety
, upgrade to the latest package version.
Trying Alan sample apps¶
In our GitHub repository, you can find sample Flutter apps already integrated with Alan. Download these apps to get an idea of how you can voice-enable your app and trigger activities in the app with voice commands.
Alan simple app: an example demonstrating how to integrate Alan with a Flutter app
Flutter Shrine app: a shopping app with a voice interface synchronized with the app visual elements
What’s next?¶
You can now proceed to building a voice interface with Alan. Use the following resources:
Read tutorials on Flutter:
Go to Script concepts to learn about Alan concepts and functionality you can use to create a voice script.