-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: adding possibility to pin information on preview area #83
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -92,10 +92,54 @@ dashbook | |
); | ||
}); | ||
|
||
return Text('Use actions to show the Dialog'); | ||
return SizedBox(); | ||
}); | ||
``` | ||
|
||
## Example information | ||
|
||
More than often, an example may not be intuitive enough and the user may be lost without some instruction on how to interact with it. To mitigate that, text information can be linked to an example to serve as a guide, or really to show any relevant information. | ||
erickzanardo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
To do so, simple use the `info` parameter on the `add` method of a story: | ||
erickzanardo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
```dart | ||
final dashbook = Dashbook(); | ||
|
||
dashbook | ||
.storiesOf('CustomDialog') | ||
.add('default', | ||
(ctx) { | ||
ctx.action('Open dialog', (context) { | ||
showDialog( | ||
context: context, | ||
builder: (_) => CustomDialog(), | ||
); | ||
}); | ||
|
||
return SizedBox(); | ||
}, | ||
info: 'Use the actions button on the side to show the dialog.', | ||
); | ||
``` | ||
|
||
This will present a small `i` icon on the side toolbar that once clicked will present the information to the user. | ||
|
||
Dashbook also offers the possibility to directly show the information on the preview area, removing the necessity for the user to click on the icon. To do so, simple pass `true` to the `pinInfo` parameter. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Too long line
erickzanardo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
```dart | ||
final dashbook = Dashbook(); | ||
|
||
dashbook | ||
.storiesOf('CustomDialog') | ||
.add('default', | ||
(ctx) { | ||
// omitted ... | ||
}, | ||
info: 'Use the actions button on the side to show the dialog.', | ||
pinInfo: true, | ||
); | ||
``` | ||
|
||
## Preview area | ||
|
||
By default Dashbook will provide the whole screen area for the preview, which means that its controll icons will appear floating above the example. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import 'package:dashbook/dashbook.dart'; | ||
import 'package:dashbook/src/widgets/icon.dart'; | ||
import 'package:dashbook/src/widgets/keys.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:shared_preferences/shared_preferences.dart'; | ||
|
@@ -18,3 +19,11 @@ extension WidgetTesterExtension on WidgetTester { | |
await pumpAndSettle(); | ||
} | ||
} | ||
|
||
extension CommonFindersX on CommonFinders { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hah never seen X been used as a short form of Extension before, is this common? I think I'd prefer the word written out. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I didn't know either, but seems to be quite common. |
||
Finder dashbookIconByTooltip(String tooltip) { | ||
return byWidgetPredicate( | ||
(widget) => widget is DashbookIcon && widget.tooltip == tooltip, | ||
); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import 'package:dashbook/dashbook.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
|
||
import '../helpers.dart'; | ||
|
||
Dashbook _getDashbookWithIconInfo() { | ||
final dashbook = Dashbook(); | ||
|
||
dashbook.storiesOf('Text').add( | ||
'default', | ||
(context) => const SizedBox(), | ||
info: 'This is some info', | ||
); | ||
|
||
return dashbook; | ||
} | ||
|
||
Dashbook _getDashbookWithPinnedInfo() { | ||
final dashbook = Dashbook(); | ||
|
||
dashbook.storiesOf('Text').add( | ||
'default', | ||
(context) => const SizedBox(), | ||
info: 'Behold! The info is already upon you!', | ||
pinInfo: true, | ||
); | ||
|
||
return dashbook; | ||
} | ||
|
||
void main() { | ||
group('Chapter Info', () { | ||
testWidgets('shows the info icon', (tester) async { | ||
await tester.pumpDashbook(_getDashbookWithIconInfo()); | ||
expect( | ||
find.dashbookIconByTooltip('Instructions'), | ||
findsOneWidget, | ||
); | ||
}); | ||
|
||
testWidgets( | ||
'show the info dialog when the icon is clicked', | ||
(tester) async { | ||
await tester.pumpDashbook(_getDashbookWithIconInfo()); | ||
|
||
await tester.tap( | ||
find.dashbookIconByTooltip('Instructions'), | ||
); | ||
|
||
await tester.pumpAndSettle(); | ||
expect(find.text('This is some info'), findsOneWidget); | ||
}, | ||
); | ||
|
||
testWidgets( | ||
'show the info dialog when the icon is clicked', | ||
(tester) async { | ||
await tester.pumpDashbook(_getDashbookWithPinnedInfo()); | ||
|
||
await tester.pumpAndSettle(); | ||
expect( | ||
find.text('Behold! The info is already upon you!'), | ||
findsOneWidget, | ||
); | ||
}, | ||
); | ||
}); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Too long line