iT邦幫忙

2023 iThome 鐵人賽

DAY 20
0
自我挑戰組

基礎學習Flutter系列 第 20

Day20-學習[Building for iOS with Flutter]IOS 轉換Android (記錄)

  • 分享至 

  • xImage
  •  

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,
      );
    }
  }
}

上一篇
Day19-學習[Building for iOS with Flutter]IOS 轉換Android (記錄)
下一篇
Day21-學習[Building for iOS with Flutter]平台通道呼叫與傳回(記錄)
系列文
基礎學習Flutter30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言