【发布时间】:2020-06-28 15:57:12
【问题描述】:
我有两个代码:
import 'package:flutter/material.dart';
class ScaffoldModels extends StatelessWidget {
final Widget bodyWidget;
ScaffoldModels(this.bodyWidget);
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Color.fromRGBO(255, 179, 0, 85),
appBar: AppBar(
title: Text(
"ROTA 56 - TESTE",
style: TextStyle(color: Colors.orange, fontSize: 26, fontFamily: ''),
),
centerTitle: true,
backgroundColor: Colors.yellow,
),
body: bodyWidget,
);
}
}
和:
import 'package:flutter/material.dart';
import 'package:rota56project/defaultmodels/scaffold.dart';
class PlottingScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
ScaffoldModels(_bodyPlotting);
}
}
Widget _bodyPlotting(BuildContext context) {
return Container();
}
在我的 main.dart 中,我调用了 PlottingScreen..
但在行:
ScaffoldModels(_bodyPlotting);
我收到这条消息: strong 参数类型'Widget Function(BuildContext)' 不能赋值给参数类型'Widget'.dart(argument_type_not_assignable) text
我的错误是什么?
【问题讨论】:
-
返回 ScaffoldModels(_bodyPlotting);
-
但这样的做法并不聪明
-
你觉得做什么比较好?