Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

with compile works for flutter3.0 #768

Closed
wants to merge 13 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions charts_common/lib/common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ export 'src/chart/layout/layout_view.dart'
ViewMargin,
ViewMeasuredSizes;
export 'src/chart/line/line_chart.dart' show LineChart;
export 'src/chart/line/line_grid_chart.dart' show LineGridChart;
export 'src/chart/line/line_renderer.dart' show LineRenderer;
export 'src/chart/line/line_renderer_config.dart' show LineRendererConfig;
export 'src/chart/pie/arc_label_decorator.dart'
Expand Down
9 changes: 9 additions & 0 deletions charts_common/lib/src/chart/common/chart_canvas.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,15 @@ abstract class ChartCanvas {
double? strokeWidthPx,
List<int>? dashPattern});

void drawSmoothLine(
{required List<Point> points,
Rectangle<num>? clipBounds,
Color? fill,
Color? stroke,
bool? roundEndCaps,
double? strokeWidthPx,
List<int>? dashPattern});

/// Renders a pie, with an optional hole in the center.
void drawPie(CanvasPie canvasPie);

Expand Down
2 changes: 1 addition & 1 deletion charts_common/lib/src/chart/common/series_renderer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import 'series_datum.dart' show SeriesDatum;
const rendererIdKey = AttributeKey<String>('SeriesRenderer.rendererId');

const rendererKey =
AttributeKey<SeriesRenderer<Object>>('SeriesRenderer.renderer');
AttributeKey<SeriesRenderer<dynamic>?>('SeriesRenderer.renderer');

/// A series renderer draws one or more series of data onto a chart canvas.
abstract class SeriesRenderer<D> extends LayoutView {
Expand Down
46 changes: 46 additions & 0 deletions charts_common/lib/src/chart/line/line_grid_chart.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright 2018 the Charts project authors. Please see the AUTHORS file
// for details.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import 'dart:collection' show LinkedHashMap;

import '../cartesian/axis/axis.dart' show NumericAxis;
import '../cartesian/axis/draw_strategy/gridline_draw_strategy.dart'
show GridlineRendererSpec;
import '../cartesian/cartesian_chart.dart' show NumericCartesianChart;
import '../common/series_renderer.dart' show SeriesRenderer;
import '../layout/layout_config.dart' show LayoutConfig;
import '../line/line_renderer.dart' show LineRenderer;
import '../line/line_chart.dart' show LineChart;

class LineGridChart extends LineChart {
LineGridChart(
{bool? vertical,
LayoutConfig? layoutConfig,
NumericAxis? primaryMeasureAxis,
NumericAxis? secondaryMeasureAxis,
LinkedHashMap<String, NumericAxis>? disjointMeasureAxes})
: super(
vertical: vertical,
layoutConfig: layoutConfig,
primaryMeasureAxis: primaryMeasureAxis,
secondaryMeasureAxis: secondaryMeasureAxis,
disjointMeasureAxes: disjointMeasureAxes);

@override
void initDomainAxis() {
domainAxis!.tickDrawStrategy = GridlineRendererSpec<num>()
.createDrawStrategy(context, graphicsFactory!);
}
}
24 changes: 17 additions & 7 deletions charts_common/lib/src/chart/line/line_renderer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -994,13 +994,23 @@ class LineRenderer<D> extends BaseCartesianRenderer<D> {
animatingLine.getCurrentLine(animationPercent))
.forEach((line) {
if (line != null) {
canvas.drawLine(
clipBounds: _getClipBoundsForExtent(line.positionExtent!),
dashPattern: line.dashPattern,
points: line.points!.toPoints(),
stroke: line.color,
strokeWidthPx: line.strokeWidthPx,
roundEndCaps: line.roundEndCaps);
if (config.smoothLine) {
canvas.drawSmoothLine(
clipBounds: _getClipBoundsForExtent(line.positionExtent!),
dashPattern: line.dashPattern,
points: line.points!.toPoints(),
stroke: line.color,
strokeWidthPx: line.strokeWidthPx,
roundEndCaps: line.roundEndCaps);
} else {
canvas.drawLine(
clipBounds: _getClipBoundsForExtent(line.positionExtent!),
dashPattern: line.dashPattern,
points: line.points!.toPoints(),
stroke: line.color,
strokeWidthPx: line.strokeWidthPx,
roundEndCaps: line.roundEndCaps);
}
}
});
}
Expand Down
3 changes: 3 additions & 0 deletions charts_common/lib/src/chart/line/line_renderer_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ class LineRendererConfig<D> extends LayoutViewConfig
/// Whether lines should have round end caps, or square if false.
final bool roundEndCaps;

final bool smoothLine;

LineRendererConfig(
{this.customRendererId,
this.radiusPx = 3.5,
Expand All @@ -85,6 +87,7 @@ class LineRendererConfig<D> extends LayoutViewConfig
this.layoutPaintOrder = LayoutViewPaintOrder.line,
this.areaOpacity = 0.1,
this.roundEndCaps = false,
this.smoothLine = false,
SymbolRenderer? symbolRenderer})
: symbolRenderer = symbolRenderer ?? LineSymbolRenderer();

Expand Down
11 changes: 5 additions & 6 deletions charts_common/lib/src/chart/pie/arc_renderer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import 'arc_renderer_element.dart'
import 'base_arc_renderer.dart';

const arcElementsKey =
AttributeKey<List<ArcRendererElement<Object>>>('ArcRenderer.elements');
AttributeKey<List<ArcRendererElement<dynamic>>?>('ArcRenderer.elements');

class ArcRenderer<D> extends BaseArcRenderer<D> {
final ArcRendererConfig<D> config;
Expand Down Expand Up @@ -160,13 +160,12 @@ class ArcRenderer<D> extends BaseArcRenderer<D> {
var arcList =
_seriesArcMap.putIfAbsent(arcListKey, () => AnimatedArcList());

var elementsList =
series.getAttr(arcElementsKey) as List<ArcRendererElement<D>>;
var elementsList = series.getAttr(arcElementsKey);

if (series.data.isEmpty) {
// If the series is empty, set up the "no data" arc element. This should
// occupy the entire chart, and use the chart style's no data color.
final details = elementsList[0];
final details = elementsList![0];

var arcKey = '__no_data__';

Expand Down Expand Up @@ -209,8 +208,8 @@ class ArcRenderer<D> extends BaseArcRenderer<D> {

for (var arcIndex = 0; arcIndex < series.data.length; arcIndex++) {
final Object? datum = series.data[arcIndex];
final details = elementsList[arcIndex];
final domainValue = details.domain;
final details = elementsList![arcIndex];
final domainValue = details.domain as D?;

var arcKey = '${series.id}__$domainValue';

Expand Down
7 changes: 4 additions & 3 deletions charts_common/lib/src/chart/scatter_plot/point_renderer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ import '../../common/math.dart'
show distanceBetweenPointAndLineSegment, NullablePoint;
import '../../common/symbol_renderer.dart'
show CircleSymbolRenderer, SymbolRenderer;
import '../../data/series.dart' show AccessorFn, AttributeKey, TypedAccessorFn;
import '../../data/series.dart'
show AccessorFn, AccessorFn2, AttributeKey, TypedAccessorFn;
import '../cartesian/axis/axis.dart'
show ImmutableAxis, domainAxisKey, measureAxisKey;
import '../cartesian/cartesian_renderer.dart' show BaseCartesianRenderer;
Expand All @@ -43,7 +44,7 @@ const pointElementsKey =
AttributeKey<List<PointRendererElement<Object>>>('PointRenderer.elements');

const pointSymbolRendererFnKey =
AttributeKey<AccessorFn<String>>('PointRenderer.symbolRendererFn');
AttributeKey<AccessorFn2<String>>('PointRenderer.symbolRendererFn');

const pointSymbolRendererIdKey =
AttributeKey<String>('PointRenderer.symbolRendererId');
Expand Down Expand Up @@ -657,7 +658,7 @@ class PointRenderer<D> extends BaseCartesianRenderer<D> {
// fall back to the default.
String? symbolRendererId;
if (symbolRendererFn != null) {
symbolRendererId = symbolRendererFn(details.index);
symbolRendererId = symbolRendererFn(details.index!);
}
symbolRendererId ??= series.getAttr(pointSymbolRendererIdKey);
symbolRendererId ??= defaultSymbolRendererId;
Expand Down
2 changes: 2 additions & 0 deletions charts_common/lib/src/data/series.dart
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,8 @@ class Series<T, D> {
/// Otherwise, [index] must be a valid subscript into a list of `series.length`.
typedef AccessorFn<R> = R Function(int? index);

typedef AccessorFn2<R> = R? Function(int index);

typedef TypedAccessorFn<T, R> = R Function(T datum, int? index);

class AttributeKey<R> extends TypedKey<R> {
Expand Down
19 changes: 11 additions & 8 deletions charts_flutter/example/android/.gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
*.iml
*.class
.gradle
gradle-wrapper.jar
/.gradle
/captures/
/gradlew
/gradlew.bat
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures
GeneratedPluginRegistrant.java

# Remember to never publicly share your keystore.
# See https://flutter.dev/docs/deployment/android#reference-the-keystore-from-the-app
key.properties
**/*.keystore
**/*.jks
7 changes: 0 additions & 7 deletions charts_flutter/example/android/Android_Charts.xml

This file was deleted.

44 changes: 32 additions & 12 deletions charts_flutter/example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,46 @@ if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'
}

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
compileSdkVersion 28
compileSdkVersion flutter.compileSdkVersion
ndkVersion flutter.ndkVersion

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

kotlinOptions {
jvmTarget = '1.8'
}

lintOptions {
disable 'InvalidPackage'
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}

defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.examples"
minSdkVersion 16
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
applicationId "com.example.example"
// You can update the following values to match your application needs.
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration.
minSdkVersion flutter.minSdkVersion
targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}

buildTypes {
Expand All @@ -45,7 +67,5 @@ flutter {
}

dependencies {
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.example">
<!-- The INTERNET permission is required for development. Specifically,
the Flutter tool needs it to communicate with the running application
to allow setting breakpoints, to provide hot reload, etc.
-->
<uses-permission android:name="android.permission.INTERNET"/>
</manifest>
41 changes: 18 additions & 23 deletions charts_flutter/example/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,39 +1,34 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.examples">

<!-- The INTERNET permission is required for development. Specifically,
flutter needs it to communicate with the running application
to allow setting breakpoints, to provide hot reload, etc.
-->
<uses-permission android:name="android.permission.INTERNET"/>

<!-- io.flutter.app.FlutterApplication is an android.app.Application that
calls FlutterMain.startInitialization(this); in its onCreate method.
In most cases you can leave this as-is, but you if you want to provide
additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. -->
<application
android:name="io.flutter.app.FlutterApplication"
android:label="Charts Flutter Gallery"
package="com.example.example">
<application
android:label="example"
android:name="${applicationName}"
android:icon="@mipmap/ic_launcher">
<activity
android:name=".MainActivity"
android:exported="true"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<!-- This keeps the window background of the activity showing
until Flutter renders its first frame. It can be removed if
there is no splash screen (such as the default splash screen
defined in @style/LaunchTheme). -->
<!-- Specifies an Android theme to apply to this Activity as soon as
the Android process has started. This theme is visible to the user
while the Flutter UI initializes. After that, this theme continues
to determine the Window background behind the Flutter UI. -->
<meta-data
android:name="io.flutter.app.android.SplashScreenUntilFirstFrame"
android:value="true" />
android:name="io.flutter.embedding.android.NormalTheme"
android:resource="@style/NormalTheme"
/>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<!-- Don't delete the meta-data below.
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
<meta-data
android:name="flutterEmbedding"
android:value="2" />
</application>
</manifest>

This file was deleted.

Loading