Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Flutter program crashing

I’m new to Flutter/Dart and am trying to write a login UI. When I attempt to run the program, the debugger stops at this, errors_patch.dart which I assume is built-in:

@pragma("vm:external-name", "AssertionError_throwNew")
  external static _doThrowNew(
      int assertionStart, int assertionEnd, Object? message);
  @pragma("vm:external-name", "AssertionError_throwNewSource")
  external static _doThrowNewSource(
      String failedAssertion, int line, int column, Object? message);

How do I proceed? I’ve not modified any settings files or something. Android Studio and Flutter/Dart are up-to-date, and I’ve previously built this project. Something here is breaking but the editor (VS Code) doesn’t indicate any errors or warnings.


Here is all my source code:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

  • lib/main.dart
    import 'package:flutter/material.dart';
    import 'config.dart';
    import 'ui/setup/login_page.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) {
        return MaterialApp(
          title: 'WiCon',
          theme: wiconTheme,
          home: const MainPage(),
        );
      }
    }
    
    class MainPage extends StatelessWidget {
      const MainPage({super.key});
    
      @override
      Widget build(BuildContext context) {
        return loginPage;
      }
    }
    
  • lib/ui/setup/login_page.dart
        import 'package:flutter/material.dart';
    
    var loginPage = Scaffold(
    
      appBar: AppBar(
        title: Row(
          children: const [
            Padding(
              padding: EdgeInsets.all(8.0),
              child: Icon(Icons.wifi),
            ),
            Padding(
              padding: EdgeInsets.all(8.0),
              child: Text("WiCon"),
            ),
          ],
        ),
      ),
    
      body: Row(
        children: [
          // Left side
          // Define the welcome message
          Column(
            children: const [
              Padding(
                padding: EdgeInsets.all(8.0),
                child: Text("Welcome to WiCon"),
              ),
              Padding(
                padding: EdgeInsets.all(8.0),
                child: Text("Please login to continue"),
              ),
            ],
          ),
    
          // Right side
          // Define the form, buttons, and status info
          Column(
            children: [
              Form(
                child: Column(
                  children: [
                    TextFormField(
                      decoration: const InputDecoration(labelText: "Register Number"),
                    ),
                    TextFormField(
                      decoration: const InputDecoration(
                        labelText: "Password",
                      ),
                      obscureText: true,
                    ),
                  ],
                ),
              ),
            ],
          )
        ],
      ),
    );
    
  • lib/config.dart
    import 'package:flutter/material.dart';
    
    final wiconTheme = ThemeData(
    useMaterial3: true,
    primarySwatch: Colors.blue,
    );
    

>Solution :

This happens due to the usage of Columns in Row. You have use Expanded or Flexible, or SizedBox with fixed with to solve this.
I used Flexible to solve this issue as following.

var loginPage = Scaffold(
      appBar: AppBar(
        title: Row(
          children: const [
            Padding(
              padding: EdgeInsets.all(8.0),
              child: Icon(Icons.wifi),
            ),
            Padding(
              padding: EdgeInsets.all(8.0),
              child: Text("WiCon"),
            ),
          ],
        ),
      ),

      body: Row(
        children: [
          // Left side
          // Define the welcome message
          Flexible(
            child: Column(
              children: const [
                Padding(
                  padding: EdgeInsets.all(8.0),
                  child: Text("Welcome to WiCon"),
                ),
                Padding(
                  padding: EdgeInsets.all(8.0),
                  child: Text("Please login to continue"),
                ),
              ],
            ),
          ),

          // Right side
          // Define the form, buttons, and status info
          Flexible(
            child: Column(
              children: [
                Form(
                  child: Column(
                    children: [
                      TextFormField(
                        decoration: const InputDecoration(labelText: "Register Number"),
                      ),
                      TextFormField(
                        decoration: const InputDecoration(
                          labelText: "Password",
                        ),
                        obscureText: true,
                      ),
                    ],
                  ),
                ),
              ],
            ),
          )
        ],
      ),
    )

Also you can use flex to decide the size of Row‘s children.

I hope this helps.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading