Skip to content

Commit

Permalink
Merge pull request #18 from mkobuolys/feat/image-slide-theme
Browse files Browse the repository at this point in the history
feat: add image slide theme
  • Loading branch information
mkobuolys authored Sep 22, 2023
2 parents b4d12dc + 73a294e commit 918e886
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# NEXT

- feat: add `FlutterDeckImageSlideTheme`

# 0.4.3

- fix: `FlutterDeckSlideStepsBuilder` triggers builder on slide change
Expand Down
10 changes: 5 additions & 5 deletions lib/src/templates/image_slide.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_deck/src/flutter_deck.dart';
import 'package:flutter_deck/src/flutter_deck_layout.dart';
import 'package:flutter_deck/src/templates/slide_base.dart';
import 'package:flutter_deck/src/theme/flutter_deck_theme.dart';
import 'package:flutter_deck/src/theme/templates/flutter_deck_image_slide_theme.dart';
import 'package:flutter_deck/src/widgets/widgets.dart';

/// A signature for a function that builds an image for a slide.
Expand All @@ -15,6 +15,8 @@ typedef ImageBuilder = Image Function(BuildContext context);
/// and rendering the image using the provided [imageBuilder].
///
/// To use a custom background, you can pass the [backgroundBuilder].
///
/// This template uses the [FlutterDeckImageSlideTheme] to style the slide.
class FlutterDeckImageSlide extends StatelessWidget {
/// Creates a new image slide.
///
Expand All @@ -40,6 +42,7 @@ class FlutterDeckImageSlide extends StatelessWidget {

@override
Widget build(BuildContext context) {
final theme = FlutterDeckImageSlideTheme.of(context);
final configuration = context.flutterDeck.configuration;
final footerConfiguration = configuration.footer;
final headerConfiguration = configuration.header;
Expand All @@ -55,10 +58,7 @@ class FlutterDeckImageSlide extends StatelessWidget {
),
if (label != null) ...[
const SizedBox(height: 4),
Text(
label!,
style: FlutterDeckTheme.of(context).textTheme.bodySmall,
),
Text(label!, style: theme.labelTextStyle),
],
],
),
Expand Down
10 changes: 10 additions & 0 deletions lib/src/theme/flutter_deck_theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ class FlutterDeckThemeData {
color: colorScheme.onBackground,
textStyle: textTheme.header,
),
imageSlideTheme: FlutterDeckImageSlideThemeData(
labelTextStyle: textTheme.bodySmall,
),
slideTheme: FlutterDeckSlideThemeData(
backgroundColor: colorScheme.background,
color: colorScheme.onBackground,
Expand Down Expand Up @@ -117,6 +120,7 @@ class FlutterDeckThemeData {
required this.codeHighlightTheme,
required this.footerTheme,
required this.headerTheme,
required this.imageSlideTheme,
required this.slideTheme,
required this.speakerInfoWidgetTheme,
required this.splitSlideTheme,
Expand All @@ -137,6 +141,9 @@ class FlutterDeckThemeData {
/// The visual properties of a header.
final FlutterDeckHeaderThemeData headerTheme;

/// The visual properties of an image slide.
final FlutterDeckImageSlideThemeData imageSlideTheme;

/// The base visual properties of a slide.
final FlutterDeckSlideThemeData slideTheme;

Expand All @@ -162,6 +169,7 @@ class FlutterDeckThemeData {
FlutterDeckCodeHighlightThemeData? codeHighlightTheme,
FlutterDeckFooterThemeData? footerTheme,
FlutterDeckHeaderThemeData? headerTheme,
FlutterDeckImageSlideThemeData? imageSlideTheme,
FlutterDeckSlideThemeData? slideTheme,
FlutterDeckSpeakerInfoWidgetThemeData? speakerInfoWidgetTheme,
FlutterDeckSplitSlideThemeData? splitSlideTheme,
Expand All @@ -173,6 +181,7 @@ class FlutterDeckThemeData {
codeHighlightTheme: this.codeHighlightTheme.merge(codeHighlightTheme),
footerTheme: this.footerTheme.merge(footerTheme),
headerTheme: this.headerTheme.merge(headerTheme),
imageSlideTheme: this.imageSlideTheme.merge(imageSlideTheme),
slideTheme: this.slideTheme.merge(slideTheme),
speakerInfoWidgetTheme:
this.speakerInfoWidgetTheme.merge(speakerInfoWidgetTheme),
Expand All @@ -192,6 +201,7 @@ class FlutterDeckThemeData {
codeHighlightTheme: codeHighlightTheme.merge(other.codeHighlightTheme),
footerTheme: footerTheme.merge(other.footerTheme),
headerTheme: headerTheme.merge(other.headerTheme),
imageSlideTheme: imageSlideTheme.merge(other.imageSlideTheme),
slideTheme: slideTheme.merge(other.slideTheme),
speakerInfoWidgetTheme:
speakerInfoWidgetTheme.merge(other.speakerInfoWidgetTheme),
Expand Down
87 changes: 87 additions & 0 deletions lib/src/theme/templates/flutter_deck_image_slide_theme.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import 'package:flutter/widgets.dart';
import 'package:flutter_deck/src/templates/image_slide.dart';
import 'package:flutter_deck/src/theme/flutter_deck_theme.dart';

/// Defines the visual properties of [FlutterDeckImageSlide].
///
/// Used by [FlutterDeckImageSlideTheme] to control the visual properties of
/// slides in a deck.
///
/// To obtain the current [FlutterDeckImageSlideThemeData], use
/// [FlutterDeckImageSlideTheme.of] to access the closest ancestor
/// [FlutterDeckImageSlideTheme] of the current [BuildContext].
///
/// See also:
///
/// * [FlutterDeckImageSlideTheme], an [InheritedWidget] that propagates the
/// theme down its subtree.
/// * [FlutterDeckTheme], which describes the overall theme information for the
/// slide deck.
class FlutterDeckImageSlideThemeData {
/// Creates a theme to style [FlutterDeckImageSlide].
const FlutterDeckImageSlideThemeData({
this.labelTextStyle,
});

/// Text style for the image label.
final TextStyle? labelTextStyle;

/// Creates a copy of this object with the given fields replaced with the new
/// values.
FlutterDeckImageSlideThemeData copyWith({
TextStyle? labelTextStyle,
}) {
return FlutterDeckImageSlideThemeData(
labelTextStyle: labelTextStyle ?? this.labelTextStyle,
);
}

/// Merge the given [FlutterDeckImageSlideThemeData] with this one.
FlutterDeckImageSlideThemeData merge(FlutterDeckImageSlideThemeData? other) {
if (other == null) return this;

return copyWith(
labelTextStyle:
labelTextStyle?.merge(other.labelTextStyle) ?? other.labelTextStyle,
);
}
}

/// An inherited widget that defines the visual properties of
/// [FlutterDeckImageSlide].
///
/// Used by [FlutterDeckImageSlide] to control the visual properties of slides
/// in the slide deck.
class FlutterDeckImageSlideTheme extends InheritedTheme {
/// Creates a theme to style [FlutterDeckImageSlide].
///
/// The [data] argument must not be null.
const FlutterDeckImageSlideTheme({
required this.data,
required super.child,
super.key,
});

/// The visual properties of [FlutterDeckImageSlide].
final FlutterDeckImageSlideThemeData data;

/// Returns the [data] from the closest [FlutterDeckImageSlideTheme] ancestor.
/// If there is no ancestor, it returns
/// [FlutterDeckThemeData.imageSlideTheme].
///
/// The returned theme data will never be null.
static FlutterDeckImageSlideThemeData of(BuildContext context) {
final theme = context
.dependOnInheritedWidgetOfExactType<FlutterDeckImageSlideTheme>();

return theme?.data ?? FlutterDeckTheme.of(context).imageSlideTheme;
}

@override
bool updateShouldNotify(FlutterDeckImageSlideTheme oldWidget) =>
data != oldWidget.data;

@override
Widget wrap(BuildContext context, Widget child) =>
FlutterDeckImageSlideTheme(data: data, child: child);
}
1 change: 1 addition & 0 deletions lib/src/theme/templates/templates.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export 'flutter_deck_image_slide_theme.dart';
export 'flutter_deck_slide_theme.dart';
export 'flutter_deck_split_slide_theme.dart';
export 'flutter_deck_title_slide_theme.dart';

0 comments on commit 918e886

Please sign in to comment.