Memo : Flutter x Dart [2015-2016]
  • Introduction
  • hello
    • helloworld
    • build flutter
    • build as standalone android app(old)
      • draw text
      • draw image
      • set icon
    • build as standalone apk(now)
    • build as ios app
    • build as linux app
    • build as mac app
    • build mojo
    • build as chromeapp
  • rendering
    • draw_rect
    • anime_rect
    • anime_rect(use animation.dart)
    • draw_image
    • rotate_image
    • draw_image_from_assets
    • sound_test(rendering & service)
    • touch_test
    • multitouch_test
    • [@]demo::mini game(spacewar!)
    • draw_text
    • draw_path
    • draw_vertexs
    • draw_vertexs_with_image
    • [@]demo:3d anime
    • input text from ime(RenderObject)
  • widget
    • text
    • network image
    • assets image
    • raw image
    • container
    • row
    • col
    • flexible
    • navigator
    • stateful component
    • scaffold
    • scaffold x drawer
    • scrollable viewport
    • scrollable list
    • input text from ime(EditableText)
  • dart:io
    • HttpClient Post & Get
    • NetworkInterface
    • TCP Socket
    • UDP Socket
    • File Path(dart:io & service)
    • File Create & Permission
  • dart:ui
    • draw rect
    • pointer event
  • mojo for flutter
    • get and post request
    • sensor test
    • [@]demo:gravity sensor
  • 2d physics for scratch
    • collision without rotation
    • [@]democollision without friction
    • [b]
  • 2d physics for newton
  • mojo for native
    • build mojo
  • 48 hour trial
    • create iron heart
    • tiny tetris
Powered by GitBook
On this page

Was this helpful?

  1. rendering

draw_path

Previousdraw_textNextdraw_vertexs

Last updated 5 years ago

Was this helpful?

// following code is checked in 2016/01/13
import 'package:flutter/widgets.dart';
import 'package:flutter/painting.dart';
import 'package:flutter/rendering.dart';
import 'dart:ui' as sky;

void main() {
  runApp(new DrawPathWidget()); //new GameTest());
}

class DrawPathWidget extends OneChildRenderObjectWidget {
  RenderObject createRenderObject() {
    return new DrawPathObject();
  }
}

class DrawPathObject extends RenderBox {
  void paint(PaintingContext context, Offset offset) {
    context.canvas.scale(2.5, 2.5);
    context.canvas.translate(50.0, 50.0);
    paintWithStroke(context, offset);
    context.canvas.translate(50.0, 0.0);
    paintWithLinearGradient(context, offset);
  }

  void paintWithStroke(PaintingContext context, Offset offset) {
    Paint p = new Paint();
    p.strokeWidth = 2.0;
    p.style = sky.PaintingStyle.stroke;
    Path path = new Path();
    path.moveTo(0.0, 0.0);
    path.lineTo(10.0, 50.0);
    path.lineTo(50.0, 60.0);
    path.lineTo(40.0, 10.0);
    path.close();
    p.color = new Color.fromARGB(0xaa, 0xaa, 0xff, 0xff);
    context.canvas.drawPath(path, p);
  }

  void paintWithLinearGradient(PaintingContext context, Offset offset) {
    Paint p = new Paint();
    p.style = sky.PaintingStyle.strokeAndFill;

    List<Color> colors = [
      const Color.fromARGB(0xaa, 0xff, 0x00, 0x00),
      const Color.fromARGB(0xaa, 0x00, 0x00, 0x00),
      const Color.fromARGB(0xaa, 0xff, 0xff, 0xff),
    ];
    List<double> stops = [0.0, 0.5, 1.0];
    LinearGradient gg = new LinearGradient(
        begin: new Point(0.0, 0.0),
        end: new Point(50.0, 60.0),
        colors: colors,
        stops: stops);
    p.shader = gg.createShader();

    Path path = new Path();
    path.moveTo(0.0, 0.0);
    path.lineTo(10.0, 50.0);
    path.lineTo(50.0, 60.0);
    path.lineTo(40.0, 10.0);
    path.close();
    context.canvas.drawPath(path, p);
  }
}
https://github.com/kyorohiro/hello_skyengine/tree/master/draw_path