当我试图在飞镖代码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);*/
}发布于 2022-01-12 08:14:36
类名为Textsection,其中section为小写,但构造函数名为TextSection,并带有大写Section。尝试将类重命名为TextSection,以便它与构造函数名称匹配。
发布于 2022-01-12 09:06:44
您必须先定义类构造函数,然后才能使用这个构造函数,我希望这将对您有用。
进口‘包装:颤振/材料。飞镖’;
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://stackoverflow.com/questions/70678142
复制相似问题