Does Flutter automatically display Cupertino UI in iOS and Material in Android with a single codebase?

后端 未结 4 488
温柔的废话
温柔的废话 2021-02-04 23:13

I need to know whether Flutter will render the iOS Cupertino style on iOS and Material on Android with a single codebase. I want to know this before starting to develop my app w

4条回答
  •  你的背包
    2021-02-04 23:51

    Below simple implementation:

    class AdaptiveSwitch extends StatelessWidget {
      const AdaptiveSwitch({Key key,
          @required this.value,
          @required this.onChanged,
          this.activeColor,
          this.dragStartBehavior = DragStartBehavior.start})
          : assert(dragStartBehavior != null),
            super(key: key);
    
      final bool value;
    
      final ValueChanged onChanged;
    
      final Color activeColor;
    
      final DragStartBehavior dragStartBehavior;
    
      @override
      Widget build(BuildContext context) {
        return Theme.of(context).targetPlatform = TargetPlatform.iOS
            ? CupertinoSwitch(
                value: value,
                activeColor: activeColor,
                onChanged: onChanged,
                dragStartBehavior: dragStartBehavior,
              )
            : Switch(
                value: value,
                activeColor: activeColor,
                onChanged: onChanged,
                dragStartBehavior: dragStartBehavior,
              );
      }
    }
    

提交回复
热议问题