realwear_dictation 0.1.0 copy "realwear_dictation: ^0.1.0" to clipboard
realwear_dictation: ^0.1.0 copied to clipboard

unlistedoutdated

RealWear Dictation Plugin.

example/lib/main.dart

import 'dart:async';

import 'package:event_bus/event_bus.dart';
import 'package:flutter/material.dart';
import 'package:logger/logger.dart';
import 'package:realwear_dictation/enums/dictation_input_type.dart';
import 'package:realwear_dictation/events/dictation_result_event.dart';
import 'package:realwear_dictation/realwear_dictation.dart';

final logger = Logger();
final eventBus = EventBus();
final realwearDictation = RealwearDictation(logger, eventBus);

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  StreamSubscription? _dictationResultEventListener;

  @override
  void initState() {
    super.initState();
    _dictationResultEventListener = eventBus.on<DictationResultEvent>().listen((event) {
      final snackBar = SnackBar(
        content: Text(event.result ?? 'null'),
      );
      ScaffoldMessenger.of(context).showSnackBar(snackBar);
    });
  }

  @override
  void dispose() {
    _dictationResultEventListener?.cancel();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('RealwearDictation Plugin Example App'),
        ),
        body: Center(
          child: Column(
            children: [
              TextButton(
                onPressed: () => realwearDictation.openDictation(inputType: DictationInputType.text),
                child: const Text('Open Dictation - Text'),
              ),
              const SizedBox(
                width: double.infinity,
                height: 16,
              ),
              TextButton(
                onPressed: () => realwearDictation.openDictation(inputType: DictationInputType.numeric),
                child: const Text('Open Dictation - Numeric'),
              ),
            ],
          ),
        ),
      ),
    );
  }
}