mintware-de / flutter_barcode_reader

A flutter plugin for reading 2D barcodes and QR codes.
MIT License
628 stars 462 forks source link

AlertDialog not being displayed after result #3

Closed BenSower closed 6 years ago

BenSower commented 6 years ago

I noticed that once the action returns, I can not properly display an alert dialog. I think it is being created, but not being displayed, since you can dismiss it by tapping outside of the invisible dialog window. I noticed this since I am working an a pull request that allows to handle if a user declines the permission request.

import 'dart:async';

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

void main() => runApp(
      new MaterialApp(
        home: new Scaffold(
          appBar: new AppBar(
            title: new Text('Barcode Scanner Example'),
          ),
          body: new MyApp(),
        ),
      ),
    );

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => new _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String barcode = "";

  @override
  initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return new Center(
      child: new Column(
        children: <Widget>[
          new Container(
            child: new MaterialButton(onPressed: scan, child: new Text("Scan")),
            padding: const EdgeInsets.all(8.0),
          ),
          new Text(barcode),
        ],
      ),
    );
  }

  Future scan() async {
    String barcode = await BarcodeScanner.scan();
    setState(() => this.barcode =
        'The dialog is not being shown, even though you can dismiss it, if you tap somewhere outside of it...');
    await showDialog(
      context: context,
      child: new AlertDialog(
        title: new Text("TITLE"),
        content:
            new Text("TESTBODY"),
        actions: <Widget>[
          new FlatButton(
            child: new Text('OK'),
            onPressed: () {
              Navigator.of(context).pop();
            },
          ),
        ],
      ),
    );
  }
}
BenSower commented 6 years ago

Ok, I don't think this issue is directly plugin related. I downgraded to flutter 0.0.19 and the dialog was displayed properly.

BenSower commented 6 years ago

I think this is the related issue: https://github.com/flutter/flutter/issues/13818

edufolly commented 6 years ago

The same issue occurs with me, but I tried to use SnackBar.

BenSower commented 6 years ago

@edufolly as mentioned in https://github.com/flutter/flutter/issues/13818, this is a problem of flutter itself. Currently this can be "fixed" by adding an artificial delay of 100ms as described in the main ticket.