Skip to content

Commit

Permalink
Introduce passing a initial stage data without a controller
Browse files Browse the repository at this point in the history
  • Loading branch information
robiness committed Jul 19, 2023
1 parent e1853ab commit 0d56b6b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 14 deletions.
12 changes: 5 additions & 7 deletions example/test/widget_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,24 @@ import 'package:stage_craft/stage_craft.dart';

void main() {
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
final StageController controller = StageController();
await tester.pumpWidgetData(controller);
controller.selectWidget(MyOtherWidgetStageData());
await tester.pumpAndSettle();
expect(find.text('MyOtherWidget'), findsOneWidget);
await tester.pumpWidgetData(MyOtherWidgetStageData());
expect(find.text('MyOtherWidget'), findsNWidgets(2));
});
}

extension WidgetTesterExtension on WidgetTester {
Future<void> pumpWidgetData(
StageController controller,
WidgetStageData stageData,
) async {
await pumpWidget(
MaterialApp(
home: Scaffold(
body: StageCraft(
stageController: controller,
stageData: stageData,
),
),
),
);
await pumpAndSettle();
}
}
33 changes: 26 additions & 7 deletions lib/src/widgets/stage_craft.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ import 'package:stage_craft/src/widgets/stage_area.dart';
///
/// Use this to create a stage for your widgets.
///
class StageCraft extends StatelessWidget {
class StageCraft extends StatefulWidget {
StageCraft({
super.key,
required this.stageController,
this.stageController,
this.configurationBarFooter,
Size? stageSize,
StageCraftSettings? settings,
this.stageData,
}) : stageSize = stageSize ?? const Size(600, 800),
settings = settings ??
StageCraftSettings(
Expand All @@ -25,7 +26,7 @@ class StageCraft extends StatelessWidget {
/// The [StageController] that controls the stage.
///
/// Create one above the [StageCraft] widget and pass it here to react to stage events or set stage properties.
final StageController stageController;
final StageController? stageController;

/// The size of the stage.
final Size stageSize;
Expand All @@ -36,19 +37,37 @@ class StageCraft extends StatelessWidget {
/// An optional footer of the configuration bar.
final Widget? configurationBarFooter;

/// The initially selected stage data.
final WidgetStageData? stageData;

@override
State<StageCraft> createState() => _StageCraftState();
}

class _StageCraftState extends State<StageCraft> {
late final _stageController = widget.stageController ?? StageController();

@override
void initState() {
super.initState();
if (widget.stageData != null) {
_stageController.selectWidget(widget.stageData!);
}
}

@override
Widget build(BuildContext context) {
return Row(
children: [
StageArea(
stageController: stageController,
settings: settings,
stageController: _stageController,
settings: widget.settings,
),
Align(
alignment: Alignment.topCenter,
child: ConfigurationBar(
controller: stageController,
configurationBarFooter: configurationBarFooter,
controller: _stageController,
configurationBarFooter: widget.configurationBarFooter,
),
),
],
Expand Down

0 comments on commit 0d56b6b

Please sign in to comment.