- Journey is an online travel application
- The purpose of building this application is to learn how to use Flutter framework. For simplicity, I have choose to clone one of the famous OTA in China - ctrip.com. Converting their mobile h5 UI to Flutter UI
- First, follow this tutorial to setup Flutter
- Setup your iOS emulator and open it
- Setup your Android emulator open it
- Check your available device emulators using
flutter emulators
- To run an emulator, run
flutter emulators --launch <your_emulator_id>
- Clone journey
- Follow the notes on how to setup search function with voice recognition for specific platform at here.
Note for iOS, underjourney/ios/plugin/ASRPlugin
, createBDSClientLib
directory, then putlibBaiduSpeechSDK.a
file you downloaded from Baidu iOS Native SDK'sios_sdk/BDSClientLib
into it - After finish setup,
cd
to thejourney
project - In Terminal, run
flutter packages get
- Start your app by running
flutter run -d <deviceId>
orflutter run -d all
to run with all devices you launched.
- Designed for iOS & Android UI
- Home Page (首页)
- Search Page (搜索)
- Travel Page (旅拍)
- My Page (我的)
- Caching images locally
- Used staggered grid layout for travel page
- Getting data/assets from GET / POST request from ctrip h5 mobile server
- Lazy loading for more travel pages when user slide up
- Handle refresh when user slide down
- Clicking on specific icon/image/post can link back to h5 mobile side and displayed as in Flutter UI using WebView
- Implemented Baidu's voice recognition for search
- Implement Baidu's voice recognition for both iOS & Android by integrating native and flutter code using Message Channel
- User can manually search using keyword
-
Setup Android Native SDK
- Download Baidu's Android 离在线融合 SDK
- Read Baidu's Speech Recognition Documentation for setup details
- Download the sdk, and unzip it.
- Open your android folder under Android Editor mode, create new module and package name
- Copy the
sdk/core/libs/bdasr_V3_xxxx_xxx.jar
to your Flutter android'sandroid/<your-plugin>/libs/bdasr_V3_xxxx_xxx.jar
- Copy the directory from
sdk/core/src/main/jniLibs
to your Flutter androids'sandroid/src/main/<jniLibs>
- Add
-keep class com.baidu.speech.**{*;}
to your Flutter android'sproguard-rules.pro
file - Copy
AndroidMainfest.xml
settings from Baidu's Speech Recognition Documentation to your android'sAndroidMainfest.xml
- In Baidu's Cloud Baidu's Speech Recogniztion, create an application and follow the on screen instruction.
- After create the application, you can setup your APP_ID, APP_KEY, APP_SECRET in your
AndroidMainfest.xml
. Find the instruction in Baidu's Speech Recognition Documentation for details.
- After create the application, you can setup your APP_ID, APP_KEY, APP_SECRET in your
- To setup speech recognition service, copy paste
to your
<service android:name="com.baidu.speech.VoiceRecognitionService" android:exported="false" />
AndroidMainfest.xml
within your<application></application>
- Configure dependencies between your
app
andyour_speech_plugin
inbuild.gradle
(Module: app) - Under
android/asr_plugin/java/<your-package-name>
, implement your plugin function - Setup
ndk
framework that flutter supports inapp
'sbuild_gradle
- Setup your dependencies between Android's & Flutter by configure
asr_plugin
'sbuild.gradle
accordingly. - Remember to configure your
app
'sbuild_gradle
to resolve dependencies conflicts betweenapp
&asr_plugin
&libflutter.so
.app
depend onlibflutter.so
&asr_plugin
asr_plugin
depend onlibflutter.so
-
Setup iOS Native SDK
- Download Baidu's iOS 离在线融合 SDK
- Read Baidu's Speech Recognition Documentation for setup details
- Download the sdk, and unzip it.
- Open your xcode workspace under
<your-project>/ios/Runnerxcworkspace
- Create a new group such as
plugin
underRunner
- Copy the
sdk/BSDClientLib
to your Flutter iOS'splugin/ASRPlugin
group directory you just created.withcreate groups
mode. - Add the
sdk/BDSClientResource/ASR/BDSClientResources
directory to your Flutter's iOSplugin/ASRPlugin
group directory with thecreate folder references
mode. - Add the
sdk/BDSClientResource/ASR/BDSClientEASRResources
directory to your Flutter's iOSplugin/ASRPlugin
group directory with thecreate groups
mode. - Rename your
- Setup / linked necessary frameworks and libraries in iOS's workspace
Runner -> General
tab- Add
libz.1.2.5.tbd
framework - Add
libc++.tbd
framework - Add
CoreTelephony
framework - Add
libsqlite3.0.tbd
framework - Add
libiconv.2.4.0.tbd
framework - Add
libBaiduSpeechSDK.a
found in downloadedsdk/BDSClientLib
- Adjust your
Library Search Paths
inBuild Settings
tab if library not found
- Add
- Setup microphone permission usage
- Under
Runner/Info.plist
, add key =Privacy - Microphone Usage Description
, value =<any description you like>
- Under
- Under your
Runner/plugin/ASRPlugin
, create files & implement your function. Ex:AsrManager.h
,AsrManager.m
,AsrPlugin.h
&AsrPlugin.m
to integrate with Flutter's client through MessageChannel - Register your
AsrPlugin.h
inRunner/App.delegate.m
-
Setup plugin & communication channel in Flutter
- Create a
plugin
directory under your Flutter'slib
directory. - Implement
asr_manager.dart
to invokeMethodChannel
and functions so that we can communicate with native Android & iOS
- Create a
- Android
- Preparing an Android app for release
- If there is a
Gradle task assembleRelease failed with exit code 1
issues, in terminal typeflutter clean
and rebuild your apkflutter build apk
.
- iOS