寻找与Android类对应的Flutter图形类

时间:2017-08-01 20:22:11

标签: flutter

我正在研究将简单的开源Android图表工具转换为Flutter的可行性。看一些Android图表工具,我发现他们可能会使用以下Android导入。

接下来,我试图找出Flutter类,这些类非常粗略地和松散地对应于Android类。大多数都是通过名字来看,我发现这个粗略的映射。

有人能够指出我在带问号的行上的Flutter课吗? (关于填充线的评论也很棒)

| Android                             | Flutter         | Comment | Android API                                                                     | Flutter API                                                |
|-------------------------------------+-----------------+---------+---------------------------------------------------------------------------------+------------------------------------------------------------|
| android.content.Context;            | ?               |         | https://developer.android.com/reference/android/content/Context.html            | ?                                                          |
| android.util.AttributeSet;          | ?               |         | https://developer.android.com/reference/android/util/AttributeSet.html          | ?                                                          |
| android.graphics.Color;             | dart:ui.Color   |         | https://developer.android.com/reference/android/graphics/Color.html             | https://docs.flutter.io/flutter/dart-ui/Color-class.html   |
| android.graphics.Canvas;            | dart:ui.Canvas  |         | https://developer.android.com/reference/android/graphics/Canvas.html            | https://docs.flutter.io/flutter/dart-ui/Canvas-class.html  |
| android.graphics.Rect;              | dart:ui.Rect    |         | https://developer.android.com/reference/android/graphics/Rect.html              | https://docs.flutter.io/flutter/dart-ui/Rect-class.html    |
| android.graphics.Point;             | dart:math.Point |         | https://developer.android.com/reference/android/graphics/Point.html             | https://docs.flutter.io/flutter/dart-math/Point-class.html |
| android.graphics.Paint;             | dart:ui.Paint   |         | https://developer.android.com/reference/android/graphics/Paint.html             | https://docs.flutter.io/flutter/dart-ui/Paint-class.html   |
| android.graphics.Region;            | ?               |         | https://developer.android.com/reference/android/graphics/Region.html            | ?                                                          |
| android.graphics.drawable.Drawable; | ? Picture ?     |         | https://developer.android.com/reference/android/graphics/drawable/Drawable.html | ?                                                          |
| android.view.View;                  | ? Viewport ?    |         | https://developer.android.com/reference/android/view/View.html                  | ?                                                          |

1 个答案:

答案 0 :(得分:0)

图形应用程序的Android-> Flutter代码转换期间,我最终使用了以下类的映射。除了我最终不需要的AttributeSet之外,每个都有或多或少的相应类。

| Android                               | Flutter                                  | Comment                                                         |
|---------------------------------------+------------------------------------------+-----------------------------------------------------------------|
| android.content.Context;              | package:flutter:widgets.BuildContext     | somewhat equivalent                                             |
| android.util.AttributeSet;            | ?                                        |                                                                 |
| android.graphics.Color;               | dart:ui.Color                            | import 'dart:ui' as ui; // in code: ui.Color                    |
| android.graphics.Canvas;              | dart:ui.Canvas                           |                                                                 |
| android.graphics.Rect;                | dart:ui.Rect                             | For operations such as "contains(Offset)" etc                   |
| android.graphics.Point;               | dart:ui.Offset (*not* dart:math.Point)   | Offset in context of graphics                                   |
| android.graphics.Paint;               | dart:ui.Paint                            |                                                                 |
| android.graphics.Region;              | dart:ui.Rect                             |                                                                 |
| android.graphics.drawable.Drawable;   | used CustomPaint - see line below        |                                                                 |
| android.view.View;  impl Drawable     | package:flutter/widgets.dart.CustomPaint | import 'package:flutter/widgets.dart' as widgets;               |
| -   (continuation line)               | -    combined with CustomPainter         | -    in code: widgets.CustomPaint, widgets.CustomPainter        |
| android.graphics.Path                 | dart:ui.Path                             |                                                                 |
| android.graphics.PathEffect           | Needed for dash-lines.                   | there is no dash-lines effect in Dart, intentional, performance |
| android.Text (when drawing on Canvas) | package:flutter/painting.dart.TextSpan   | import package:flutter/painting.dart';                          |
| -   (continuation line)               | -    *not* widgets.Text                  | -    there are multiple *Text* classes in Dart.                 |
|                                       |                                          | -    TextSpan is for drawing text on Canvas.                    |