當我試圖在飛鏢代碼中定義顏色時, final Color _color; TextSection (this._color);
它給了我一個錯誤。有誰知道如何解決這個錯誤。

import 'package:flutter/material.dart';
class Textsection extends StatelessWidget {
final Color _color;
TextSection (this._color);
@override
Widget build(BuildContext context) {
return Container(
decoration: BoxDecoration(
color:_color,
),
child:Text('hi')
);
}
/* @override
noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);*/
}
uj5u.com熱心網友回復:
您的類名是Textsection小寫section的,但您的建構式以TextSection大寫命名Section。嘗試重命名您的類,TextSection使其與您的建構式名稱匹配。
uj5u.com熱心網友回復:
您必須先定義類建構式,然后才能使用它,我希望這對您有用。
匯入“包:顫振/material.dart”;
class Textsection extends StatelessWidget {
final Color? color;
const Textsection({Key? key, this.color}) : super(key: key);
@override
Widget build(BuildContext context) {
return Container(
decoration: BoxDecoration(
color:color,
),
child:Text('hi')
);
}
/* @override
noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);*/
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/409984.html
標籤:
