(Flutter) pub 聊天失败取决于 charts_flutter >=0.0.1+1 <0.4.0 这需要 SDK 版本 >=1.23.0 <2.0.0 退出代码 1

Posted

技术标签:

【中文标题】(Flutter) pub 聊天失败取决于 charts_flutter >=0.0.1+1 <0.4.0 这需要 SDK 版本 >=1.23.0 <2.0.0 退出代码 1【英文标题】:(Flutter) pub get failed chat depends on charts_flutter >=0.0.1+1 <0.4.0 which requires SDK version >=1.23.0 <2.0.0 exit code 1 【发布时间】:2020-04-20 01:34:33 【问题描述】:

大家好,新年快乐。

我是颤振和飞镖的初学者,每当我在 pubspec.yaml 依赖项中添加 charts_flutter 时都会遇到颤振问题。

我尝试运行flutter clean,寻找其他主题存在此类问题,并更改了 Flutter SDK 环境,但没有成功。

ma​​in.dart

import 'package:flutter/material.dart';
import 'package:charts_flutter/flutter.dart' as charts;
void main() => runApp(new MyApp());
class MyApp extends StatelessWidget 
   @override
   Widget build(BuildContext context) 
   return new MaterialApp(
      title: 'Flutter Demo',
      theme: new ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: new MyHomePage(title: 'Flutter Demo Home Page'),
    );
  


class MyHomePage extends StatefulWidget 
   MyHomePage(Key key, this.title) : super(key: key);
   final String title;
   @override
  _MyHomePageState createState() => new _MyHomePageState();


class ClicksPerYear 
   final String year;
   final int clicks;
   final charts.Color color;
   ClicksPerYear(this.year, this.clicks, Color color)
      : this.color = new charts.Color(r: color.red, g: color.green, b: color.blue, a: color.alpha);


class _MyHomePageState extends State<MyHomePage> 
   int _counter = 0;
   void _incrementCounter() 
   setState(() 
      _counter++;
    );
  
   @override
   Widget build(BuildContext context) 
   var data = [
   new ClicksPerYear('2016', 12, Colors.red),
   new ClicksPerYear('2017', 42, Colors.yellow),
   new ClicksPerYear('2018', _counter, Colors.green),
    ];
   var series = [
   new charts.Series(
        domainFn: (ClicksPerYear clickData, _) => clickData.year,
        measureFn: (ClicksPerYear clickData, _) => clickData.clicks,
        colorFn: (ClicksPerYear clickData, _) => clickData.color,
        id: 'Clicks',
        data: data,
      ),
    ];
   var chart = new charts.BarChart<ClicksPerYear>(
      series,
      animate: true,
    );
   var chartWidget = new Padding(
      padding: new EdgeInsets.all(32.0),
      child: new SizedBox(
        height: 200.0,
        child: chart,
      ),
    );
   return new Scaffold(
      appBar: new AppBar(
        title: new Text(widget.title),
      ),
      body: new Center(
        child: new Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
   new Text('You have pushed the button this many times:',
            ),
   new Text('$_counter',
              style: Theme.of(context).textTheme.display1,
            ),
            chartWidget,
          ],
        ),
      ),
      floatingActionButton: new FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: new Icon(Icons.add),
      ),
    );
  

pubspec.yaml

version: 1.0.0+1

environment:
  sdk: ">=2.1.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter
  charts_flutter: ^0.2.0


  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for ios style icons.
  cupertino_icons: ^0.1.2

dev_dependencies:
  flutter_test:
    sdk: flutter

这些是错误消息:

在聊天中运行“flutter pub get”... 当前的 Dart SDK 版本是 2.8.0-dev.0.0.flutter-aa6709974d。 因为聊天依赖charts_flutter >=0.0.1+1 =1.23.0 =0.0.1+1 =1.23.0

【问题讨论】:

【参考方案1】:

出了什么问题?

您正在添加一个过时版本的 charts_flutter 插件,它依赖于旧版本的 Flutter SDK。

你能做什么?

在您的 pubspec.yaml 中,替换:

charts_flutter: ^0.2.0

charts_flutter: ^0.8.1

我为什么会遇到这个问题?

由于聊天依赖于charts_flutter >=0.0.1+1 =1.23.0 =0.0.1+1 =1.23.0

从日志中可以看出,charts_flutter v0.2.0 需要 Flutter SDK &gt;=1.23.0 &lt;2.0.0。就您而言,它目前使用的是 Flutter SDK 版本 &gt;=2.1.0 &lt;3.0.0

pubspec.yaml

environment:
  sdk: ">=2.1.0 <3.0.0"

【讨论】:

【参考方案2】:

只需在终端中运行flutter upgrade 即可将flutter 升级到最新的稳定版本。你可以阅读这个upgrading flutter

【讨论】:

以上是关于(Flutter) pub 聊天失败取决于 charts_flutter >=0.0.1+1 <0.4.0 这需要 SDK 版本 >=1.23.0 <2.0.0 退出代码 1的主要内容,如果未能解决你的问题,请参考以下文章

Flutter 2.0 升级,pub 因无意义的依赖行为而失败

使用新的 Flutter 2.2.2 版本为 Riverpod 运行“flutter pub get”时版本解决失败

Stream 内的 Flutter ListView.Builder 不更新

Flutter Android Studio 构建失败

Firebase for Flutter 登录构建失败

升级后在 nfc_in_flutter 上构建失败