Skip to content

Commit a158112

Browse files
committed
version 2.2.2 changes:
* Fixed overflow issue when using minWidth: double.maxFinite * Code cleanups
1 parent 9f650c0 commit a158112

File tree

9 files changed

+267
-213
lines changed

9 files changed

+267
-213
lines changed

CHANGELOG.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1+
## 2.2.2
2+
* Fixed overflow [issue](https://github.com/PramodJoshi/toggle_switch/issues/79)
3+
* Code cleanups
4+
15
## 2.2.1
2-
* updated version in README
3-
* updated screenshot
6+
* Updated version in README
7+
* Updated screenshot
48

59
## 2.2.0
610
* Minor cleanups and fixes
@@ -16,7 +20,7 @@
1620
* Added cancel toggle function ([PR 77](https://github.com/PramodJoshi/toggle_switch/pull/77/files)):
1721
- function:
1822
- cancelToggle: (index) {} (return type - Future\<bool>)
19-
* Added these options [PR 74](https://github.com/PramodJoshi/toggle_switch/pull/74/files)):
23+
* Added these options ([PR 74](https://github.com/PramodJoshi/toggle_switch/pull/74/files)):
2024
- center text:
2125
- centerText (optional, type bool - default false)
2226
- multi-line text:

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ In the `pubspec.yaml` of your flutter project, add the following dependency:
99
```yaml
1010
dependencies:
1111
...
12-
toggle_switch: ^2.2.1
12+
toggle_switch: ^2.2.2
1313
```
1414
1515
Import it:

example/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ In the `pubspec.yaml` of your flutter project, add the following dependency:
99
```yaml
1010
dependencies:
1111
...
12-
toggle_switch: ^2.2.1
12+
toggle_switch: ^2.2.2
1313
```
1414
1515
Import it:

example/pubspec.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ packages:
158158
path: ".."
159159
relative: true
160160
source: path
161-
version: "2.1.0"
161+
version: "2.2.2"
162162
vector_math:
163163
dependency: transitive
164164
description:

example/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: example
22
description: An example application using toggle switch widget.
3-
version: 2.2.1
3+
version: 2.2.2
44
publish_to: none
55

66
environment:

lib/row_to_column.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'package:flutter/material.dart';
22

3+
/// A widget that displays its children in a row or column based on the value of isVertical (toggle switch type).
34
class RowToColumn extends StatelessWidget {
45
final List<Widget> children;
56
final bool isVertical;

lib/toggle_switch.dart

Lines changed: 202 additions & 205 deletions
Large diffs are not rendered by default.

lib/utils.dart

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import 'package:flutter/material.dart';
2+
3+
class Utils {
4+
/// Calculates width to prevent overflow by taking screen width into account.
5+
/// Ignores customWidths if toggle switch is vertical
6+
static double calculateWidth(
7+
{required BuildContext context,
8+
required int index,
9+
required int totalSwitches,
10+
List<double>? customWidths,
11+
required double minWidth}) {
12+
/// Extra width to prevent overflow and add padding
13+
double extraWidth = 0.10 * totalSwitches;
14+
15+
/// Max screen width
16+
double screenWidth = MediaQuery.of(context).size.width;
17+
18+
/// Returns width per label
19+
///
20+
/// Returns passed minWidth per label if total requested width plus extra width is less than max screen width.
21+
/// Returns calculated width to fit within the max screen width if total requested width plus extra width is more than max screen width.
22+
return customWidths != null
23+
? customWidths[index]
24+
: ((totalSwitches + extraWidth) * minWidth < screenWidth
25+
? minWidth
26+
: screenWidth / (totalSwitches + extraWidth));
27+
}
28+
29+
/// Ignores customHeights if toggle switch is horizontal
30+
static double calculateHeight(
31+
{required BuildContext context,
32+
required int index,
33+
required int totalSwitches,
34+
List<double>? customHeights,
35+
required double minHeight}) {
36+
/// Extra height to prevent overflow and add padding
37+
double extraHeight = 0.10 * totalSwitches;
38+
39+
/// Max screen height
40+
double screenHeight = MediaQuery.of(context).size.height;
41+
42+
/// Returns width per label
43+
///
44+
/// Returns passed minHeight per label if total requested width plus extra height is less than max screen height.
45+
/// Returns calculated width to fit within the max screen width if total requested width plus extra height is more than max screen height.
46+
return customHeights != null
47+
? customHeights[index]
48+
: ((totalSwitches + extraHeight) * minHeight < screenHeight
49+
? minHeight
50+
: screenHeight / (totalSwitches + extraHeight));
51+
}
52+
}

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: toggle_switch
22
description: Toggle Switch - A simple toggle switch widget. It can be fully customized with desired icons, width, colors, text, corner radius etc. It also maintains selection state.
3-
version: 2.2.1
3+
version: 2.2.2
44
homepage: https://github.com/PramodJoshi/toggle_switch
55

66
environment:

0 commit comments

Comments
 (0)