Files
2022-01-24 16:10:41 +08:00

97 lines
2.4 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:iflytek_speech_demo/iflytek_speech_demo.dart';
//插件的示例代码调用插件dart中
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Flutter_ScreenUtil',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: HomePage(title: 'FlutterScreenUtil Demo'),
);
}
}
class HomePage extends StatefulWidget {
const HomePage({Key? key, required this.title}) : super(key: key);
final String title;
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
@override
Widget build(BuildContext context) {
//设置尺寸填写设计中设备的屏幕尺寸如果设计基于360dp * 690dp的屏幕
ScreenUtil.init(
BoxConstraints(
maxWidth: MediaQuery.of(context).size.width,
maxHeight: MediaQuery.of(context).size.height),
designSize: Size(360, 690),
context: context,
minTextAdapt: true,
orientation: Orientation.portrait);
return Scaffold(
appBar: AppBar(
title: Text('测试'),
),
body: Content(),
);
}
}
class Content extends StatefulWidget {
const Content({Key? key}) : super(key: key);
@override
_ContentState createState() => _ContentState();
}
class _ContentState extends State<Content> {
String appID = 'da2aaf9b';
IflytekSpeechDemo iflytekSpeechDemo = IflytekSpeechDemo();
@override
Widget build(BuildContext context) {
return Container(
height: 1.sh - 90,
width: 1.sw,
child: ListView(
children: [
ElevatedButton(
child: Text("test"),
onPressed: () {
print('我被点击了');
iflytekSpeechDemo.init(appID);
},
),
ElevatedButton(
child: Text("start"),
onPressed: () {
print('我被点击了');
iflytekSpeechDemo.start((Map<String, dynamic> event) async {
print("flutter onOpenNotification: $event");
});
},
),
],
),
);
}
}