Skip to content

Commit ffa42d1

Browse files
refactor: Add Stac Theme and ThemeData classes to stac_core (#379)
* refactor: Move theme classes to Stac_core * refactor: Update theme parsers and add missing docs. * chore: Remove FVM configuration files * refactor: Update StacTabBarThemeData parser to use TabBarThemeData and include in StacThemeParser * chore: Remove .fvmrc file from stac_core package * refactor: Change return type of parse method in StacAppBarThemeParser to non-nullable AppBarTheme * refactor: Update theme parsers to return non-nullable types and improve documentation * refactor: Remove unused StacRoundedRectangleBorder class and related files * code formatting * refactor: Clean up JSON serialization in widget classes for consistency - Updated various widget classes to ensure consistent formatting in JSON serialization. - Simplified null checks and improved readability across multiple files, including StacButton, StacCard, StacColumn, and others. - Enhanced maintainability by standardizing the structure of child widget handling and property parsing.
1 parent a4d7e02 commit ffa42d1

File tree

212 files changed

+5854
-23902
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

212 files changed

+5854
-23902
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,6 @@ mason-lock.json
4141

4242
# Cursor Files
4343
.cursor/
44+
45+
# FVM Version Cache
46+
.fvm/

examples/movie_app/pubspec.lock

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -171,14 +171,6 @@ packages:
171171
description: flutter
172172
source: sdk
173173
version: "0.0.0"
174-
freezed_annotation:
175-
dependency: transitive
176-
description:
177-
name: freezed_annotation
178-
sha256: "7294967ff0a6d98638e7acb774aac3af2550777accd8149c90af5b014e6d44d8"
179-
url: "https://pub.dev"
180-
source: hosted
181-
version: "3.1.0"
182174
http:
183175
dependency: transitive
184176
description:

packages/stac/lib/src/framework/stac.dart

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,8 @@ import 'package:stac_core/actions/network_request/stac_network_request.dart';
1010
import 'package:stac_core/core/stac_options.dart';
1111
import 'package:stac_framework/stac_framework.dart';
1212

13-
typedef ErrorWidgetBuilder = Widget Function(
14-
BuildContext context,
15-
dynamic error,
16-
);
13+
typedef ErrorWidgetBuilder =
14+
Widget Function(BuildContext context, dynamic error);
1715

1816
typedef LoadingWidgetBuilder = Widget Function(BuildContext context);
1917

@@ -31,10 +29,8 @@ typedef LoadingWidgetBuilder = Widget Function(BuildContext context);
3129
/// },
3230
/// );
3331
/// ```
34-
typedef StacErrorWidgetBuilder = Widget Function(
35-
BuildContext context,
36-
StacError errorDetails,
37-
);
32+
typedef StacErrorWidgetBuilder =
33+
Widget Function(BuildContext context, StacError errorDetails);
3834

3935
class Stac extends StatelessWidget {
4036
const Stac({
@@ -79,10 +75,7 @@ class Stac extends StatelessWidget {
7975
);
8076
}
8177

82-
static Widget? fromJson(
83-
Map<String, dynamic>? json,
84-
BuildContext context,
85-
) {
78+
static Widget? fromJson(Map<String, dynamic>? json, BuildContext context) {
8679
return StacService.fromJson(json, context);
8780
}
8881

@@ -139,10 +132,7 @@ class _StacView extends StatelessWidget {
139132
}
140133

141134
return FutureBuilder<Response?>(
142-
future: StacCloud.fetchScreen(
143-
context: context,
144-
routeName: routeName,
145-
),
135+
future: StacCloud.fetchScreen(context: context, routeName: routeName),
146136
builder: (context, snapshot) {
147137
if (snapshot.connectionState == ConnectionState.waiting) {
148138
return loadingWidget ?? const _LoadingWidget();
@@ -166,10 +156,6 @@ class _LoadingWidget extends StatelessWidget {
166156

167157
@override
168158
Widget build(BuildContext context) {
169-
return Scaffold(
170-
body: const Center(
171-
child: CircularProgressIndicator(),
172-
),
173-
);
159+
return Scaffold(body: const Center(child: CircularProgressIndicator()));
174160
}
175161
}

packages/stac/lib/src/framework/stac_app.dart

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import 'package:flutter/material.dart';
2-
import 'package:stac/src/parsers/theme/stac_theme/stac_theme.dart';
2+
import 'package:stac/src/parsers/theme/themes.dart';
33

44
class StacApp extends StatelessWidget {
55
const StacApp({
@@ -41,11 +41,11 @@ class StacApp extends StatelessWidget {
4141
this.restorationScopeId,
4242
this.scrollBehavior,
4343
this.useInheritedMediaQuery = false,
44-
}) : routeInformationProvider = null,
45-
routeInformationParser = null,
46-
routerDelegate = null,
47-
backButtonDispatcher = null,
48-
routerConfig = null;
44+
}) : routeInformationProvider = null,
45+
routeInformationParser = null,
46+
routerDelegate = null,
47+
backButtonDispatcher = null,
48+
routerConfig = null;
4949

5050
const StacApp.router({
5151
super.key,
@@ -82,14 +82,14 @@ class StacApp extends StatelessWidget {
8282
this.restorationScopeId,
8383
this.scrollBehavior,
8484
this.useInheritedMediaQuery = false,
85-
}) : navigatorObservers = null,
86-
navigatorKey = null,
87-
onGenerateRoute = null,
88-
homeBuilder = null,
89-
onGenerateInitialRoutes = null,
90-
onUnknownRoute = null,
91-
routes = null,
92-
initialRoute = null;
85+
}) : navigatorObservers = null,
86+
navigatorKey = null,
87+
onGenerateRoute = null,
88+
homeBuilder = null,
89+
onGenerateInitialRoutes = null,
90+
onUnknownRoute = null,
91+
routes = null,
92+
initialRoute = null;
9393

9494
final GlobalKey<NavigatorState>? navigatorKey;
9595
final GlobalKey<ScaffoldMessengerState>? scaffoldMessengerKey;

packages/stac/lib/src/framework/stac_error.dart

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,7 @@ class StacError {
3535
/// The [error] parameter is required and should contain the actual
3636
/// error or exception that was thrown. All other parameters are optional
3737
/// but recommended for better error diagnostics.
38-
const StacError({
39-
this.type,
40-
required this.error,
41-
this.json,
42-
this.stackTrace,
43-
});
38+
const StacError({this.type, required this.error, this.json, this.stackTrace});
4439

4540
/// The type identifier of the failing Stac entity.
4641
///
@@ -117,10 +112,7 @@ class StacError {
117112
/// )
118113
/// ```
119114
class StacErrorWidget extends StatefulWidget {
120-
const StacErrorWidget({
121-
super.key,
122-
required this.errorDetails,
123-
});
115+
const StacErrorWidget({super.key, required this.errorDetails});
124116

125117
final StacError errorDetails;
126118

@@ -212,16 +204,16 @@ class _StacErrorWidgetState extends State<StacErrorWidget> {
212204
child: Row(
213205
crossAxisAlignment: CrossAxisAlignment.start,
214206
children: [
215-
const Icon(Icons.warning_amber,
216-
color: _warningOrange, size: 16),
207+
const Icon(
208+
Icons.warning_amber,
209+
color: _warningOrange,
210+
size: 16,
211+
),
217212
const SizedBox(width: 8),
218213
Expanded(
219214
child: Text(
220215
widget.errorDetails.error.toString(),
221-
style: const TextStyle(
222-
color: _errorRed,
223-
fontSize: 13,
224-
),
216+
style: const TextStyle(color: _errorRed, fontSize: 13),
225217
),
226218
),
227219
],
@@ -239,9 +231,7 @@ class _StacErrorWidgetState extends State<StacErrorWidget> {
239231
_buildExpandableSection(
240232
title: 'JSON Data',
241233
section: _ExpandableSection.json,
242-
child: _buildCodeBlock(
243-
_formatJson(widget.errorDetails.json!),
244-
),
234+
child: _buildCodeBlock(_formatJson(widget.errorDetails.json!)),
245235
),
246236
const SizedBox(height: 8),
247237
],
@@ -391,18 +381,16 @@ class _StacErrorWidgetState extends State<StacErrorWidget> {
391381
),
392382
),
393383
),
394-
if (isExpanded) ...[
395-
const SizedBox(height: 4),
396-
child,
397-
],
384+
if (isExpanded) ...[const SizedBox(height: 4), child],
398385
],
399386
);
400387
}
401388

402389
String _getTroubleshootingTips() {
403390
final errorStr = widget.errorDetails.error.toString().toLowerCase();
404-
final errorType =
405-
widget.errorDetails.error.runtimeType.toString().toLowerCase();
391+
final errorType = widget.errorDetails.error.runtimeType
392+
.toString()
393+
.toLowerCase();
406394

407395
// Check for unregistered widget/action types
408396
if (errorStr.contains('type') && errorStr.contains('not found')) {

packages/stac/lib/src/framework/stac_registry.dart

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -50,24 +50,22 @@ class StacRegistry {
5050
}
5151
}
5252

53-
Future<dynamic> registerAll(List<StacParser> parsers,
54-
[bool override = false]) {
55-
return Future.forEach(
56-
parsers,
57-
(StacParser parser) {
58-
return register(parser, override);
59-
},
60-
);
53+
Future<dynamic> registerAll(
54+
List<StacParser> parsers, [
55+
bool override = false,
56+
]) {
57+
return Future.forEach(parsers, (StacParser parser) {
58+
return register(parser, override);
59+
});
6160
}
6261

63-
Future<dynamic> registerAllActions(List<StacActionParser> parsers,
64-
[bool override = false]) {
65-
return Future.forEach(
66-
parsers,
67-
(StacActionParser parser) {
68-
return registerAction(parser, override);
69-
},
70-
);
62+
Future<dynamic> registerAllActions(
63+
List<StacActionParser> parsers, [
64+
bool override = false,
65+
]) {
66+
return Future.forEach(parsers, (StacActionParser parser) {
67+
return registerAction(parser, override);
68+
});
7169
}
7270

7371
StacParser<dynamic>? getParser(String type) {

packages/stac/lib/src/framework/stac_service.dart

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,7 @@ class StacService {
173173
_errorWidgetBuilder = errorWidgetBuilder;
174174
}
175175

176-
static Widget? fromJson(
177-
Map<String, dynamic>? json,
178-
BuildContext context,
179-
) {
176+
static Widget? fromJson(Map<String, dynamic>? json, BuildContext context) {
180177
try {
181178
if (json == null) {
182179
return null;
@@ -318,8 +315,9 @@ class StacService {
318315
throw TypeError();
319316
}
320317

321-
final stacActionParser =
322-
StacRegistry.instance.getActionParser(actionType);
318+
final stacActionParser = StacRegistry.instance.getActionParser(
319+
actionType,
320+
);
323321

324322
if (stacActionParser == null) {
325323
Log.w('Action type [$actionType] not supported');

packages/stac/lib/src/parsers/actions/stac_dialog_action/stac_dialog_action_parser.dart

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,7 @@ class StacDialogActionParser extends StacActionParser<StacDialogAction> {
2626
Stac.fromJson(model.widget, context) ?? const SizedBox(),
2727
);
2828
} else if (model.assetPath?.isNotEmpty ?? false) {
29-
return _showDialog(
30-
context,
31-
model,
32-
Stac.fromAssets(model.assetPath!),
33-
);
29+
return _showDialog(context, model, Stac.fromAssets(model.assetPath!));
3430
} else if (model.request != null) {
3531
return _showDialog(
3632
context,

packages/stac/lib/src/parsers/actions/stac_navigate_action/stac_navigate_action_parser.dart

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,7 @@ class StacNavigateActionParser extends StacActionParser<StacNavigateAction> {
8181
break;
8282

8383
case NavigationStyle.pushNamed:
84-
return Navigator.pushNamed(
85-
context,
86-
routeName!,
87-
arguments: arguments,
88-
);
84+
return Navigator.pushNamed(context, routeName!, arguments: arguments);
8985

9086
case NavigationStyle.pushNamedAndRemoveAll:
9187
return Navigator.pushNamedAndRemoveUntil(

packages/stac/lib/src/parsers/actions/stac_snack_bar/stac_snack_bar_parser.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ class StacSnackBarParser extends StacActionParser<StacSnackBar> {
5353
}
5454

5555
SnackBarAction? _parseAction(
56-
BuildContext context, StacSnackBarAction? action) {
56+
BuildContext context,
57+
StacSnackBarAction? action,
58+
) {
5759
if (action == null) return null;
5860
return SnackBarAction(
5961
textColor: action.textColor?.toColor(context),

0 commit comments

Comments
 (0)