Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Indy M. Indy9000

🏠
Working from home
View GitHub Profile
@Indy9000
Indy9000 / main.dart
Created Aug 1, 2021
flutter-mythbusting-06
View main.dart
...
children: <Widget>[
_buildMyWidget1(),
_buildMyWidget2(),
// const MyWidget1(),
// const MyWidget2(),
Text(
'You have pushed the button this many times:',
),
Text(
@Indy9000
Indy9000 / main.dart
Created Aug 1, 2021
flutter-mythbusting-05
View main.dart
...
children: <Widget>[
// _buildMyWidget1(),
// _buildMyWidget2(),
const MyWidget1(),
MyWidget2(),
Text(
'You have pushed the button this many times:',
),
@Indy9000
Indy9000 / main.dart
Last active Aug 1, 2021
flutter-mythbusting-04
View main.dart
...
children: <Widget>[
_buildMyWidget1(),
_buildMyWidget2(),
// MyWidget1(),
// MyWidget2(),
Text(
'You have pushed the button this many times:',
),
@Indy9000
Indy9000 / mywidget2.dart
Created Aug 1, 2021
flutter-mythbusting-03
View mywidget2.dart
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 Aug 1, 2021
flutter-mythbusting-02
View mywidget1.dart
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 Aug 1, 2021
flutter-mybusting-01
View main.dart
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>[
View linechartpainter-04.dart
@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);
View linechartpainter-05.dart
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;
View linechartpainter-03.dart
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) {
View linechartpainter-02.dart
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);
}