Home > Software engineering >  Flutter gives errors when using TextField
Flutter gives errors when using TextField

Time:10-14

This is the error: Could not load source 'dart:core-patch/errors_patch.dart': <source not available>. I will use a TextField in a certain file and it will open up errors_patch.dart file that contains the error that I wrote above.

Code:

import "package:flutter/material.dart";

class EditNoteHeader extends StatefulWidget {
  const EditNoteHeader({super.key});

  @override
  State<EditNoteHeader> createState() => _EditNoteHeaderState();
}

class _EditNoteHeaderState extends State<EditNoteHeader> {
  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: const EdgeInsets.all(8.0),
      child: ClipRRect(
        borderRadius: const BorderRadius.all(Radius.circular(8.0)),
        child: ColoredBox(
          color: const Color(0xFF656565),
          child: Padding(
            padding: const EdgeInsets.all(8.0),
            child: Row(
              children: [
                IntrinsicHeight(
                  child: Row(
                    crossAxisAlignment: CrossAxisAlignment.stretch,
                    children: [
                      Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: const [
                          TextField(
                            decoration: InputDecoration(
                              hintText: "New Text",
                            ),
                          ),
                        ],
                      )
                    ],
                  ),
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }
}

CodePudding user response:

Wrap your Textfield inside SizedBox or Container Widget

    SizedBox(
            width: 300,
            height: 60,
            child: TextField(
              decoration: InputDecoration(
                hintText: "New Text",
              ),
            ),
          ),

CodePudding user response:

I think you like to have IntrinsicWidth instead of IntrinsicHeight on TextField.

IntrinsicWidth(
  child: TextField(
    decoration: InputDecoration(
      hintText: "New Text",
    ),
  ),
),

If you need more control about sizing, you can use LayoutBuilder with SizedBox(width:x for row case.

CodePudding user response:

This error occurs when an error has happened and VS code or any IDE wants to display the source code however its not avaiilable in the SDK.To find out what is causing the error try to use the call stack view if using vs code to the top and take a look at the exception popup shown.

  • Related