0

To prevent errors I want to disable the user input while my flutter app is uploading some data to firebase. I already tried IgnorePointer and AbsorbPointer with a boolean which gets updated via setState when the user presses "upload data". But the user can still enter something on the screen.

Is there a way to disable the user input while the data is uploading? After the upload is finished the user will be navigated automatically in the main menu.

Here are some parts of the code:

class AddJob extends StatefulWidget {
 AddJob({Key? key}) : super(key: key);
 @override
 _AddJobState createState() => _AddJobState();
}

class _AddJobState extends State<AddJob> {
 bool ignoring = false;
 Future<void> addJob() async {
 return showDialog<void>(
    barrierDismissible: true,
    context: context,
    builder: (context) {
      return AlertDialog(
        shape: RoundedRectangleBorder(
            borderRadius:       BorderRadius.all(Radius.circular(15))),
        title: Text('Privat oder Öffentlich?'),
        content: Text(
            'xy'),
        actions: <Widget>[
          TextButton(
            onPressed: () {
              Navigator.of(context).pop();
            },
            child: Text('back'),
          ),
          TextButton(
              onPressed: () async {
                setState(() {
                  ignoring = true;
                });

                ScaffoldMessenger.of(context).showSnackBar(SnackBar(
                  duration: Duration(seconds: 4),
                  content: Row(
                    children: <Widget>[
                      new CircularProgressIndicator(),
                      new Text(" Hochladen...")
                    ],
                  ),
                ));

... uploading
  }
}

@override
Widget build(BuildContext context) {
final _picker = ImagePicker();
return IgnorePointer(
  ignoring: ignoring,
  child: GestureDetector(
    onTap: () {
      FocusScopeNode currentFocus = FocusScope.of(context);
      if (!currentFocus.hasPrimaryFocus) {
        currentFocus.unfocus();
      }
    },
    child: Scaffold(
      appBar: AppBar(
        shape: RoundedRectangleBorder(
            borderRadius:
                BorderRadius.vertical(bottom: Radius.circular(15))),
        backgroundColor: blueLayerOne,
        title: Text('create'),
        actions: [
          IconButton(
              icon: Icon(Icons.info_outline_rounded),
              onPressed: () {
                showInfos();
              }),
        ],
      ),
      body: SingleChildScrollView(

...normal screen widgets
  }
}
Jason Aller
  • 3,541
  • 28
  • 38
  • 38
beax07
  • 11
  • 3

0 Answers0