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:
lib/main.dartimport '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.dartimport '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.dartimport '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.