Line data Source code
1 : // ThemeExtension has no home outside material.dart on the supported SDKs.
2 : // ignore: deprecated_member_use
3 : import 'package:flutter/material.dart' show ThemeExtension;
4 : import 'package:flutter/widgets.dart';
5 : import 'package:fossui/src/theme/lerp_encoders.dart';
6 : import 'package:theme_tailor_annotation/theme_tailor_annotation.dart';
7 :
8 : part 'foss_spacing.tailor.dart';
9 :
10 : /// Spacing scale built from one [unit] (4 px). Call the instance to scale the
11 : /// unit ([call]) or build an inset ([all]); every step is `unit * n`.
12 : ///
13 : /// ```dart
14 : /// const s = FossSpacing.standard;
15 : /// final gap = s(2); // 8 px
16 : /// final pad = s.all(4); // EdgeInsets.all(16)
17 : /// ```
18 : @TailorMixin(themeGetter: ThemeGetter.none, encoders: [DoubleLerpEncoder()])
19 : class FossSpacing extends ThemeExtension<FossSpacing>
20 : with _$FossSpacingTailorMixin {
21 : /// Creates a spacing scale. Prefer [standard] unless retheming.
22 5 : const FossSpacing({this.unit = 4});
23 :
24 : /// Base spacing unit in logical pixels.
25 : @override
26 : final double unit;
27 :
28 : /// `unit * n`: `spacing(2)` is 8 px, `spacing(1.5)` is 6 px.
29 153 : double call(double n) => unit * n;
30 :
31 : /// `EdgeInsets.all(unit * n)`.
32 4 : EdgeInsets all(double n) => EdgeInsets.all(unit * n);
33 :
34 : /// The default spacing scale.
35 : static const standard = FossSpacing();
36 : }
|