小编GoV*_*ndh的帖子

如何在 dart/flutter 中监听流值

任何人都可以帮助追踪音频的位置(即)

   if(durationtoOne(position==5)){
FlutterToast.Showtoast(msg:"I am At 5 sec");
}
Run Code Online (Sandbox Code Playgroud)

如果在 initstate 中添加出现错误,我会卡在哪里添加此代码,我想通过音频平台收听位置

代码从这里开始

  import 'dart:async';
    import 'package:assets_audio_player/assets_audio_player.dart';
    import 'package:flutter/material.dart';
    import 'package:fluttertoast/fluttertoast.dart';

    class SmartMantra extends StatefulWidget {
    @override
  _SmartMantraState createState() => _SmartMantraState();
}

class _SmartMantraState extends State<SmartMantra> {
  StreamSubscription _positionSubscription;
  Duration position;
  AssetsAudioPlayer _assetsAudioPlayer;


  stream() {
    _positionSubscription = _assetsAudioPlayer.currentPosition
        .listen((p) => setState(() => position = p),);
  }

  @override
  void initState() {
    _assetsAudioPlayer.open("assets/shivamantra.mp3");
    stream();
    _assetsAudioPlayer.finished.listen((finished) {
      print(finished);
//      print(count);
    });
    super.initState();
  }

  @override
  void dispose() {
    _positionSubscription.cancel();
    super.dispose();
  }
  @override
  Widget build(BuildContext context) …
Run Code Online (Sandbox Code Playgroud)

stream dart flutter

6
推荐指数
1
解决办法
3万
查看次数

飞行模式开启时 getCurrentPosition 不返回位置

插件地理定位器:^9.0.1 飞行关闭模式运行良好,

如果飞行模式打开,则无法获取位置/抛出任何错误。即使在飞行模式下我也需要获取位置

请建议更改或使用此功能的其他插件

也尝试使用位置插件,同样的情况发生

最少的代码

import 'package:flutter/material.dart';
import 'package:geolocator/geolocator.dart';

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: HomePage(),
    );
  }
}
class HomePage extends StatefulWidget {
  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
   Position? pos;
   bool? _isLoading;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("Location"),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center, …
Run Code Online (Sandbox Code Playgroud)

location flutter geolocator

5
推荐指数
1
解决办法
420
查看次数

标签 统计

flutter ×2

dart ×1

geolocator ×1

location ×1

stream ×1