Closed mg3994 closed 4 months ago
Is your feature request related to a problem? Please describe. This is a alternative of feedback_gitlab => feedback_github where we create issues using PAT
Describe the solution you'd like
import 'dart:io'; import 'package:feedback/feedback.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:http/http.dart' as http; extension BetterFeedbackXT on FeedbackController { /// Example usage: /// ```dart /// import 'package:feedback_github/feedback_github.dart'; /// /// RaisedButton( /// child: Text('Click me'), /// onPressed: (){ /// BetterFeedback.of(context).showAndUploadToGithub /// tag: "BUG" /// username:"githubusername" /// repository:"<REPO NAME>" /// authToken: '<PAT TOKEN>', /// ); /// } /// ) void showAndUploadToGithub({ required BuildContext context, required String username, required String repository, required String authToken, required String tag, }) { show(uploadToGithub( context: context, username: username, repository: repository, authToken: authToken, tag: tag, )); } } @visibleForTesting OnFeedbackCallback uploadToGithub({ required BuildContext context, required String username, required String repository, required String authToken, required String tag, }) { final baseUrl = "https://api.github.com"; return (UserFeedback feedback) async { final uri = Uri.parse('$baseUrl/repos/$username/$repository/issues'); final request = http.MultipartRequest('POST', uri) ..fields['title'] = tag ..fields['body'] = feedback.text ..fields['extra'] = feedback.extra.toString(); final screenshotBytes = Uint8List.fromList(feedback.screenshot); final tempFile = await _saveImageToFile(screenshotBytes); request.files.add( await http.MultipartFile.fromPath( 'image', tempFile.path, ), ); request.headers['Authorization'] = 'token $authToken'; final streamedResponse = await request.send(); final response = await http.Response.fromStream(streamedResponse); if (response.statusCode == 201) { ScaffoldMessenger.of(context).showSnackBar( //TODO: Avoid context at async gap const SnackBar( content: Text('Issue created successfully ✔'), backgroundColor: Colors.green, ), ); } else { ScaffoldMessenger.of(context).showSnackBar( //TODO: Avoid context at async gap SnackBar( content: Text('Failed to create issue ❌ : ${response.body}'), backgroundColor: Colors.red, ), ); } // Delete the temporary file await tempFile.delete(); }; } Future<File> _saveImageToFile(Uint8List imageBytes) async { final tempDir = await Directory.systemTemp.create(); final tempFile = File('${tempDir.path}/screenshot.png'); await tempFile.writeAsBytes(imageBytes); return tempFile; }
Describe alternatives you've considered code provided
Additional context Please create a new package with that name where we can use custom Markdown and can create issues
Thanks for considering my Request
This can currently be achieved by using feedback_github. Please see the README for more information.
As of now, this can't be done securely for GitHub.
Is your feature request related to a problem? Please describe. This is a alternative of feedback_gitlab => feedback_github where we create issues using PAT
Describe the solution you'd like
buggy code but you will get what i am trying to say
Describe alternatives you've considered code provided
Additional context Please create a new package with that name where we can use custom Markdown and can create issues