This repository was archived by the owner on Jun 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathmain.dart
63 lines (57 loc) · 1.47 KB
/
main.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import 'package:flutter/material.dart';
import "package:p5/p5.dart";
import "sketch.dart";
void main() {
runApp(MyApp());
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key, this.title}) : super(key: key);
final String? title;
@override
_MyHomePageState createState() {
return _MyHomePageState();
}
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'P5 Demo',
theme: ThemeData(
// This is the theme of your application.
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'P5 Demo Home Page'),
);
}
}
class _MyHomePageState extends State<MyHomePage>
with SingleTickerProviderStateMixin {
MySketch? sketch;
late PAnimator animator;
@override
void initState() {
super.initState();
sketch = MySketch();
// Need an animator to call the draw() method in the sketch continuously,
// otherwise it will be called only when touch events are detected.
animator = PAnimator(this);
animator.addListener(() {
setState(() {
sketch!.redraw();
});
});
animator.run();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text("P5 Draw!")),
backgroundColor: const Color.fromRGBO(200, 200, 200, 1.0),
body: Center(
child: PWidget(sketch),
),
);
}
}