Skip to content

Instantly share code, notes, and snippets.

@suragch
Last active July 3, 2019 23:14
Show Gist options
  • Save suragch/33fa53eda8f79bdaec74a0b6348d2138 to your computer and use it in GitHub Desktop.
Save suragch/33fa53eda8f79bdaec74a0b6348d2138 to your computer and use it in GitHub Desktop.
CustomPaint setup
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: HomeWidget(),
),
);
}
}
class HomeWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Center(
child: CustomPaint( // <-- CustomPaint widget
size: Size(300, 300),
painter: MyPainter(),
),
);
}
}
class MyPainter extends CustomPainter { // <-- CustomPainter class
@override
void paint(Canvas canvas, Size size) {
// <-- Insert your painting code here.
}
@override
bool shouldRepaint(CustomPainter old) {
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment