小编Nik*_*cio的帖子

Flutter url_launcher 未处理的异常:无法启动 youtube url(由 canLaunch 引起)

我正在尝试使用该url_launcher插件通过链接打开 youtube 视频,但该canLaunch功能不断抛出错误。我只能通过完全删除该canLaunch功能来绕过此错误,但无法弄清楚出了什么问题。

代码不起作用:

_goToVideo(YoutubeVideoData video) async {
  if (await canLaunch(video.url)) {
    await launch(video.url);
  } else {
    throw 'Could not launch ${video.url}';
  }
}
Run Code Online (Sandbox Code Playgroud)

代码工作:

_goToVideo(YoutubeVideoData video) async {
  await launch(video.url);
}
Run Code Online (Sandbox Code Playgroud)

我不太确定为什么我不能使用自述文件示例中canLaunch所写的方法

错误:

E/flutter (12574): [ERROR:flutter/lib/ui/ui_dart_state.cc(166)] Unhandled Exception: Could not launch https://www.youtube.com/watch?v=-3g5WlqJtIo
E/flutter (12574): #0      _goToVideo (package:esfandapp/widgets/newsList/videoCard.dart:71:5)
E/flutter (12574): <asynchronous suspension>
E/flutter (12574): #1      VideoCard.build.<anonymous closure> (package:esfandapp/widgets/newsList/videoCard.dart:13:20)
E/flutter (12574): #2      _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:992:19)
E/flutter (12574): #3      _InkResponseState.build.<anonymous closure> (package:flutter/src/material/ink_well.dart:1098:38)
E/flutter (12574): …
Run Code Online (Sandbox Code Playgroud)

flutter

14
推荐指数
4
解决办法
8877
查看次数

当 showSelectedLabels 和 showUnselectedLabels 设置为 false 时,bottomNavigationBar 显示标签(Flutter)

弄乱了bottomNavigationBarTheme并注意到标签显示在所选项目上,即使showSelectedLabels设置为false。这是一个错误还是我错过了什么?此行为仅在属性ThemeData在移至时声明时才成立,bottomNavigationBar它的行为符合预期。

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

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'app',
      themeMode: ThemeMode.dark,
      darkTheme: ThemeData(
        brightness: Brightness.dark,
        primarySwatch: Colors.blueGrey,
        canvasColor: Color.fromRGBO(52, 58, 70, 1),
        bottomNavigationBarTheme: BottomNavigationBarThemeData(
          selectedIconTheme: IconThemeData(
           color: Color.fromRGBO(113, 124, 152, 1),
           size: 28,
          ),
          unselectedIconTheme: IconThemeData(
            color: Color.fromRGBO(196, 201, 212, 1),
            size: 28,
          ),
          type: BottomNavigationBarType.fixed,
          showSelectedLabels: false,
          showUnselectedLabels: false,
        ),
        cardColor: Color.fromRGBO(52, 58, 70, …
Run Code Online (Sandbox Code Playgroud)

flutter

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

标签 统计

flutter ×2