n_bug_reporter 0.0.2 copy "n_bug_reporter: ^0.0.2" to clipboard
n_bug_reporter: ^0.0.2 copied to clipboard

Naylalabs proprietary bug reporter plugin

example/lib/main.dart

import 'dart:typed_data';

import 'package:flutter/material.dart';
import 'dart:async';

import 'package:flutter/services.dart';
import 'package:n_bug_reporter/n_bug_reporter.dart';
import 'package:n_bug_reporter/model/clickup_custom_field_ids.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _platformVersion = 'Unknown';
  String? _createdTaskId = 'Unknown';
  static const String privateKey =
      '';
  Uint8List? _currentSS;

  // this has to be passed to nbugsreporter
  // and scaffold should be wrapped around repaint boundary
  // about repaint boundary: https://www.woolha.com/tutorials/flutter-using-repaintboundary-examples
  final GlobalKey _key = GlobalKey();

  @override
  void initState() {
    super.initState();
    NBugReporter.configure(
        privateKey: privateKey,
        listId: '',
        templateId: '',
        customFieldIds: ClickUpCustomFieldIds(
            appBundleId: '',
            activity: '',
            deviceInfo: '',
            platform: ''),
        repaintBoundaryKey: _key);
    initPlatformState();
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    String platformVersion;
    String createdTaskId;
    // Platform messages may fail, so we use a try/catch PlatformException.
    // We also handle the message potentially returning null.
    try {
      platformVersion =
          await NBugReporter.platformVersion ?? 'Unknown platform version';
    } on PlatformException {
      platformVersion = 'Failed to get platform version.';
    }

    // If the widget was removed from the tree while the asynchronous platform
    // message was in flight, we want to discard the reply rather than calling
    // setState to update our non-existent appearance.
    if (!mounted) return;

    setState(() {
      _platformVersion = platformVersion;
    });
  }

  @override
  Widget build(BuildContext context) {
    final ButtonStyle style =
        ElevatedButton.styleFrom(textStyle: const TextStyle(fontSize: 20));

    return MaterialApp(
      home: RepaintBoundary(
        key: _key,
        child: Scaffold(
          appBar: AppBar(
            title: const Text('Plugin example app'),
          ),
          body: Stack(
            children: [
              Positioned(
                  child: NBugReporter.nBugReporterButton(
                    prereport: (){},
                    postreport: (){},
                  ),
                  left: 0,
                  bottom: 0),
              Center(
                child: Column(
                  children: [
                    Text('Running on: $_platformVersion\n'),
                    Text('createdTaskId: $_createdTaskId\n'),
                    ElevatedButton(
                      style: style,
                      onPressed: () async {
                        var res = await NBugReporter.createTaskFromTemplate();
                        setState(() {
                          _createdTaskId = res?.id;
                        });
                      },
                      child: const Text('create N BUG REPORTER task'),
                    ),
                    ElevatedButton(
                      style: style,
                      onPressed: () async {
                        var ss = await NBugReporter.getScreenshot(
                            repaintBoundaryKey: _key);
                        setState(() {
                          _currentSS = ss;
                        });
                      },
                      child: Column(
                        children: [
                          _currentSS != null
                              ? Image.memory(
                                  _currentSS!,
                                  height: 100,
                                  width: 100,
                                )
                              : const SizedBox.shrink(),
                          const Text('get screenshot'),
                        ],
                      ),
                    )
                  ],
                ),
              )
            ],
          ),
        ),
      ),
    );
  }
}
1
likes
110
points
28
downloads

Publisher

unverified uploader

Weekly Downloads

Naylalabs proprietary bug reporter plugin

Documentation

API reference

License

MIT (license)

Dependencies

device_info_plus, dio, flutter, flutter_web_plugins, json_annotation, package_info_plus

More

Packages that depend on n_bug_reporter