Home > Software engineering >  When I Use Marquee Package in Flutter, an Error Occurs
When I Use Marquee Package in Flutter, an Error Occurs

Time:11-02

The Goal

Make it able to use Marquee() without errors.

What I Did

I installed marquee package.

Wrote code :

import 'package:marquee/marquee.dart';

// In Column()
Marquee(
                                                text: "Exampleeeeeeeeeeeeeeeeeee",
                                                pauseAfterRound:
                                                    const Duration(
                                                        seconds: 1),
                                                style: const TextStyle(
                                                    fontSize: 20),
                                              ),

Error

I didn't see any errors in the debug console, but I saw colored code in dart file:

  // errors_patch.dart

  static _doThrowNew(int assertionStart, int assertionEnd, Object? message)
      native "AssertionError_throwNew";

What I Tried

I found that I can solve this error by using Expanded. So I surrounded Marquee with Expanded like this

                                              Expanded(
                                                  child: Marquee(
                                                text: "Exampleeeeeeeeeeeeeeeee",
                                                pauseAfterRound:
                                                    const Duration(
                                                        seconds: 1),
                                                style: const TextStyle(
                                                    fontSize: 20),
                                              )),

But error still occurs.

════════ Exception caught by rendering library ═════════════════════════════════
RenderBox was not laid out: RenderViewport#96fb3 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
'package:flutter/src/rendering/box.dart':
package:flutter/…/rendering/box.dart:1
Failed assertion: line 1999 pos 12: 'hasSize'

The relevant error-causing widget was
Marquee
lib\favorites.dart:167
════════════════════════════════════════════════════════════════════════════════

Environment

$flutter doctor -v result:

[√] Flutter (Channel beta, 2.6.0-5.2.pre, on Microsoft Windows [Version 10.0.22000.282], locale ja-JP)
    • Flutter version 2.6.0-5.2.pre at D:\src\flutter_windows_2.5.0-stable\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 400608f101 (6 weeks ago), 2021-09-15 15:50:26 -0700
    • Engine revision 1d521d89d8
    • Dart version 2.15.0 (build 2.15.0-82.2.beta)

[√] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
    • Android SDK at D:\Android
    • Platform android-30, build-tools 29.0.3
    • Java binary at: D:\Program Files\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 11.0.8 10-b944.6842174)
    • All Android licenses accepted.

[√] Chrome - develop for the web
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[√] Android Studio (version 4.2)
    • Android Studio at D:\Program Files\Android\Android Studio
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.8 10-b944.6842174)

[√] VS Code (version 1.61.2)
    • VS Code at C:\Users\yukik\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.27.0

[√] Connected device (3 available)
    • Android SDK built for x86 (mobile) • emulator-5554 • android-x86    • Android 10 (API 29) (emulator)
    • Chrome (web)                       • chrome        • web-javascript • Google Chrome 95.0.4638.54
    • Edge (web)                         • edge          • web-javascript • Microsoft Edge 95.0.1020.40

• No issues found!

CodePudding user response:

Add it in this hierarchy Column Row Flexible Marquee You are trying to use an expanded inside a column widget which doesn't have a finite height. So it throws an error.

CodePudding user response:

I've surrounded Marquee with the following widgets.

Column -> Expanded -> SizedBox -> Marquee

This works.

  • Related