Upgrade to Pro — share decks privately, control downloads, hide ads and more …

SVG na ratunek nudnym UI

SVG na ratunek nudnym UI

Prezentacja z meetupu 9.06.2022r na Flutter Silesia #3 w Katowicach

Wojciech Warwas

June 23, 2022
Tweet

More Decks by Wojciech Warwas

Other Decks in Programming

Transcript

  1. <svg height="80" width="300"> <g fill="none"> <path stroke="red" d="M5 20 l215

    0" /> <path stroke="black" d="M5 40 l215 0" /> <path stroke="blue" d="M5 60 l215 0" /> </g> </svg>
  2. <svg height="80" width="300"> <g fill="none"> <path stroke="red" d="M5 20 l215

    0" /> <path stroke="black" d="M5 40 l215 0" /> <path stroke="blue" d="M5 60 l215 0" /> </g> </svg>
  3. Przewaga paint - brak i/o - kontrola nad rysowaniem -

    wydajność - możliwości dalszej optymalizacji / zmian
  4. - node.js CLI - generuje kod Flutter na podstawie SVG

    - krzywe beziera - FILL oraz STROKE - path tracing svg-to- fl utter convert ~/path.svg SVG to fl utter
  5. Show me the code! <svg height="80" width="300"> <g fill="none"> <path

    stroke="red" d="M5 20 l215 0" /> <path stroke="black" d="M5 40 l215 0" /> <path stroke="blue" d="M5 60 l215 0" /> </g> </svg>
  6. Show me the code! <svg height="80" width="300"> <g fill="none"> <path

    stroke="red" d="M5 20 l215 0" /> <path stroke="black" d="M5 40 l215 0" /> <path stroke="blue" d="M5 60 l215 0" /> </g> </svg> class MyPainter extends CustomPainter { @override void paint(Canvas canvas, Size size) { Path path = Path(); final Paint paint = Paint(); // Path 3 Stroke path = Path(); paint.color = const Color(0xff0000ff); paint.style = PaintingStyle.stroke; paint.strokeWidth = 1; path.moveTo(size.width * 0.02, size.height * 0.75); path.lineTo(size.width * 0.73, size.height * 0.75); canvas.drawPath(path, paint); } @override bool shouldRepaint(CustomPainter oldDelegate) { return true; } } // Path 1 Stroke paint.color = const Color(0xffff0000); paint.style = PaintingStyle.stroke; paint.strokeWidth = 1; path.moveTo(size.width * 0.02, size.height * 0.25); path.lineTo(size.width * 0.73, size.height * 0.25); canvas.drawPath(path, paint);
  7. Show me the code! <svg height="80" width="300"> <g fill="none"> <path

    stroke="red" d="M5 20 l215 0" /> <path stroke="black" d="M5 40 l215 0" /> <path stroke="blue" d="M5 60 l215 0" /> </g> </svg> // Path 1 Stroke paint.color = const Color(0xffff0000); paint.style = PaintingStyle.stroke; paint.strokeWidth = 1; path.moveTo(size.width * 0.02, size.height * 0.25); path.lineTo(size.width * 0.73, size.height * 0.25); canvas.drawPath(path, paint);
  8. Path tracing PathMetrics pathMetrics = path.computeMetrics(); for (PathMetric pathMetric in

    pathMetrics) { Path extractPath = pathMetric.extractPath( 0.0, pathMetric.length * progress, ); canvas.drawPath(extractPath, paint); } svg-to- fl utter convert ~/path.svg --path-tracing svg-to- fl utter convert ~/path.svg —path-tracing-all
  9. Dzięki za uwagę! Q&A Dodatkowe podziękowania: Kuba za pomysły Iteo

    za one line Łukasz za cierpliwość https://github.com/ fl utter-clutter/svg-to- fl utter-path-converter https://github.com/obiwanzenobi/svg-to- fl utter-path-converter/tree/temp/fsilesia