Skip to content

Instantly share code, notes, and snippets.

View Indy9000's full-sized avatar
🏠
Working from home

Indy M. Indy9000

🏠
Working from home
View GitHub Profile
@Indy9000
Indy9000 / main.dart
Created August 1, 2021 20:20
flutter-mythbusting-06
...
children: <Widget>[
_buildMyWidget1(),
_buildMyWidget2(),
// const MyWidget1(),
// const MyWidget2(),
Text(
'You have pushed the button this many times:',
),
Text(
@Indy9000
Indy9000 / main.dart
Created August 1, 2021 19:53
flutter-mythbusting-05
...
children: <Widget>[
// _buildMyWidget1(),
// _buildMyWidget2(),
const MyWidget1(),
MyWidget2(),
Text(
'You have pushed the button this many times:',
),
@Indy9000
Indy9000 / main.dart
Last active August 1, 2021 20:35
flutter-mythbusting-04
...
children: <Widget>[
_buildMyWidget1(),
_buildMyWidget2(),
// MyWidget1(),
// MyWidget2(),
Text(
'You have pushed the button this many times:',
),
@Indy9000
Indy9000 / mywidget2.dart
Created August 1, 2021 19:32
flutter-mythbusting-03
class MyWidget2 extends StatefulWidget {
const MyWidget2({Key? key}) : super(key: key);
@override
_MyWidget2State createState() => _MyWidget2State();
}
class _MyWidget2State extends State<MyWidget2> {
@override
Widget build(BuildContext context) {
@Indy9000
Indy9000 / mywidget1.dart
Created August 1, 2021 19:30
flutter-mythbusting-02
class MyWidget1 extends StatelessWidget {
const MyWidget1({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
print('MyWidget1 is building');
return Container(
child: Text("Stateless Widget1", style: TextStyle(fontSize: 30)));
}
}
@Indy9000
Indy9000 / main.dart
Created August 1, 2021 19:26
flutter-mybusting-01
Widget build(BuildContext context) {
print('MyHomePage is building');
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
@Indy9000
Indy9000 / linechartpainter-04.dart
Created June 13, 2021 19:50
line-chart-widget
@override
void paint(Canvas canvas, Size size) {
...
final labels = _computeLabels();
_drawYLabels(canvas, labels, points, boxW, border);
// draw x labels
final lt1 = Offset(border + boxW / 2.0, border + 4.5 * hu);
_drawXLabels(canvas, lt1, boxW);
@Indy9000
Indy9000 / linechartpainter-05.dart
Created June 13, 2021 19:50
line-chart-widget
List<String> _computeLabels() {
return _Y.map((yp) => "${yp.toStringAsFixed(1)}").toList();
}
void _drawYLabels(Canvas canvas, List<String> labels, List<Offset> points,
double boxW, double top) {
var i = 0;
labels.forEach((label) {
final dp = points[i];
final dy = (dp.dy - 15.0) < top ? 15.0 : -15.0;
@Indy9000
Indy9000 / linechartpainter-03.dart
Last active June 13, 2021 18:59
line-chart-widget
List<Offset> _computePoints(Offset lt, double boxW, double boxH, double hr) {
return _Y.map((yp) {
final yy = boxH - (yp - _min) * hr;
final dp = lt + Offset(0, yy);
lt += Offset(boxW, 0);
return dp;
}).toList();
}
Path _computePath(List<Offset> points) {
@Indy9000
Indy9000 / linechartpainter-02.dart
Last active June 13, 2021 19:00
line-chart-widget
void paint(Canvas canvas, Size size) {
...
final hr = boxH / (_max - _min); // height per unit value
final lt = Offset(border + boxW / 2.0, border);
final points = _computePoints(lt, boxW, boxH, hr);
final path = _computePath(points);
canvas.drawPath(path, linePaint);
_drawDataPoints(canvas, points, dotPaintFill);
}