svui_plugin 0.0.32 copy "svui_plugin: ^0.0.32" to clipboard
svui_plugin: ^0.0.32 copied to clipboard

svui sdk.

example/lib/main.dart

// Copyright 2018 The Flutter team. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:math';

import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:svui_plugin/account.dart';
import 'package:svui_plugin/language.dart';
import 'package:svui_plugin/svui/svui_listener.dart';
import 'package:svui_plugin/svui_plugin.dart';
import 'package:svui_plugin/util.dart';
import 'package:svui_plugin/loglevel.dart';
import 'package:svui_plugin_example/login/model_login_auth.dart';
import 'package:svui_plugin_example/login/presenter_login.dart';
import 'package:svui_plugin_example/net/net.dart';
import 'package:svui_plugin_example/player.dart';
import 'package:svui_plugin_example/qa/qawidget.dart';
import 'package:svui_plugin_example/test/testwidget.dart';
import 'package:svui_plugin_example/util/config_manager.dart';
import 'package:svui_plugin_example/util/configure.dart';
import 'package:svui_plugin_example/util/preference.dart';
import 'package:svui_plugin_example/util/toast.dart';
import 'login/route_login.dart';
import 'oral/oralwidget.dart';

void main() {
  Global.init().then((value) => runApp(MultiProvider(
          // provider 主题变化数据
          providers: [
            ChangeNotifierProvider(create: (_) => LoginAuthModel()),
          ],
          // provider 主题变化监听
          child: MyApp())));
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        title: 'Startup Name Generator',
        theme: ThemeData(primaryColor: Colors.white),
        home: MainWidget());
  }
}

class MainWidget extends StatefulWidget {
  @override
  _MainWidgetState createState() => _MainWidgetState();
}

class _MainWidgetState extends State<MainWidget> with PresenterLogin {
  bool _islogin = Configure.isLogin();
  bool isRelease = Configure.isReleased();

  @override
  void initState() {
    super.initState();
    SvuiUtil.setLogLevel(LogLevel.LOG_LEVEL_VERBOSE);
  }

  @override
  Widget build(BuildContext context) {
    if (Net.context == null) {
      Net.context = context;
    }
    return new Scaffold(
      appBar: AppBar(
        title: Text("SVUI DEMO"),
      ),
      body: Center(
        child: ListView(
          children: [
            SizedBox(height: 10),
            Center(child: Text(isRelease ? "product" : "test")),
            Center(
              child: Switch(
                onChanged: (v) {
                  if (Configure.isLogin()) {
                    Toast.showToast("请先退出登录,再切换环境!");
                    return;
                  }
                  setState(() {
                    isRelease = v;
                    Preference.setBool(Configure.RELEASE_KEY, isRelease);
                    Global.init();
                  });
                },
                value: isRelease,
              ),
            ),
            SizedBox(height: 8),
            Container(
              height: 50,
              color: Colors.green,
              child: FlatButton(
                onPressed: () {
                  Navigator.of(context).push(
                      MaterialPageRoute<void>(builder: (BuildContext context) {
                    return WordOralWidget();
                  }));
                },
                child: Text(
                  '口语评测',
                  style: TextStyle(color: Colors.white),
                ),
              ),
            ),
            SizedBox(height: 0),
            Container(
              height: 50,
              color: Colors.yellow,
              child: FlatButton(
                onPressed: () {
                  Navigator.of(context).push(
                      MaterialPageRoute<void>(builder: (BuildContext context) {
                    return QAWidget();
                  }));
                },
                child: Text(
                  '问答',
                  style: TextStyle(color: Colors.white),
                ),
              ),
            ),
            SizedBox(height: 0),
            Container(
              height: 50,
              color: _islogin ? Colors.grey : Colors.lightGreen,
              child: FlatButton(
                onPressed: () {
                  if (_islogin) {
                    Toast.showToast("已登录 如需更换账号,请先点击退出登录");
                    return;
                  }
                  Navigator.of(context).push(
                      MaterialPageRoute<void>(builder: (BuildContext context) {
                    return LoginRoute();
                  }));
                },
                child: Text(
                  _islogin ? "已登录" : "登录",
                  style: TextStyle(color: Colors.white),
                ),
              ),
            ),
            SizedBox(height: 0),
            Container(
              height: 50,
              color: Colors.redAccent,
              child: FlatButton(
                onPressed: () {
                  logout(context);
                  setState(() {
                    _islogin = false;
                  });
                },
                child: Text(
                  '退出登录',
                  style: TextStyle(color: Colors.white),
                ),
              ),
            ),
            SizedBox(height: 0),
            Container(
              height: 50,
              color: Colors.blueAccent,
              child: FlatButton(
                onPressed: () {
                  Random random = new Random();
                  SvuiPlugin.getInstance().speak(
                      "我说粤语 ${random.nextInt(10000)}",
                      language: "yue-CHN");
                },
                child: Text(
                  '测试',
                  style: TextStyle(color: Colors.white),
                ),
              ),
            ),
            SizedBox(height: 0),
            Container(
              height: 50,
              color: Colors.purpleAccent,
              child: FlatButton(
                onPressed: () {
                  Navigator.of(context).push(
                      MaterialPageRoute<void>(builder: (BuildContext context) {
                    return TestWidget();
                  }));
                },
                child: Text(
                  '接口测试',
                  style: TextStyle(color: Colors.white),
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }

  void playVideo() {
    Player player = Player();
    player.init();
    // player.playAssets('res/file/perfect.mp3');
    player.playUrl(
        "http://ros.roobo.net/voice/static/usertts/2020-10-20/156/reply.7edeef7e1df7fcd7.183c61c6-7476-4e6e-b8b6-a22601fcaed3.mp3");
  }

  void getSize() async {
    int s = await SvuiUtil.getAudioRecordSize();
    print("cache size:$s");
  }
}
1
likes
110
points
42
downloads

Publisher

unverified uploader

Weekly Downloads

svui sdk.

Homepage

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

connectivity, convert, crypto, dio, flutter, flutter_web_plugins

More

Packages that depend on svui_plugin