-
Notifications
You must be signed in to change notification settings - Fork 0
Add an example app #23
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,7 @@ | ||
| # 6.0.1 | ||
|
|
||
| - Add an example app. | ||
|
|
||
| # 6.0.0 | ||
|
|
||
| - Bump flutter_bugfender version to 5.0.0 | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| include: package:leancode_lint/analysis_options.yaml |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| // An example app showing how to wire `logging_bugfender` into a Flutter app. | ||
| // | ||
| // This directory ships without the platform folders – run `flutter create .` | ||
| // in it once before `flutter run`. | ||
|
|
||
| import 'package:flutter/material.dart'; | ||
| import 'package:logging/logging.dart'; | ||
| import 'package:logging_bugfender/logging_bugfender.dart'; | ||
|
|
||
| /// The key under which the signed in user is reported to Bugfender. | ||
| const usernameKey = 'username'; | ||
|
|
||
| void main() { | ||
| // During debugging, you'll usually want to log everything. On production, | ||
| // `Level.INFO` and above is usually enough. | ||
| Logger.root.level = Level.ALL; | ||
|
|
||
| final loggingListener = LoggingBugfenderListener( | ||
| 'my-very-secret-app-key', | ||
| // Logs are only sent to Bugfender by default – printing them to the | ||
| // console too is handy while debugging. | ||
| consolePrintStrategy: const PlainTextPrintStrategy(), | ||
| )..listen(Logger.root); | ||
|
|
||
| runApp(ExampleApp(loggingListener: loggingListener)); | ||
| } | ||
|
|
||
| class ExampleApp extends StatelessWidget { | ||
| const ExampleApp({super.key, required this.loggingListener}); | ||
|
|
||
| final LoggingBugfenderListener loggingListener; | ||
|
|
||
| @override | ||
| Widget build(BuildContext context) { | ||
| return MaterialApp( | ||
| title: 'logging_bugfender example', | ||
| home: ExamplePage(loggingListener: loggingListener), | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| class ExamplePage extends StatefulWidget { | ||
| const ExamplePage({super.key, required this.loggingListener}); | ||
|
|
||
| final LoggingBugfenderListener loggingListener; | ||
|
|
||
| @override | ||
| State<ExamplePage> createState() => _ExamplePageState(); | ||
| } | ||
|
|
||
| class _ExamplePageState extends State<ExamplePage> { | ||
| /// Every class that logs should have its own [Logger] – its name is included | ||
| /// in the log message, so you always know where a record came from. | ||
| final _logger = Logger('ExamplePage'); | ||
|
|
||
| bool _signedIn = false; | ||
|
|
||
| /// Custom data is attached to every log sent from this device, which makes | ||
| /// it easy to tell whose session you're looking at in the Bugfender console. | ||
| Future<void> _toggleSignIn() async { | ||
| final signedIn = _signedIn; | ||
|
|
||
| try { | ||
| if (signedIn) { | ||
| await widget.loggingListener.removeCustomData(usernameKey); | ||
| } else { | ||
| await widget.loggingListener.setCustomData(usernameKey, 'jane.doe'); | ||
| } | ||
| } catch (err, st) { | ||
| // Both the error and the stack trace are sent to Bugfender. | ||
| _logger.severe('Failed updating the custom data', err, st); | ||
| return; | ||
| } | ||
|
|
||
| _logger.info(signedIn ? 'Signed out' : 'Signed in'); | ||
|
|
||
| if (mounted) { | ||
| setState(() => _signedIn = !signedIn); | ||
| } | ||
| } | ||
|
|
||
| @override | ||
| Widget build(BuildContext context) { | ||
| return Scaffold( | ||
| appBar: AppBar(title: const Text('logging_bugfender')), | ||
| body: Center( | ||
| child: Column( | ||
| mainAxisAlignment: MainAxisAlignment.center, | ||
| children: [ | ||
| FilledButton( | ||
| onPressed: () => _logger.fine('The details button was tapped'), | ||
| child: const Text('Log at FINE'), | ||
| ), | ||
| FilledButton( | ||
| onPressed: () => _logger.warning('The cache is almost full'), | ||
| child: const Text('Log at WARNING'), | ||
| ), | ||
| const SizedBox(height: 16), | ||
| FilledButton( | ||
| onPressed: _toggleSignIn, | ||
| child: Text(_signedIn ? 'Sign out' : 'Sign in'), | ||
| ), | ||
| ], | ||
| ), | ||
| ), | ||
| ); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| name: logging_bugfender_example | ||
| description: An example app showing how to integrate Bugfender with the logging package. | ||
| publish_to: none | ||
|
|
||
| environment: | ||
| sdk: '>=3.3.0 <4.0.0' | ||
| flutter: '>=3.19.0' | ||
|
|
||
| dependencies: | ||
| flutter: | ||
| sdk: flutter | ||
| logging: ^1.0.2 | ||
| logging_bugfender: | ||
| path: ../ | ||
|
|
||
| dev_dependencies: | ||
| leancode_lint: '>=2.1.0 <2.2.0' | ||
|
|
||
| flutter: | ||
| uses-material-design: true | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
2? Not 25? 🤔
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.
That's the constraint used by the main package as well; upgrading lints will also force us to change SDK constraints and other stuff – for later 😛
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.
😱