triple_switch 1.1.3 copy "triple_switch: ^1.1.3" to clipboard
triple_switch: ^1.1.3 copied to clipboard

Triple switch has three positions ON - WAIT - OFF

Triple Switch

Triple Switch #

Three-position switch has three states ON - WAIT - OFF. WAIT is a state awaiting finish heavy operation like getting information from net. ON / OFF is a usual state of switch

Usage #

In main setup, the initial state of switches and stateful functions

SwitchState().data = {
    'stringIdentifier1':  SwitchModel(
        position: await readData('switch1'),          /// Read state from same Storage
        saveFunc: (val) => saveData('switch1', val),  /// Save state to some Storage
    ),
    'stringIdentifier2': SwitchModel(
        position: await readData('switch2'),          /// Read state from same Storage
        saveFunc: (val) => saveData('switch2', val)   /// Save state to some Storage
    ),
    'stringIdentifier3': SwitchModel(
        position: await readData('switch3'),          /// Read state from same Storage
        saveFunc: (val) => saveData('switch3', val)   /// Save state to some Storage
    ),
    'stringIdentifier4': SwitchModel(),               /// Can use without usage statement
};

Use the widget

TripleSwitch(
  /// String Unique Identifier of switch
  /// If the switch is used as a three-way switch, a unique ID must be specified.
  /// If the switch is used as a regular two-position switch, 
  /// you do not need to specify the id, but to work, 
  /// you must specify the original value in value and get a new value in the onChange() event.
  id: 'stringIdentifier1',
  
  /// Enabled or Disabled switch
  enabled: true,                                

  /// Default value of two-position switch, true -> ON / false -> OFF
  value: swState,

  /// Mirroring by horizontal functionality for slider
  mirroring: false,
  
  /// Timeout for waiting for the called function from OFF to ON
  timeoutOffOn: 50,

  /// Timeout for waiting for the called function from ON to OFF
  timeoutOnOff: 15,

  /// Function witch called when tap on widget for switching state from OFF to ON
  functionOffOn: heavyFunction1,

  /// Function witch called when tap on widget for switching state from ON to OFF
  functionOnOff: heavyFunction3,

  /// List of arguments for called function from OFF to ON
  argumentsOffOn: [923000000],

  /// List of arguments for called function from ON to OFF
  argumentsOnOff: [12, 12],

  /// The event returns the new position of the switch, 
  /// which is the opposite of the one passed in the Value parameter.
  onChanged: (v) => setState(() => swState = v);

  /// Speed of animation switch
  animateDuration: 200,

  /// Size of track
  sizeTrack: Size(100, 50),

  /// Size of slider
  sizeSlider: Size(50, 50),

  /// Custom decoration of track in ON position
  decorationTrackOn: BoxDecoration(...),

  /// Custom decoration of track in OFF position
  decorationTrackOff: BoxDecoration(...),

  /// Custom decoration of track in WAIT position
  decorationTrackWait: BoxDecoration(...),

  /// Custom decoration of track when switch is Disabled
  decorationTrackDisabled: BoxDecoration(...),

  /// Custom decoration of slider in ON position
  decorationSliderOn: BoxDecoration(...),

  /// Custom decoration of slider in OFF position
  decorationSliderOff: BoxDecoration(...),

  /// Custom decoration of slider in WAIT position
  decorationSliderWait: BoxDecoration(...),

  /// Custom decoration of slider when switch is Disabled
  decorationSliderDisabled: BoxDecoration(...),

  /// Widget on slider in ON Position
  on: Text('ON'),

  /// Widget on slider in OFF Position
  off: Text('OFF'),

  /// Widget on slider in WAIT Position
  wait: Text('WAIT'),

  /// Widget on slider when switch is Disabled
  disabled: Text('DIS'),                        
  
  timerStyle: TextStyle(...),                   /// Style of text for timeout
)

A heavy function should be of the following format, it can gets a list of arguments of different types and returns a list in which the first element is the result of an operation of a different type, and the second element is the result of the success of the operation - has a logical type (true or false).

Future<List<dynamic>> heavyFunction1(List<dynamic> args) async {
  ///... Some heavy and long operations
  
  return [total, res];
}

Additional information #

- if timeout isn't set this switch will be work like usually 2-position switcher.
- When widget "wait" don't initialize, the countdown timer is showing
- This switcher widget will gets different Design, assigned user. 
img1 img2 img3
img4 img5 img6

Planned future changes #

1. Add the option to disable visualization of slider
2. Figure out what you can replace the isolate with for the web version
2
likes
150
points
28
downloads
screenshot

Publisher

verified publisherleocode.ru

Weekly Downloads

Triple switch has three positions ON - WAIT - OFF

Homepage
Repository (GitHub)

Topics

#widget

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

flutter

More

Packages that depend on triple_switch