when I’m trying to define colour in dart code final Color _color; TextSection (this._color);
it gives me an error. do anyone know how to fix this error.
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);*/
}
2
Answers
Your class name is
Textsection
wheresection
is lowercase but your constructor is namedTextSection
with an uppercaseSection
.Try renaming your class to
TextSection
so it matches your constructor name.You have to define the class constructor first then you are able to use this, I hope this will work for you.
import ‘package:flutter/material.dart’;