View main.dart
This file contains 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
... | |
children: <Widget>[ | |
_buildMyWidget1(), | |
_buildMyWidget2(), | |
// const MyWidget1(), | |
// const MyWidget2(), | |
Text( | |
'You have pushed the button this many times:', | |
), | |
Text( |
View main.dart
This file contains 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
... | |
children: <Widget>[ | |
// _buildMyWidget1(), | |
// _buildMyWidget2(), | |
const MyWidget1(), | |
MyWidget2(), | |
Text( | |
'You have pushed the button this many times:', | |
), |
View main.dart
This file contains 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
... | |
children: <Widget>[ | |
_buildMyWidget1(), | |
_buildMyWidget2(), | |
// MyWidget1(), | |
// MyWidget2(), | |
Text( | |
'You have pushed the button this many times:', | |
), |
View mywidget2.dart
This file contains 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 MyWidget2 extends StatefulWidget { | |
const MyWidget2({Key? key}) : super(key: key); | |
@override | |
_MyWidget2State createState() => _MyWidget2State(); | |
} | |
class _MyWidget2State extends State<MyWidget2> { | |
@override | |
Widget build(BuildContext context) { |
View mywidget1.dart
This file contains 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 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))); | |
} | |
} |
View main.dart
This file contains 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
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
This file contains 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
@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
This file contains 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
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
This file contains 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
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
This file contains 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(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); | |
} |
NewerOlder