-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add progress indicator themes (#717)
- Loading branch information
Showing
9 changed files
with
397 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
lib/src/widgets/yaru_circular_progress_indicator_theme.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import 'dart:ui'; | ||
|
||
import 'package:flutter/material.dart'; | ||
import 'package:yaru_widgets/src/widgets/yaru_progress_indicator.dart'; | ||
|
||
class YaruCircularProgressIndicatorThemeData | ||
extends YaruProgressIndicatorThemeData< | ||
YaruCircularProgressIndicatorThemeData> { | ||
YaruCircularProgressIndicatorThemeData( | ||
super.color, | ||
super.trackColor, | ||
super.strokeWidth, | ||
super.trackStrokeWidth, | ||
); | ||
|
||
@override | ||
ThemeExtension<YaruCircularProgressIndicatorThemeData> copyWith({ | ||
Color? color, | ||
Color? trackColor, | ||
double? strokeWidth, | ||
double? trackStrokeWidth, | ||
}) { | ||
return YaruCircularProgressIndicatorThemeData( | ||
color ?? this.color, | ||
trackColor ?? this.trackColor, | ||
strokeWidth ?? this.strokeWidth, | ||
trackStrokeWidth ?? this.trackStrokeWidth, | ||
); | ||
} | ||
|
||
@override | ||
ThemeExtension<YaruCircularProgressIndicatorThemeData> lerp( | ||
covariant ThemeExtension<YaruCircularProgressIndicatorThemeData>? other, | ||
double t, | ||
) { | ||
final o = other as YaruCircularProgressIndicatorThemeData?; | ||
return YaruCircularProgressIndicatorThemeData( | ||
Color.lerp(color, o?.color, t), | ||
Color.lerp(trackColor, o?.trackColor, t), | ||
lerpDouble(strokeWidth, o?.strokeWidth, t), | ||
lerpDouble(trackStrokeWidth, o?.trackStrokeWidth, t), | ||
); | ||
} | ||
} | ||
|
||
class YaruCircularProgressIndicatorTheme extends InheritedWidget { | ||
const YaruCircularProgressIndicatorTheme({ | ||
super.key, | ||
required this.data, | ||
required super.child, | ||
}); | ||
|
||
final YaruCircularProgressIndicatorThemeData data; | ||
|
||
static YaruCircularProgressIndicatorThemeData? of(BuildContext context) { | ||
final t = context.dependOnInheritedWidgetOfExactType< | ||
YaruCircularProgressIndicatorTheme>(); | ||
return t?.data ?? | ||
Theme.of(context).extension<YaruCircularProgressIndicatorThemeData>(); | ||
} | ||
|
||
@override | ||
bool updateShouldNotify(YaruCircularProgressIndicatorTheme oldWidget) { | ||
return data != oldWidget.data; | ||
} | ||
} |
Oops, something went wrong.