Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
"widgets/row",
"widgets/safe_area",
"widgets/sized_box",
"widgets/sliver_padding",
"widgets/sliver_to_box_adapter",
"widgets/spacer",
"widgets/stack",
Expand Down
43 changes: 43 additions & 0 deletions docs/widgets/sliver_padding.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---
title: "SliverPadding"
description: "Documentation for SliverPadding"
---

The Stac SliverPadding allows you to inset a sliver widget by a given padding using JSON. It is typically used inside a `CustomScrollView`.
To know more about the sliver padding widget in Flutter, refer to
the [official documentation](https://api.flutter.dev/flutter/widgets/SliverPadding-class.html).

## Properties

| Property | Type | Description |
|----------|------------------------|--------------------------------------------------|
| padding | `Map<String, dynamic>` | The amount of space by which to inset the child. |
| sliver | `Map<String, dynamic>` | The sliver widget inside the padding. |

## Example JSON

```json
{
"type": "sliverPadding",
"padding": 16.0,
"sliver": {
"type": "sliverToBoxAdapter",
"child": {
"type": "container",
"height": 150,
"color": "#4CAF50",
"child": {
"type": "center",
"child": {
"type": "text",
"data": "I am a Box inside a SliverPadding!",
"style": {
"color": "#FFFFFF",
"fontWeight": "bold"
}
}
}
}
}
}
```
24 changes: 24 additions & 0 deletions examples/stac_gallery/assets/json/home_screen.json
Original file line number Diff line number Diff line change
Expand Up @@ -1236,6 +1236,30 @@
}
}
},
{
"type": "listTile",
"leading": {
"type": "icon",
"iconType": "cupertino",
"icon": "app_fill"
},
"title": {
"type": "text",
"data": "Stac Sliver Padding"
},
"subtitle": {
"type": "text",
"data": "A SliverPadding widget"
},
Comment thread
akhil-ge0rge marked this conversation as resolved.
"style": "list",
"onTap": {
"actionType": "navigate",
"widgetJson": {
"type": "exampleScreen",
"assetPath": "assets/json/sliver_padding_example.json"
}
}
},
{
"type": "listTile",
"leading": {
Expand Down
31 changes: 31 additions & 0 deletions examples/stac_gallery/assets/json/sliver_padding_example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"type": "scaffold",
"body": {
"type": "customScrollView",
"slivers": [
{
"type": "sliverPadding",
"padding": 16.0,
"sliver": {
"type": "sliverToBoxAdapter",
"child": {
"type": "container",
"height": 150,
"color": "#4CAF50",
"child": {
"type": "center",
"child": {
"type": "text",
"data": "I am a Box inside a SliverPadding!",
"style": {
"color": "#FFFFFF",
"fontWeight": "bold"
}
}
}
}
}
}
]
}
}
1 change: 1 addition & 0 deletions packages/stac/lib/src/framework/stac_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ class StacService {
const StacRadioGroupParser(),
const StacSliderParser(),
const StacSliverAppBarParser(),
const StacSliverPaddingParser(),
const StacSliverToBoxAdapterParser(),
const StacOpacityParser(),
const StacPlaceholderParser(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import 'package:flutter/material.dart';
import 'package:stac/src/parsers/core/stac_widget_parser.dart';

import 'package:stac/src/parsers/foundation/geometry/stac_edge_insets_parser.dart';
import 'package:stac_core/stac_core.dart';
import 'package:stac_framework/stac_framework.dart';

class StacSliverPaddingParser extends StacParser<StacSliverPadding> {
const StacSliverPaddingParser();

@override
String get type => WidgetType.sliverPadding.name;

@override
StacSliverPadding getModel(Map<String, dynamic> json) =>
StacSliverPadding.fromJson(json);

@override
Widget parse(BuildContext context, StacSliverPadding model) {
return SliverPadding(
padding: model.padding.parse,
sliver: model.sliver.parse(context),
);
}
}
1 change: 1 addition & 0 deletions packages/stac/lib/src/parsers/widgets/widgets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export 'package:stac/src/parsers/widgets/stac_single_child_scroll_view/stac_sing
export 'package:stac/src/parsers/widgets/stac_sized_box/stac_sized_box_parser.dart';
export 'package:stac/src/parsers/widgets/stac_slider/stac_slider_parser.dart';
export 'package:stac/src/parsers/widgets/stac_sliver_app_bar/stac_sliver_app_bar_parser.dart';
export 'package:stac/src/parsers/widgets/stac_sliver_padding/stac_sliver_padding_parser.dart';
export 'package:stac/src/parsers/widgets/stac_sliver_to_box_adapter/stac_sliver_to_box_adapter_parser.dart';
export 'package:stac/src/parsers/widgets/stac_spacer/stac_spacer_parser.dart';
export 'package:stac/src/parsers/widgets/stac_stack/stac_stack_parser.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,9 @@ enum WidgetType {
/// Sliver app bar widget
sliverAppBar,

/// Sliver padding widget
sliverPadding,

/// Sliver to box adapter widget
sliverToBoxAdapter,

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import 'package:json_annotation/json_annotation.dart';
import 'package:stac_core/core/stac_widget.dart';
import 'package:stac_core/foundation/foundation.dart';
part 'stac_sliver_padding.g.dart';

/// A Stac model representing Flutter's [SliverPadding] widget.
///
/// Insets its sliver child by the given padding.
///
/// {@tool snippet}
/// Dart Example:
/// ```dart
/// const StacSliverPadding(
/// padding: StacEdgeInsets.all(16),
/// sliver: StacSliverToBoxAdapter(...),
/// )
/// ```
/// {@end-tool}
///
/// {@tool snippet}
/// JSON Example:
/// ```json
/// {
/// "type": "sliverPadding",
/// "padding": 16.0,
/// "sliver": {
/// "type": "sliverToBoxAdapter",
/// "child": {
/// "type": "container",
/// "height": 150,
/// "color": "#4CAF50",
/// "child": {
/// "type": "center",
/// "child": {
/// "type": "text",
/// "data": "I am a Box inside a SliverPadding!",
/// "style": {
/// "color": "#FFFFFF",
/// "fontWeight": "bold"
/// }
/// }
/// }
/// }
/// }
/// }
/// ```
Comment thread
coderabbitai[bot] marked this conversation as resolved.
/// {@end-tool}
///
/// See also:
/// * Flutter's [SliverPadding documentation](https://api.flutter.dev/flutter/widgets/SliverPadding-class.html)
@JsonSerializable()
class StacSliverPadding extends StacWidget {
/// Creates a [StacSliverPadding].
const StacSliverPadding({required this.sliver, required this.padding});

/// The amount of space by which to inset the child sliver.
final StacEdgeInsets padding;

/// The sliver to apply padding to.
final StacWidget sliver;

/// Widget type identifier.
@override
String get type => WidgetType.sliverPadding.name;

/// Creates a [StacSliverPadding] from a JSON map.
factory StacSliverPadding.fromJson(Map<String, dynamic> json) =>
_$StacSliverPaddingFromJson(json);

/// Converts this [StacSliverPadding] instance to JSON.
@override
Map<String, dynamic> toJson() => _$StacSliverPaddingToJson(this);
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/stac_core/lib/widgets/widgets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export 'single_child_scroll_view/stac_single_child_scroll_view.dart';
export 'sized_box/stac_sized_box.dart';
export 'slider/stac_slider.dart';
export 'sliver_app_bar/stac_sliver_app_bar.dart';
export 'sliver_padding/stac_sliver_padding.dart';
export 'sliver_to_box_adapter/stac_sliver_to_box_adapter.dart';
export 'spacer/stac_spacer.dart';
export 'stack/stac_stack.dart';
Expand Down