Skip to content
This repository has been archived by the owner on Oct 10, 2020. It is now read-only.

AlertDialog not being displayed after result #3

Closed
BenSower opened this issue Jan 4, 2018 · 4 comments
Closed

AlertDialog not being displayed after result #3

BenSower opened this issue Jan 4, 2018 · 4 comments

Comments

@BenSower
Copy link
Contributor

BenSower commented Jan 4, 2018

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 BenSower changed the title AlertDialog Problem AlertDialog not being displayed after result Jan 4, 2018
@BenSower
Copy link
Contributor Author

BenSower commented Jan 5, 2018

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 BenSower closed this as completed Jan 5, 2018
@BenSower
Copy link
Contributor Author

BenSower commented Jan 5, 2018

I think this is the related issue: flutter/flutter#13818

@edufolly
Copy link

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

@BenSower
Copy link
Contributor Author

@edufolly as mentioned in flutter/flutter#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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants