基礎子界面新增:
class AddToLogScreen extends StatelessWidget {
@override
Widget build (BuildContext context) {
return CupertinoPageScaffold(
navigationBar: CupertinoNavigationBar(
middle: Text ('Add to Log'),
), // CupertinoNavigationBar
child: Center(
child: Text('Add to Log Screen!'),
),// Center
),// CupertinoPageScaffold
}
}
新增:
class AddToLogScreen extends Statelesswidget {
@override
Widget build(Bui laContext context) {
final model = Provider.of<AppStates>(context, listen: true);
return AdaptiveTextTheme(
child: CupertinoPageScaffold(
navigationBar: CupertinoNavigationBar(
middle: Text ('Add to Log'),
), // CupertinoNavigationBar
child: AddToLogForm(model.veggieById(1),(entry) {
model.addLogEntry(entry);
Navigator.of(context).pop();
}), // Center
), // CupertinoPageScaffold
); //AdaptiveTextTheme
}
}
typedef LogEntryCallback = void Function (LogEntry entry) ;
class AddToLogForm extends Statefulwidget {
const AddToLogForm(this.veggie, this.onEntryCreated);
final Veggie veggie;
final LogEntryCallback onEntryCreated;
@override
_AddToLogFormState createState () => _AddToLogFormState() ;
}
class _AddToLogFormState extends State<AddToLogForm> {
@override
Widget build(BuildContext context) {
final textTheme = AdaptiveTextTheme. of(context);
return SizedBox();
並解答如何將業務邏輯與表示邏輯分開?
當中使用螢幕小工具(AddToLogScreen),為管理與模型的活動。實際上會從中讀取數據並將數據保存其中有咩。
另一個小部件(_AddToLogFormState)負責表單的外觀和界面表現方式