Hello everyone and happy new year.
I am a beginner with flutter and dart an I have an issue on flutter whenever I add charts_flutter
in my pubspec.yaml dependencies.
I tried running flutter clean
, look out for the others topics with this kind of issue, and changed the Flutter SDK environment but it didn't work.
main.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
And these are the error messages:
Running "flutter pub get" in chat...
The current Dart SDK version is 2.8.0-dev.0.0.flutter-aa6709974d. Because chat depends on charts_flutter >=0.0.1+1 <0.4.0 which requires SDK version >=1.23.0 <2.0.0, version solving failed. pub get failed (1; Because chat depends on charts_flutter >=0.0.1+1 <0.4.0 which requires SDK version >=1.23.0 <2.0.0, version solving failed.) exit code 1