class _MeisikiChartPage2State extends State<MeisikiChartPage2> {
int j = 0; // ■■■■■■■■■受け渡したい変数を定義
// 省略
Widget build(BuildContext context) {
// このwidget内で使用する変数を定義
return MediaQuery(
data: MediaQuery.of(context).copyWith(textScaleFactor: 1.0),
child: Scaffold(
appBar: AppBar(
title: Text('命式チャート(工事中) j:$j'),
),
body: Container(
color: Colors.black,
child: Center(
child: Column(
children: [
// 省略
CustomPaint(
painter: ShapePainter2(gogyou: j), // ■■■■■■■渡したい変数を引数に指定する
// painter: 渡したいクラス ( 渡した先で代入したい変数 : 渡したい変数 ), ■■■■■■■
),
],
), // Column
), // Center
), // Container
), // Scaffold
); // MediaQuery
} // Widget
} // class
// 省略
class ShapePainter2 extends CustomPainter {
int gogyou = 1; // 五行 0:木 1:火 2:土 3:金 4:水 // ■■■■■■受け取る値を代入する変数を定義
ShapePainter2({required this.gogyou}); // ■■■■■■■■■受け取る値を上記変数に代入
// 省略
} // class
_MeisikiChartPage2State クラスで定義されている変数 j を ShapePainter2 クラスで、変数 gogyou として使えるようにしている。