Giter VIP home page Giter VIP logo

Comments (1)

QuncCccccc avatar QuncCccccc commented on June 26, 2024 1

If the differences are only the default size, color, and animation, I think we can introduce a private _SwitchConfig and do adaptation inside CupertinoSwitch, just like what we did in material Switch. IMHO, creating 2 different widgets might be not necessary:) But I'm open to other suggestions if there are any other concerns!

mixin _SwitchConfig {
  double get trackHeight;
  double get trackWidth;
  double get thumbRadius;
  double get ThumbExtension; // This is 7 for iOS switch, 1 for macOS switch
}

class _SwitchConfigIOS with _SwitchConfig {
  ...
  @override
  double get ThumbExtension => 7.0;
}

class _SwitchConfigMacOS with _SwitchConfig {
  ...
  @override
  double get ThumbExtension => 1.0;
}

Based on different platforms, we can provide different values using switch statement when we build the Switch widget,

final _SwitchConfig config = switch (platform) {
  TargetPlatform.android || TargetPlatform.fuchsia || TargetPlatform.iOS => _SwitchConfigIOS(context),
  TargetPlatform.linux || TargetPlatform.windows || TargetPlatform.macOS => _SwitchConfigMacOS(context),
}

Or we can only return _SwitchConfigMacOS() when the platform is macOS, and _SwitchConfigIOS() for other platforms.

from flutter.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.