The `TotalFood` in the
static List category = [
{"name": "Food", "amount": totalfood},
{"name": "Entertainment", "amount": 100.0},
{"name": "Personal", "amount": 80.0},
{"name": "Transportation", "amount": 50.0},
{"name": "Studies", "amount": 100.0},
{"name": "Any", "amount": 30.0},
];
給出錯誤無法在初始化程式中訪問實體成員“totalfood”。嘗試用不同的運算式替換對實體成員的參考。
import 'package:flutter/material.dart';
class AppColors {
final double totalfood;
const AppColors(this.totalfood);
static List pieColors = [
Colors.indigo[400],
Colors.blue,
Colors.green,
Colors.amber,
Colors.deepOrange,
Colors.brown,
];
static List category = [
{"name": "Food", "amount": totalfood},
{"name": "Entertainment", "amount": 100.0},
{"name": "Personal", "amount": 80.0},
{"name": "Transportation", "amount": 50.0},
{"name": "Studies", "amount": 100.0},
{"name": "Any", "amount": 30.0},
];
static Color primaryWhite = Color(0xffedf1f4);
}
這是影像

uj5u.com熱心網友回復:
category是靜態的,在totalfood這種情況下必須是靜態的。
你可以這樣做
class AppColors {
static late final double totalfood;
void _totalFood(double tf) {
totalfood = tf;
}
AppColors({required double totalFood}) {
_totalFood(totalFood);
}
//....
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/426605.html
