0
E/flutter (12906): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: No Overlay widget found.
E/flutter (12906): Some widgets require an Overlay widget ancestor for correct operation.
E/flutter (12906): The most common way to add an Overlay to an application is to include a MaterialApp, CupertinoApp or Navigator widget in the runApp() call.
E/flutter (12906): The context from which that widget was searching for an overlay was:
E/flutter (12906):   MyApp
E/flutter (12906): #0      Overlay.of.<anonymous closure>
overlay.dart:384
E/flutter (12906): #1      Overlay.of
overlay.dart:387
E/flutter (12906): #2      ToastView.createView
toast.dart:97
E/flutter (12906): #3      Toast.show
toast.dart:68

My Main dart

import 'package:flutter/material.dart';
import 'package:minwentaryzacja/screens/loginForm.dart';
import 'package:minwentaryzacja/screens/signupForm.dart';
import 'package:toast/toast.dart';

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

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    ToastContext().init(context);
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'm-Inwentaryzacja',
      theme: ThemeData(
        primarySwatch: Colors.blue,
        primaryColor: Colors.white,
        accentColor: Colors.black,
        backgroundColor: Color.fromARGB(255, 0, 36, 66),
        buttonTheme: ButtonThemeData(
          buttonColor: Color.fromARGB(255, 190, 2, 58),
        ),
      ),
      home: const LoginForm(title: 'm-Inwentaryzacja'),
      routes: {
        SignUpForm.routeName: (ctx) => SignUpForm(),
      },
    );
  }
}

my toastHelper.dart

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

alertDialog(BuildContext context, String msg) {
  Toast.show(msg, duration: Toast.lengthLong, gravity: Toast.bottom);
}

My loginForm.dart

import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:flutter/src/widgets/placeholder.dart';
import 'package:minwentaryzacja/common/textFormField.dart';
import 'package:minwentaryzacja/common/toastHelper.dart';
import 'package:minwentaryzacja/databaseHandler/dbHelper.dart';
import 'package:minwentaryzacja/screens/signupForm.dart';

class LoginForm extends StatefulWidget {
  const LoginForm({super.key, required this.title});

  // static const routeName = '/loginPange';

  final String title;

  @override
  State<LoginForm> createState() => _LoginFormState();
}

class _LoginFormState extends State<LoginForm> {
  bool _obscureText = true;

  final _formKey = new GlobalKey<FormState>();

  final _conUserId = TextEditingController();
  final _conPassword = TextEditingController();
  var dbHelper;

  @override
  void initState() {
    super.initState();
    dbHelper = DbHelper();
  }

  void login() {
    final form = _formKey.currentState;
    String uid = _conUserId.text;
    String password = _conPassword.text;
    // String passwordR = _conPasswordR.text;

    if (uid.isEmpty) {
      alertDialog(context, "Wpisz nazwę Użytkownika");
    } else if (password.isEmpty) {
      alertDialog(context, "Podaj Hasło");
    }
  }

  void _toggle() {
    setState(() {
      _obscureText = !_obscureText;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      decoration: const BoxDecoration(
          image: DecorationImage(
              image: AssetImage("assets/images/background.png"),
              fit: BoxFit.cover)),
      child: Scaffold(
        backgroundColor: Colors.transparent,
        // appBar: AppBar(
        //   title: Text(widget.title),
        // ),
        body: SingleChildScrollView(
          scrollDirection: Axis.vertical,
          child: Container(
            width: double.infinity,
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                SizedBox(
                  height: 30.0,
                ),
                Row(
                  mainAxisAlignment: MainAxisAlignment.start,
                  children: [
                    // Expanded(
                    //     child: SizedBox(
                    //   width: 10.0,
                    // )),
                    Padding(
                      padding: EdgeInsets.only(left: 20, top: 20),
                      child: Image.asset(
                        "assets/images/logo.png",
                        width: 100,
                      ),
                    ),
                    Expanded(
                        child: SizedBox(
                      width: 10.0,
                    )),
                  ],
                ),
                SizedBox(
                  height: 80.0,
                ),
                Text(
                  "Inwentaryzacja",
                  style: TextStyle(
                      fontWeight: FontWeight.bold,
                      color: Theme.of(context).primaryColor,
                      fontSize: 45),
                ),
                SizedBox(
                  height: 70.0,
                ),
                Text(
                  "Logowanie",
                  style: TextStyle(
                      fontWeight: FontWeight.normal,
                      color: Theme.of(context).primaryColor,
                      fontSize: 25.0),
                ),
                SizedBox(
                  height: 10,
                ),
                getTextFormField(
                  controller: _conUserId,
                  hintName: "Użytkownik",
                  icon: Icons.person,
                ),
                SizedBox(
                  height: 10,
                ),
                // getTextFormField(
                //   controller: _conUserId,
                //   hintName: "Hasło",
                //   icon: Icons.person,
                //   isobscureText: true,
                // ),
                Container(
                  margin: EdgeInsets.only(left: 50, right: 50),
                  child: TextFormField(
                    obscureText: _obscureText,
                    decoration: InputDecoration(
                        border: InputBorder.none,
                        enabledBorder: OutlineInputBorder(
                            borderRadius: BorderRadius.all(Radius.circular(20)),
                            borderSide: BorderSide(color: Colors.transparent)),
                        focusedBorder: OutlineInputBorder(
                          borderRadius: BorderRadius.all(Radius.circular(20)),
                        ),
                        prefixIcon: Icon(Icons.lock),
                        suffixIcon: IconButton(
                          onPressed: _toggle,
                          icon: Icon(_obscureText
                              ? Icons.visibility
                              : Icons.visibility_off),
                        ),
                        hintText: "Hasło",
                        fillColor: Colors.grey[200],
                        filled: true),
                  ),
                ),
                Container(
                    width: double.infinity,
                    margin: EdgeInsets.only(top: 30, left: 50, right: 50),
                    child: TextButton(
                        child: Text(
                          "Zaloguj",
                          style:
                              TextStyle(color: Theme.of(context).primaryColor),
                        ),
                        onPressed: login,
                        style: TextButton.styleFrom(
                          shape: RoundedRectangleBorder(
                            borderRadius: BorderRadius.circular(12),
                          ),
                          foregroundColor: Theme.of(context).primaryColor,
                          padding: const EdgeInsets.all(20.0),
                          backgroundColor:
                              // Theme.of(context).colorScheme.primary,
                              Theme.of(context).backgroundColor,
                        ))),
                Container(
                    width: double.infinity,
                    margin: EdgeInsets.only(top: 10, left: 50, right: 50),
                    child: TextButton(
                      child: Text(
                        "Przejdź do rejestracji",
                        style: TextStyle(color: Theme.of(context).primaryColor),
                      ),
                      onPressed: () {
                        Navigator.of(context).pushNamed(SignUpForm.routeName);
                      },
                    )),
              ],
            ),
          ),
        ),
      ),
    );
  }
}

My textFormField.dart

import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:flutter/src/widgets/placeholder.dart';
import 'package:minwentaryzacja/common/toastHelper.dart';

class getTextFormField extends StatelessWidget {
  TextEditingController controller;
  String hintName;
  IconData icon;
  bool isobscureText;

  getTextFormField(
      {required this.controller,
      required this.hintName,
      required this.icon,
      this.isobscureText = false});

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: EdgeInsets.only(top: 10, left: 50, right: 50),
      child: TextFormField(
        controller: this.controller,
        obscureText: isobscureText,
        validator: (value) {
          if (value == null || value.isEmpty) {
            return "Wprowadź $hintName";
          }
          if (hintName == "Hasło" && value.length < 6) {
            return 'Hasło musi zawierać wiecej niż 6 znakoów';
          }
          return null;
        },
        // validator: (val) => (val == null) ? "Proszę wprowadź $hintName" : null,
        // onSaved: (val) => controller.text = val!,
        decoration: InputDecoration(
            errorStyle:
                TextStyle(color: Colors.black, fontWeight: FontWeight.bold),
            border: InputBorder.none,
            enabledBorder: OutlineInputBorder(
                borderRadius: BorderRadius.all(Radius.circular(20)),
                borderSide: BorderSide(color: Colors.transparent)),
            focusedBorder: OutlineInputBorder(
              borderRadius: BorderRadius.all(Radius.circular(20)),
            ),
            prefixIcon: Icon(icon),
            hintText: hintName,
            // labelText: hintName,
            labelStyle: TextStyle(color: Theme.of(context).accentColor),
            fillColor: Colors.grey[200],
            filled: true),
      ),
    );
  }
}

I'm having trouble displaying my toastHelper. I am getting an error that I don't know how to fix. dependencies: flutter: sdk: flutter path_provider: ^2.0.14 sqflite: ^2.2.6 toast: ^0.2.9

when my input (uid.isEmpty) I have Error when i click Login " alertDialog(context, "Podaj Hasło");" Not working. No notification window is displayed

1

1 Answer 1

0

Your Main.dart should be like:

import 'package:flutter/material.dart';
import 'package:minwentaryzacja/screens/loginForm.dart';
import 'package:minwentaryzacja/screens/signupForm.dart';
import 'package:toast/toast.dart';

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

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    ToastContext().init(context);
    return OverlaySupport.global(
      child: MaterialApp(
        debugShowCheckedModeBanner: false,
        title: 'm-Inwentaryzacja',
        theme: ThemeData(
          primarySwatch: Colors.blue,
          primaryColor: Colors.white,
          accentColor: Colors.black,
          backgroundColor: Color.fromARGB(255, 0, 36, 66),
          buttonTheme: ButtonThemeData(
            buttonColor: Color.fromARGB(255, 190, 2, 58),
          ),
        ),
        home: const LoginForm(title: 'm-Inwentaryzacja'),
        routes: {
          SignUpForm.routeName: (ctx) => SignUpForm(),
        },
      ),
    );
  }
} 
Sign up to request clarification or add additional context in comments.

2 Comments

I add pub overlay_support and in my file main.dart import 'package:overlay_support/overlay_support.dart'; And i got error "E/flutter (15273): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: No Overlay widget found. E/flutter (15273): Some widgets require an Overlay widget ancestor for correct operation. E/flutter (15273): The most common way to add an Overlay to an application is to include a MaterialApp, CupertinoApp or Navigator widget in the runApp() call. E/flutter (15273): The context from which that widget was searching for an overlay was:"
I edited my answer with how your Main.dart should be. Also iclude import 'package:overlay_support/overlay_support.dart'; on top

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.