@@ -22,21 +22,24 @@ Then run `pub get` to install the dependencies.
2222A simple example of using Commander to create an ask component :
2323
2424- ✅ Secure
25- - ✅ Validator with error message as callback
25+ - ✅ Integrated or custom validators
2626- ✅ Default value
2727
2828` ` ` dart
2929Future<void> main() async {
3030 final commander = Commander(level: Level.verbose);
3131
32+ final value = await commander.ask('What is your email ?',
33+ validate: (validator) => validator
34+ ..notEmpty(message: 'Name cannot be empty :)')
35+ ..email(message: 'Please enter a valid email'));
36+
37+ // Custom validator
3238 final value = await commander.ask('What is your name ?',
33- defaultValue: 'John Doe',
34- validate: (value) {
35- return switch (value) {
36- String(:final isEmpty) when isEmpty => 'Name cannot be empty',
37- _ => null,
38- };
39- });
39+ validate: (validator) => validator
40+ ..validate((value) => value == 'Bob'
41+ ? 'Bob is not allowed'
42+ : null));
4043
4144 print(value);
4245}
@@ -202,3 +205,41 @@ Future<void> main() async {
202205Future<void> wait() =>
203206 Future.delayed(Duration(seconds: Random().nextInt(3) + 1));
204207` ` `
208+
209+ # # Theming
210+
211+ Commander provides a theming system to customize the appearance of the components.
212+ It is possible to define a global theme for all components or a specific theme for each component.
213+
214+ ` ` ` dart
215+ Future<void> main() async {
216+ final commander = Commander(
217+ level: Level.verbose,
218+ componentTheme: ComponentTheme(
219+ askTheme: DefaultAskTheme.copyWith(askPrefix: '🤖')
220+ ));
221+
222+ final value = await commander.ask('What is your email ?',
223+ validate: (validator) => validator
224+ ..notEmpty(message: 'Name cannot be empty :)')
225+ ..email(message: 'Please enter a valid email'));
226+
227+ print(value);
228+ }
229+ ` ` `
230+
231+ Each component that interacts with the user has a `theme` property that allows the appearance to be customised.
232+
233+ ` ` ` dart
234+ Future<void> main() async {
235+ final commander = Commander(level: Level.verbose);
236+
237+ final value = await commander.ask('What is your email ?',
238+ theme: DefaultAskTheme.copyWith(askPrefix: '🤖'),
239+ validate: (validator) => validator
240+ ..notEmpty(message: 'Name cannot be empty :)')
241+ ..email(message: 'Please enter a valid email'));
242+
243+ print(value);
244+ }
245+ ` ` `
0 commit comments