70-92
class Logscreen extends Statelesswadget {
@override
Widget build(BuildContext context) {
final model = Provider.of<AppState>(context, listen: true);
final dayModels = model.days.map((day) {
return DailySummaryViewModel(
day,
model.entriesforDay(day).map((entry) {
return LogEntryViewModel (entry, model. veggieById(entry.veggield));
}).toList(),
); // DailySummaryViewModel
}).toList();
return AdaptivePageScaffold(
title: 'Your Log',
child: ListView.builder(
itenCount: dayModels.length,
itemBuilder: (context, index) => DailyDisplay(dayModels [index]),
),// ListView.builder
);// AdaptivePageScaffold
}
}
114-131
class AddToLogScreen extends Statelesswidget {
const AddToLogScreen(this veggield);
final int veggield;
@override
Widget build (BuildContext context) {
final model = Provider.of<AppState>(context, listen: true);
return AdaptivePageScaffold(
title: 'Add to Log',
child: AddToLogForm(model.veggieById(veggieId), (entry) {
model.addLogEntry(entry);
Navigator.of (context).pop();
}),// AddToLogForm
);// AdaptivePageScaffold
}
}
尾段
360-396
class AdaptiveSlider extends Statelesswidget {
const AdaptiveSlider({
this.value,
this.onChanged,
this.min = 0.0,
this.max = 1.0,
this.divisions,
Key key,
}) : super(key: key);
final double value;
final ValueChanged<double> onChanged;
final double min;
final double max;
final int divisions;
@override
Widget build (BuildContext context) {
if (isIOS) {
return CupertinoSlider(
value: value,
onChanged: onChanged,
min: min,
max: max,
divisions: divisions,
):
} else {
return Slider(
value; value,
onChanged: onChanged,
min: min,
max: max,
divisions: divisions,
);
}
}
}
//398-472
class AdaptiveTextField extends StatelessWidget { //調整顯示的文字
const AdaptiveTextField({
this.maxLines,
this.controller,
this.focusNode,
this.textAlign,
this.keyboardType,
this.maxLength,
this.onChanged,
this.style,
Key key,
}) : super(key: key);
final int maxlines;
final TextEditingController controller;
final FocusNode focusNode;
final TextAlign textAlign;
final TextinputType keyboardType;
final int maxLength;
final ValueChanged<String> onChanged;
final TextStyle style;
@override
Widget build(BuildContext context) {
if (is10S) {
return CupertinoTextfield(
maxLines: maxlines,
controller: controller,
focusNode: focusnode,
textAlign: textAlign,
keyboardtype: keyboardType,
maxLength: maxLength,
onChanged: onChanged,
style: style,
);
} else {
return TextField(
maxLines: maxlines,
controller: controller,
focusNode: focusnode,
textAlign: textAlign,
keyboardtype: keyboardType,
maxLength: maxLength,
onChanged: onChanged,
style: style,
);
}
}
}
}
class AdaptiveButton extends StatelessWidget { //調整底部顯示的文字
const AdaptiveButton ({
this.child,
this.onPressed,
Key key,
}) : super (key: key) ;
final Widget child;
final VoidCallback onPressed;
@override
Widget build (BuildContext context) {
if (isIOS) {
return CupertinoButton.filled( //選擇性使用CupertinoButton
child: child,
onPressed: onPressed,
);
} else {
return RaisedButton( //選擇性使用RaisedButton
child: child,
onPressed: onPressed,
);
}
}
}