@@ -72,6 +72,36 @@ void main() {
7272 expect (command.stringArgDeprecated ('key' ), 'value' );
7373 expect (() => command.stringArgDeprecated ('empty' ), throwsA (const TypeMatcher <ArgumentError >()));
7474 });
75+
76+ testUsingContext ('List<String> safe argResults' , () async {
77+ final DummyFlutterCommand command = DummyFlutterCommand (
78+ commandFunction: () async {
79+ return const FlutterCommandResult (ExitStatus .success);
80+ }
81+ );
82+ final FlutterCommandRunner runner = FlutterCommandRunner (verboseHelp: true );
83+ command.argParser.addMultiOption (
84+ 'key' ,
85+ allowed: < String > ['a' , 'b' , 'c' ],
86+ );
87+ // argResults will be null at this point, if attempt to read them is made,
88+ // exception `Null check operator used on a null value` would be thrown.
89+ expect (() => command.stringsArg ('key' ), throwsA (const TypeMatcher <TypeError >()));
90+
91+ runner.addCommand (command);
92+ await runner.run (< String > ['dummy' , '--key' , 'a' ]);
93+
94+ // throws error when trying to parse non-existent key.
95+ expect (() => command.stringsArg ('empty' ),throwsA (const TypeMatcher <ArgumentError >()));
96+
97+ expect (command.stringsArg ('key' ), < String > ['a' ]);
98+
99+ await runner.run (< String > ['dummy' , '--key' , 'a' , '--key' , 'b' ]);
100+ expect (command.stringsArg ('key' ), < String > ['a' , 'b' ]);
101+
102+ await runner.run (< String > ['dummy' ]);
103+ expect (command.stringsArg ('key' ), < String > []);
104+ });
75105}
76106
77107void verifyCommandRunner (CommandRunner <Object > runner) {
0 commit comments