main.dart 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import 'package:flutter/material.dart';
  2. import 'dart:async';
  3. import 'package:flutter/services.dart';
  4. import 'package:dubbing_lib/dubbing_lib.dart';
  5. void main() => runApp(MyApp());
  6. class MyApp extends StatefulWidget {
  7. @override
  8. _MyAppState createState() => _MyAppState();
  9. }
  10. class _MyAppState extends State<MyApp> {
  11. String _platformVersion = 'Unknown';
  12. @override
  13. void initState() {
  14. super.initState();
  15. initPlatformState();
  16. }
  17. // Platform messages are asynchronous, so we initialize in an async method.
  18. Future<void> initPlatformState() async {
  19. String platformVersion;
  20. // Platform messages may fail, so we use a try/catch PlatformException.
  21. try {
  22. platformVersion = await DubbingLib.platformVersion;
  23. } on PlatformException {
  24. platformVersion = 'Failed to get platform version.';
  25. }
  26. // If the widget was removed from the tree while the asynchronous platform
  27. // message was in flight, we want to discard the reply rather than calling
  28. // setState to update our non-existent appearance.
  29. if (!mounted) return;
  30. setState(() {
  31. _platformVersion = platformVersion;
  32. });
  33. }
  34. @override
  35. Widget build(BuildContext context) {
  36. return MaterialApp(
  37. home: Scaffold(
  38. appBar: AppBar(
  39. title: const Text('Plugin example app'),
  40. ),
  41. body: Center(
  42. child: Text('Running on: $_platformVersion\n'),
  43. ),
  44. ),
  45. );
  46. }
  47. }