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
26 changes: 26 additions & 0 deletions packages/stac/lib/src/framework/stac.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'dart:convert';

import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:stac/src/framework/stac_error.dart';
import 'package:stac/src/framework/stac_service.dart';
import 'package:stac/src/services/stac_cloud.dart';
import 'package:stac_core/actions/network_request/stac_network_request.dart';
Expand All @@ -16,6 +17,25 @@ typedef ErrorWidgetBuilder = Widget Function(

typedef LoadingWidgetBuilder = Widget Function(BuildContext context);

/// Global parse-error widget builder for Stac.
///
/// Allows apps to provide a custom widget when parsing a Stac widget/action
/// fails. The builder receives useful context like the widget/action type,
/// original JSON and stack trace (when available).
///
/// Example:
/// ```dart
/// Stac.initialize(
/// errorWidgetBuilder: (context, errorDetails) {
/// return Text('Error in ${errorDetails.type}: ${errorDetails.error}');
/// },
/// );
/// ```
typedef StacErrorWidgetBuilder = Widget Function(
BuildContext context,
StacError errorDetails,
);

class Stac extends StatelessWidget {
const Stac({
super.key,
Expand All @@ -34,13 +54,19 @@ class Stac extends StatelessWidget {
List<StacActionParser> actionParsers = const [],
Dio? dio,
bool override = false,
bool showErrorWidgets = true,
bool logStackTraces = true,
StacErrorWidgetBuilder? errorWidgetBuilder,
}) async {
return StacService.initialize(
options: options,
parsers: parsers,
actionParsers: actionParsers,
dio: dio,
override: override,
showErrorWidgets: showErrorWidgets,
logStackTraces: logStackTraces,
errorWidgetBuilder: errorWidgetBuilder,
);
}

Expand Down
Loading