当我尝试使用传递给无状态小部件的字符串时出现错误。在内部版本中打印的消息会打印我正在发送的消息,但是当我尝试在Text(message)中使用它时,会得到以下提示:
Arguments of a constant creation must be constant expressions. Try making the argument a valid constant, or use 'new' to call the constructor.
import 'package:flutter/material.dart';
class ProgressCenter extends StatelessWidget {
const ProgressCenter({
Key key,
this.message,
}) : super(key: key);
final String message;
@override
Widget build(BuildContext context) {
print(message);
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
SizedBox(
child: CircularProgressIndicator(),
width: 60,
height: 60,
),
const Padding(
padding: EdgeInsets.only(top: 16),
child: Text(message),
)
],
),
);
}
}