From d7cdbca0237cffc4b60d9a3f24b9d739ee813c9f Mon Sep 17 00:00:00 2001 From: Khushal Rao Date: Fri, 19 Sep 2025 18:11:40 +0530 Subject: [PATCH 1/9] fix: updated scenario generator to process lines of data table without curly braces --- lib/src/scenario_generator.dart | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/lib/src/scenario_generator.dart b/lib/src/scenario_generator.dart index 75f5fd2..7260fd5 100644 --- a/lib/src/scenario_generator.dart +++ b/lib/src/scenario_generator.dart @@ -118,17 +118,16 @@ Iterable _processScenarioLines( ); for (final line in lines.skip(1)) { - yield BddLine.fromValue( - line.type, - _replacePlaceholders(line.value, examples), - ); + yield _replacePlaceholdersInLine(line, examples); } } -String _replacePlaceholders(String line, Map example) { - var replaced = line; +BddLine _replacePlaceholdersInLine(BddLine line, Map example) { + var replaced = line.value; + final isDataTable = line.type == LineType.dataTableStep; for (final e in example.keys) { - replaced = replaced.replaceAll('<$e>', '{${example[e]}}'); + final replaceWith = isDataTable ? '${example[e]}' : '{${example[e]}}'; + replaced = replaced.replaceAll('<$e>', replaceWith); } - return replaced; + return BddLine.fromValue(line.type, replaced); } From 5a4322ac53545dbb893dc0777aacada1b592b1f7 Mon Sep 17 00:00:00 2001 From: Khushal Rao Date: Fri, 19 Sep 2025 18:12:23 +0530 Subject: [PATCH 2/9] feat: updated example app --- example/lib/main.dart | 45 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 38 insertions(+), 7 deletions(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index a107c64..25f157b 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -27,16 +27,33 @@ class MyHomePage extends StatefulWidget { class _MyHomePageState extends State { int _counter = 0; + Color? _color = Colors.blue; void _incrementCounter() { - setState(() { - _counter++; - }); + _counter++; + _changeColor(_counter); + } + + void _decrementCounter() { + _counter--; + _changeColor(_counter); + } + + void _changeColor(int counter) { + if (counter < 12) { + _color = Colors.blue; + } else if (counter < 24) { + _color = Colors.green; + } else if (counter < 35) { + _color = Colors.yellow; + } + setState(() {}); } @override Widget build(BuildContext context) { return Scaffold( + backgroundColor: _color, appBar: AppBar(title: Text(widget.title)), body: Center( child: Column( @@ -52,10 +69,24 @@ class _MyHomePageState extends State { ], ), ), - floatingActionButton: FloatingActionButton( - onPressed: _incrementCounter, - tooltip: 'Increment', - child: const Icon(Icons.add), + floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked, + floatingActionButton: Padding( + padding: const EdgeInsets.all(8), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + FloatingActionButton( + onPressed: _decrementCounter, + tooltip: 'Decrement', + child: const Icon(Icons.remove), + ), + FloatingActionButton( + onPressed: _incrementCounter, + tooltip: 'Increment', + child: const Icon(Icons.add), + ), + ], + ), ), ); } From b0f76748c78eae020ff6d8cd93c5caca6a197870 Mon Sep 17 00:00:00 2001 From: Khushal Rao Date: Fri, 19 Sep 2025 18:12:35 +0530 Subject: [PATCH 3/9] test: added example tests --- example/test/sample.feature | 14 ++++++++ example/test/sample_test.dart | 56 +++++++++++++++++++++++++++++ example/test/step/i_see_result.dart | 28 +++++++++++++++ 3 files changed, 98 insertions(+) create mode 100644 example/test/step/i_see_result.dart diff --git a/example/test/sample.feature b/example/test/sample.feature index 5783995..fb13d07 100644 --- a/example/test/sample.feature +++ b/example/test/sample.feature @@ -27,6 +27,20 @@ Feature: Counter | 1 | '1' | | 42 | '42' | + Scenario Outline: Add and remove buttons work together + Given the app is running + When I tap {Icons.add} icon times + And I tap {Icons.remove} icon times + Then I see result + | 'counter' | 'color' | + | | | + Examples: + | addTimes | removeTimes | counter | color | + | 20 | 15 | '5' | 'blue' | + | 25 | 10 | '15' | 'green' | + | 40 | 10 | '30' | 'yellow' | + + # Scenario: Built-in steps # And I don't see {Icons.add} icon # And I don't see {'text'} rich text diff --git a/example/test/sample_test.dart b/example/test/sample_test.dart index 4aca3af..7c4fbd8 100644 --- a/example/test/sample_test.dart +++ b/example/test/sample_test.dart @@ -1,6 +1,7 @@ // GENERATED CODE - DO NOT MODIFY BY HAND // ignore_for_file: type=lint, type=warning +import 'package:bdd_widget_test/data_table.dart' as bdd; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -9,6 +10,7 @@ import './step/i_do_not_see_text.dart'; import './step/i_see_text.dart'; import './step/i_tap_icon.dart'; import './step/i_tap_icon_times.dart'; +import './step/i_see_result.dart'; void main() { group('''Counter''', () { @@ -70,5 +72,59 @@ void main() { await bddTearDown(tester); } }); + testWidgets( + '''Outline: Add and remove buttons work together (20, 15, '5', 'blue')''', + (tester) async { + try { + await bddSetUp(tester); + await theAppIsRunning(tester); + await iTapIconTimes(tester, Icons.add, 20); + await iTapIconTimes(tester, Icons.remove, 15); + await iSeeResult( + tester, + const bdd.DataTable([ + ['counter', 'color'], + ['5', 'blue'] + ])); + } finally { + await bddTearDown(tester); + } + }); + testWidgets( + '''Outline: Add and remove buttons work together (25, 10, '15', 'green')''', + (tester) async { + try { + await bddSetUp(tester); + await theAppIsRunning(tester); + await iTapIconTimes(tester, Icons.add, 25); + await iTapIconTimes(tester, Icons.remove, 10); + await iSeeResult( + tester, + const bdd.DataTable([ + ['counter', 'color'], + ['15', 'green'] + ])); + } finally { + await bddTearDown(tester); + } + }); + testWidgets( + '''Outline: Add and remove buttons work together (40, 10, '30', 'yellow')''', + (tester) async { + try { + await bddSetUp(tester); + await theAppIsRunning(tester); + await iTapIconTimes(tester, Icons.add, 40); + await iTapIconTimes(tester, Icons.remove, 10); + await iSeeResult( + tester, + const bdd.DataTable([ + ['counter', 'color'], + ['30', 'yellow'] + ])); + } finally { + await bddTearDown(tester); + } + }); }); } diff --git a/example/test/step/i_see_result.dart b/example/test/step/i_see_result.dart new file mode 100644 index 0000000..3dbd518 --- /dev/null +++ b/example/test/step/i_see_result.dart @@ -0,0 +1,28 @@ +import 'package:bdd_widget_test/data_table.dart' as bdd; +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; + +/// Usage: I see result +Future iSeeResult(WidgetTester tester, bdd.DataTable dataTable) async { + final counter = dataTable.asMaps().first['counter'] as String; + final color = _colorFromName(dataTable.asMaps().first['color'] as String); + + expect(find.text(counter), findsOneWidget); + expect( + (tester.firstWidget(find.byType(Scaffold)) as Scaffold).backgroundColor, + color, + ); +} + +Color _colorFromName(String colorName) { + switch (colorName) { + case 'blue': + return Colors.blue; + case 'green': + return Colors.green; + case 'yellow': + return Colors.yellow; + default: + throw UnimplementedError('Unknown color: $colorName'); + } +} From d7560210ba93f5fecd66113ecca5c2f98e2b90a2 Mon Sep 17 00:00:00 2001 From: Khushal Rao Date: Fri, 19 Sep 2025 18:31:29 +0530 Subject: [PATCH 4/9] test: Added auto generated code test --- test/data_tables_test.dart | 51 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/test/data_tables_test.dart b/test/data_tables_test.dart index 5bc7926..da54746 100644 --- a/test/data_tables_test.dart +++ b/test/data_tables_test.dart @@ -485,4 +485,55 @@ Future theFollowingSongs(WidgetTester tester, String param1, bdd.DataTable expectedStep, ); }); + + test('Scenario Outline with data table variables', () { + const featureFile = ''' +Feature: Testing feature + Scenario Outline: Add and remove buttons work together + Given the app is running + When I tap add icon times + Then I see result + | 'counter' | 'color' | + | | | + Examples: + | times | counter | color | + | 20 | '20' | 'blue' | + | 25 | '25' | 'green' | +'''; + + const expectedFeatureDart = ''' +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: type=lint, type=warning + +import 'package:bdd_widget_test/data_table.dart' as bdd; +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; + +import './step/the_app_is_running.dart'; +import './step/i_tap_add_icon_times.dart'; +import './step/i_see_result.dart'; + +void main() { + group(\'\'\'Testing feature\'\'\', () { + testWidgets(\'\'\'Outline: Add and remove buttons work together (20, '20', 'blue')\'\'\', (tester) async { + await theAppIsRunning(tester); + await iTapAddIconTimes(tester, 20); + await iSeeResult(tester, const bdd.DataTable([['counter', 'color'], ['20', 'blue']])); + }); + testWidgets(\'\'\'Outline: Add and remove buttons work together (25, '25', 'green')\'\'\', (tester) async { + await theAppIsRunning(tester); + await iTapAddIconTimes(tester, 25); + await iSeeResult(tester, const bdd.DataTable([['counter', 'color'], ['25', 'green']])); + }); + }); +} +'''; + + final feature = FeatureFile( + featureDir: 'test.feature', + package: 'test', + input: featureFile, + ); + expect(feature.dartContent, expectedFeatureDart); + }); } From 6d72c20c65307aa23866100733f33acaecfee95c Mon Sep 17 00:00:00 2001 From: Khushal Rao Date: Fri, 19 Sep 2025 18:37:17 +0530 Subject: [PATCH 5/9] refactor: Example and its tests --- example/lib/main.dart | 29 +++++------------------------ example/test/sample.feature | 13 ++++++------- example/test/sample_test.dart | 15 ++++++--------- 3 files changed, 17 insertions(+), 40 deletions(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index 25f157b..433f4ab 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -27,18 +27,13 @@ class MyHomePage extends StatefulWidget { class _MyHomePageState extends State { int _counter = 0; - Color? _color = Colors.blue; + Color _color = Colors.blue; void _incrementCounter() { _counter++; _changeColor(_counter); } - void _decrementCounter() { - _counter--; - _changeColor(_counter); - } - void _changeColor(int counter) { if (counter < 12) { _color = Colors.blue; @@ -69,24 +64,10 @@ class _MyHomePageState extends State { ], ), ), - floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked, - floatingActionButton: Padding( - padding: const EdgeInsets.all(8), - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - FloatingActionButton( - onPressed: _decrementCounter, - tooltip: 'Decrement', - child: const Icon(Icons.remove), - ), - FloatingActionButton( - onPressed: _incrementCounter, - tooltip: 'Increment', - child: const Icon(Icons.add), - ), - ], - ), + floatingActionButton: FloatingActionButton( + onPressed: _incrementCounter, + tooltip: 'Increment', + child: const Icon(Icons.add), ), ); } diff --git a/example/test/sample.feature b/example/test/sample.feature index fb13d07..d03cfff 100644 --- a/example/test/sample.feature +++ b/example/test/sample.feature @@ -30,15 +30,14 @@ Feature: Counter Scenario Outline: Add and remove buttons work together Given the app is running When I tap {Icons.add} icon times - And I tap {Icons.remove} icon times Then I see result - | 'counter' | 'color' | - | | | + | 'counter' | 'color' | + | | | Examples: - | addTimes | removeTimes | counter | color | - | 20 | 15 | '5' | 'blue' | - | 25 | 10 | '15' | 'green' | - | 40 | 10 | '30' | 'yellow' | + | addTimes | counter | color | + | 5 | '5' | 'blue' | + | 15 | '15' | 'green' | + | 30 | '30' | 'yellow' | # Scenario: Built-in steps diff --git a/example/test/sample_test.dart b/example/test/sample_test.dart index 7c4fbd8..4d1ed42 100644 --- a/example/test/sample_test.dart +++ b/example/test/sample_test.dart @@ -73,13 +73,12 @@ void main() { } }); testWidgets( - '''Outline: Add and remove buttons work together (20, 15, '5', 'blue')''', + '''Outline: Add and remove buttons work together (5, '5', 'blue')''', (tester) async { try { await bddSetUp(tester); await theAppIsRunning(tester); - await iTapIconTimes(tester, Icons.add, 20); - await iTapIconTimes(tester, Icons.remove, 15); + await iTapIconTimes(tester, Icons.add, 5); await iSeeResult( tester, const bdd.DataTable([ @@ -91,13 +90,12 @@ void main() { } }); testWidgets( - '''Outline: Add and remove buttons work together (25, 10, '15', 'green')''', + '''Outline: Add and remove buttons work together (15, '15', 'green')''', (tester) async { try { await bddSetUp(tester); await theAppIsRunning(tester); - await iTapIconTimes(tester, Icons.add, 25); - await iTapIconTimes(tester, Icons.remove, 10); + await iTapIconTimes(tester, Icons.add, 15); await iSeeResult( tester, const bdd.DataTable([ @@ -109,13 +107,12 @@ void main() { } }); testWidgets( - '''Outline: Add and remove buttons work together (40, 10, '30', 'yellow')''', + '''Outline: Add and remove buttons work together (30, '30', 'yellow')''', (tester) async { try { await bddSetUp(tester); await theAppIsRunning(tester); - await iTapIconTimes(tester, Icons.add, 40); - await iTapIconTimes(tester, Icons.remove, 10); + await iTapIconTimes(tester, Icons.add, 30); await iSeeResult( tester, const bdd.DataTable([ From 022a727521987e834783b80286887a7e6e593191 Mon Sep 17 00:00:00 2001 From: Khushal Rao Date: Mon, 22 Sep 2025 11:27:25 +0530 Subject: [PATCH 6/9] Revert "refactor: Example and its tests" This reverts commit 6d72c20c65307aa23866100733f33acaecfee95c. --- example/lib/main.dart | 29 ++++++++++++++++++++++++----- example/test/sample.feature | 13 +++++++------ example/test/sample_test.dart | 15 +++++++++------ 3 files changed, 40 insertions(+), 17 deletions(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index 433f4ab..25f157b 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -27,13 +27,18 @@ class MyHomePage extends StatefulWidget { class _MyHomePageState extends State { int _counter = 0; - Color _color = Colors.blue; + Color? _color = Colors.blue; void _incrementCounter() { _counter++; _changeColor(_counter); } + void _decrementCounter() { + _counter--; + _changeColor(_counter); + } + void _changeColor(int counter) { if (counter < 12) { _color = Colors.blue; @@ -64,10 +69,24 @@ class _MyHomePageState extends State { ], ), ), - floatingActionButton: FloatingActionButton( - onPressed: _incrementCounter, - tooltip: 'Increment', - child: const Icon(Icons.add), + floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked, + floatingActionButton: Padding( + padding: const EdgeInsets.all(8), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + FloatingActionButton( + onPressed: _decrementCounter, + tooltip: 'Decrement', + child: const Icon(Icons.remove), + ), + FloatingActionButton( + onPressed: _incrementCounter, + tooltip: 'Increment', + child: const Icon(Icons.add), + ), + ], + ), ), ); } diff --git a/example/test/sample.feature b/example/test/sample.feature index d03cfff..fb13d07 100644 --- a/example/test/sample.feature +++ b/example/test/sample.feature @@ -30,14 +30,15 @@ Feature: Counter Scenario Outline: Add and remove buttons work together Given the app is running When I tap {Icons.add} icon times + And I tap {Icons.remove} icon times Then I see result - | 'counter' | 'color' | - | | | + | 'counter' | 'color' | + | | | Examples: - | addTimes | counter | color | - | 5 | '5' | 'blue' | - | 15 | '15' | 'green' | - | 30 | '30' | 'yellow' | + | addTimes | removeTimes | counter | color | + | 20 | 15 | '5' | 'blue' | + | 25 | 10 | '15' | 'green' | + | 40 | 10 | '30' | 'yellow' | # Scenario: Built-in steps diff --git a/example/test/sample_test.dart b/example/test/sample_test.dart index 4d1ed42..7c4fbd8 100644 --- a/example/test/sample_test.dart +++ b/example/test/sample_test.dart @@ -73,12 +73,13 @@ void main() { } }); testWidgets( - '''Outline: Add and remove buttons work together (5, '5', 'blue')''', + '''Outline: Add and remove buttons work together (20, 15, '5', 'blue')''', (tester) async { try { await bddSetUp(tester); await theAppIsRunning(tester); - await iTapIconTimes(tester, Icons.add, 5); + await iTapIconTimes(tester, Icons.add, 20); + await iTapIconTimes(tester, Icons.remove, 15); await iSeeResult( tester, const bdd.DataTable([ @@ -90,12 +91,13 @@ void main() { } }); testWidgets( - '''Outline: Add and remove buttons work together (15, '15', 'green')''', + '''Outline: Add and remove buttons work together (25, 10, '15', 'green')''', (tester) async { try { await bddSetUp(tester); await theAppIsRunning(tester); - await iTapIconTimes(tester, Icons.add, 15); + await iTapIconTimes(tester, Icons.add, 25); + await iTapIconTimes(tester, Icons.remove, 10); await iSeeResult( tester, const bdd.DataTable([ @@ -107,12 +109,13 @@ void main() { } }); testWidgets( - '''Outline: Add and remove buttons work together (30, '30', 'yellow')''', + '''Outline: Add and remove buttons work together (40, 10, '30', 'yellow')''', (tester) async { try { await bddSetUp(tester); await theAppIsRunning(tester); - await iTapIconTimes(tester, Icons.add, 30); + await iTapIconTimes(tester, Icons.add, 40); + await iTapIconTimes(tester, Icons.remove, 10); await iSeeResult( tester, const bdd.DataTable([ From 1b841ab94d9ece936a2a9d337042bb58aa2ed3f9 Mon Sep 17 00:00:00 2001 From: Khushal Rao Date: Mon, 22 Sep 2025 11:27:46 +0530 Subject: [PATCH 7/9] Revert "test: added example tests" This reverts commit b0f76748c78eae020ff6d8cd93c5caca6a197870. --- example/test/sample.feature | 14 -------- example/test/sample_test.dart | 56 ----------------------------- example/test/step/i_see_result.dart | 28 --------------- 3 files changed, 98 deletions(-) delete mode 100644 example/test/step/i_see_result.dart diff --git a/example/test/sample.feature b/example/test/sample.feature index fb13d07..5783995 100644 --- a/example/test/sample.feature +++ b/example/test/sample.feature @@ -27,20 +27,6 @@ Feature: Counter | 1 | '1' | | 42 | '42' | - Scenario Outline: Add and remove buttons work together - Given the app is running - When I tap {Icons.add} icon times - And I tap {Icons.remove} icon times - Then I see result - | 'counter' | 'color' | - | | | - Examples: - | addTimes | removeTimes | counter | color | - | 20 | 15 | '5' | 'blue' | - | 25 | 10 | '15' | 'green' | - | 40 | 10 | '30' | 'yellow' | - - # Scenario: Built-in steps # And I don't see {Icons.add} icon # And I don't see {'text'} rich text diff --git a/example/test/sample_test.dart b/example/test/sample_test.dart index 7c4fbd8..4aca3af 100644 --- a/example/test/sample_test.dart +++ b/example/test/sample_test.dart @@ -1,7 +1,6 @@ // GENERATED CODE - DO NOT MODIFY BY HAND // ignore_for_file: type=lint, type=warning -import 'package:bdd_widget_test/data_table.dart' as bdd; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -10,7 +9,6 @@ import './step/i_do_not_see_text.dart'; import './step/i_see_text.dart'; import './step/i_tap_icon.dart'; import './step/i_tap_icon_times.dart'; -import './step/i_see_result.dart'; void main() { group('''Counter''', () { @@ -72,59 +70,5 @@ void main() { await bddTearDown(tester); } }); - testWidgets( - '''Outline: Add and remove buttons work together (20, 15, '5', 'blue')''', - (tester) async { - try { - await bddSetUp(tester); - await theAppIsRunning(tester); - await iTapIconTimes(tester, Icons.add, 20); - await iTapIconTimes(tester, Icons.remove, 15); - await iSeeResult( - tester, - const bdd.DataTable([ - ['counter', 'color'], - ['5', 'blue'] - ])); - } finally { - await bddTearDown(tester); - } - }); - testWidgets( - '''Outline: Add and remove buttons work together (25, 10, '15', 'green')''', - (tester) async { - try { - await bddSetUp(tester); - await theAppIsRunning(tester); - await iTapIconTimes(tester, Icons.add, 25); - await iTapIconTimes(tester, Icons.remove, 10); - await iSeeResult( - tester, - const bdd.DataTable([ - ['counter', 'color'], - ['15', 'green'] - ])); - } finally { - await bddTearDown(tester); - } - }); - testWidgets( - '''Outline: Add and remove buttons work together (40, 10, '30', 'yellow')''', - (tester) async { - try { - await bddSetUp(tester); - await theAppIsRunning(tester); - await iTapIconTimes(tester, Icons.add, 40); - await iTapIconTimes(tester, Icons.remove, 10); - await iSeeResult( - tester, - const bdd.DataTable([ - ['counter', 'color'], - ['30', 'yellow'] - ])); - } finally { - await bddTearDown(tester); - } - }); }); } diff --git a/example/test/step/i_see_result.dart b/example/test/step/i_see_result.dart deleted file mode 100644 index 3dbd518..0000000 --- a/example/test/step/i_see_result.dart +++ /dev/null @@ -1,28 +0,0 @@ -import 'package:bdd_widget_test/data_table.dart' as bdd; -import 'package:flutter/material.dart'; -import 'package:flutter_test/flutter_test.dart'; - -/// Usage: I see result -Future iSeeResult(WidgetTester tester, bdd.DataTable dataTable) async { - final counter = dataTable.asMaps().first['counter'] as String; - final color = _colorFromName(dataTable.asMaps().first['color'] as String); - - expect(find.text(counter), findsOneWidget); - expect( - (tester.firstWidget(find.byType(Scaffold)) as Scaffold).backgroundColor, - color, - ); -} - -Color _colorFromName(String colorName) { - switch (colorName) { - case 'blue': - return Colors.blue; - case 'green': - return Colors.green; - case 'yellow': - return Colors.yellow; - default: - throw UnimplementedError('Unknown color: $colorName'); - } -} From e3f4f63759b24ffc3bb2936b1de36158cb1f32ac Mon Sep 17 00:00:00 2001 From: Khushal Rao Date: Mon, 22 Sep 2025 11:27:53 +0530 Subject: [PATCH 8/9] Revert "feat: updated example app" This reverts commit 5a4322ac53545dbb893dc0777aacada1b592b1f7. --- example/lib/main.dart | 45 +++++++------------------------------------ 1 file changed, 7 insertions(+), 38 deletions(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index 25f157b..a107c64 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -27,33 +27,16 @@ class MyHomePage extends StatefulWidget { class _MyHomePageState extends State { int _counter = 0; - Color? _color = Colors.blue; void _incrementCounter() { - _counter++; - _changeColor(_counter); - } - - void _decrementCounter() { - _counter--; - _changeColor(_counter); - } - - void _changeColor(int counter) { - if (counter < 12) { - _color = Colors.blue; - } else if (counter < 24) { - _color = Colors.green; - } else if (counter < 35) { - _color = Colors.yellow; - } - setState(() {}); + setState(() { + _counter++; + }); } @override Widget build(BuildContext context) { return Scaffold( - backgroundColor: _color, appBar: AppBar(title: Text(widget.title)), body: Center( child: Column( @@ -69,24 +52,10 @@ class _MyHomePageState extends State { ], ), ), - floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked, - floatingActionButton: Padding( - padding: const EdgeInsets.all(8), - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - FloatingActionButton( - onPressed: _decrementCounter, - tooltip: 'Decrement', - child: const Icon(Icons.remove), - ), - FloatingActionButton( - onPressed: _incrementCounter, - tooltip: 'Increment', - child: const Icon(Icons.add), - ), - ], - ), + floatingActionButton: FloatingActionButton( + onPressed: _incrementCounter, + tooltip: 'Increment', + child: const Icon(Icons.add), ), ); } From 60448ded118b72e740733e9e591b6e0da4feda79 Mon Sep 17 00:00:00 2001 From: Khushal Rao Date: Mon, 22 Sep 2025 11:54:00 +0530 Subject: [PATCH 9/9] refactor: scenario generator placeholder line processor --- lib/src/scenario_generator.dart | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/lib/src/scenario_generator.dart b/lib/src/scenario_generator.dart index 7260fd5..1af4a53 100644 --- a/lib/src/scenario_generator.dart +++ b/lib/src/scenario_generator.dart @@ -118,16 +118,20 @@ Iterable _processScenarioLines( ); for (final line in lines.skip(1)) { - yield _replacePlaceholdersInLine(line, examples); + yield BddLine.fromValue( + line.type, + _replacePlaceholders( + line.value, line.type == LineType.dataTableStep, examples), + ); } } -BddLine _replacePlaceholdersInLine(BddLine line, Map example) { - var replaced = line.value; - final isDataTable = line.type == LineType.dataTableStep; +String _replacePlaceholders( + String line, bool isDataTableStep, Map example) { + var replaced = line; for (final e in example.keys) { - final replaceWith = isDataTable ? '${example[e]}' : '{${example[e]}}'; - replaced = replaced.replaceAll('<$e>', replaceWith); + final value = isDataTableStep ? '${example[e]}' : '{${example[e]}}'; + replaced = replaced.replaceAll('<$e>', value); } - return BddLine.fromValue(line.type, replaced); + return replaced; }