This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyApp extends StatelessWidget { | |
... | |
Widget build(...) { | |
return MaterialApp(..., home: MyHomePage()); | |
} | |
} | |
class MyHomePage extends StatefulWidget { | |
... | |
_MyHomePageState createState() => _MyHomePageState(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void paint(ui.Canvas canvas, ui.Size size) { | |
final Offset centerPoint = Offset(0, 0); | |
// math for each branch | |
final angle = 360 / nodes; | |
// list of branch end points (x,y) | |
List<List<double>> points = []; | |
// for each branch | |
for (int i = 0; i < nodes; i++) { | |
final double lineLength = 200; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class RadarChartTransition extends AnimatedWidget { | |
final AnimationController controller; | |
final int nodes; | |
final int segments; | |
final List<double> data; | |
final List<String> labels; | |
// CONSTRUCTOR | |
RadarChartTransition( | |
this.controller, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// in pubspec.yaml | |
flame: ^0.29.4 | |
// in main.dart | |
import 'package:flutter/material.dart'; | |
import 'package:flame/game.dart'; // for creating Game class | |
import 'package:flame/gestures.dart'; // for TapDetector mixin | |
import 'package:flutter/gestures.dart'; // for TapDownDetails class | |
import 'dart:ui'; // for Canvas and Size | |
// in console | |
flutter run --no-sound-null-safety |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CustomGame extends Game { | |
@override | |
void render(Canvas canvas) { | |
// TODO: implement render | |
} | |
@override | |
void update(double t) { | |
// TODO: implement update | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void main() { | |
CustomGame game = CustomGame(); // create instance of class | |
runApp(game.widget); // run game | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CustomGame extends Game { | |
Size? screenSize; | |
bool hasPressed; | |
// this will be CustomGame's resize function | |
@override | |
void resize (Size size) { | |
screenSize = size; // assign Game widget size to screenSize | |
super.resize(size); // call Game's resize function again | |
} | |
... // update and render functions |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void render(Canvas canvas) { | |
/// BACKGROUND (BOTTOMMOST LAYER) | |
Rect bgRect = Rect.fromLTWH(0, 0, screenSize!.width,screenSize!.height); | |
Paint bgPaint = Paint(); | |
bgPaint.color = Color(0xffbbcc00); | |
canvas.drawRect(bgRect, bgPaint); | |
/// TARGET BOX (TOPMOST LAYER) | |
print(screenSize); // ! target box does not change with screen size | |
double screenCenterX = screenSize!.width / 2; | |
double screenCenterY = screenSize!.height / 2; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flame/gestures.dart'; // for TapDetector mixin | |
import 'package:flutter/gestures.dart'; // for TapDownDetails class | |
class BoxGame extends Game with TapDetector { | |
bool hasWon = false; | |
@override | |
void onTapDown(TapDownDetails tapDownDetails) { | |
// handle taps here |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void main() { | |
print('Hello World!'); | |
List<int> testList = List.generate(5, (index) => index); | |
print(testList); | |
} | |
// OUTPUT: | |
// Hello World! | |
// [0,1,2,3,4] |
OlderNewer