Files

105 lines
2.6 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';
String ttsText = '今天合肥天气很不好';
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.wakeupStart((Map<String, dynamic> event) async {
print("flutter onOpenNotification: $event");
});
},
),
ElevatedButton(
child: Text("tts"),
onPressed: () {
print('我要合成');
iflytekSpeechDemo.ttsStart(ttsText);
},
),
],
),
);
}
}