flutter-examples/hello_world/README.md
A minimal Flutter example that displays sherpa-onnx version information.
cd flutter-examples
flutter create --project-name hello_world --org com.k2fsa hello_world
Edit pubspec.yaml, replace the dependencies: section with:
dependencies:
flutter:
sdk: flutter
sherpa_onnx: ^1.13.4
Then run:
cd hello_world
flutter pub get
Replace the contents of lib/main.dart with:
import 'package:flutter/material.dart';
import 'package:sherpa_onnx/sherpa_onnx.dart';
void main() {
WidgetsFlutterBinding.ensureInitialized();
initBindings();
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'sherpa-onnx hello world',
home: const VersionPage(),
);
}
}
class VersionPage extends StatelessWidget {
const VersionPage({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('sherpa-onnx hello world')),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text('sherpa-onnx version: ${getVersion()}'),
Text('Git SHA1: ${getGitSha1()}'),
Text('Git date: ${getGitDate()}'),
Text('onnxruntime version: ${getOnnxruntimeVersion()}'),
],
),
),
);
}
}
flutter run
The app will display the sherpa-onnx version, git SHA1, git date, and onnxruntime version.
# macOS
flutter build macos
# iOS (no codesign for CI)
flutter build ios --no-codesign
# Android
flutter build apk
# Linux
flutter build linux
# Windows
flutter build windows
cd flutter-examples/hello_world
flutter pub get
flutter run -d chrome
flutter build web
The output is in build/web/. Serve it with any HTTP server:
cd build/web
python3 -m http.server 8080
Then start your browser and visit http://localhost:8080 .
xcrun simctl list devices
Look for a booted simulator, e.g.:
iPhone 16 Plus (UUID) (Booted)
flutter run -d <UUID>
For example:
flutter run -d 34FB0674-4ABA-4870-ABF2-D0D6E110A7C2
If you see ld: framework 'sherpa_onnx' not found, it means the Xcode
project has stale Swift Package Manager (SPM) references. Remove them:
cd ios
# Remove SPM references from the Xcode project
# (edit Runner.xcodeproj/project.pbxproj to remove FlutterGeneratedPluginSwiftPackage entries)
Or regenerate the iOS project:
flutter clean
flutter pub get
flutter run -d <UUID>