assertion was thrown while rebuilding dirty elements: Assertion failed: stack_frame.dart:180 line != '=asynchronous gap =='

56 Views Asked by At

I am getting this error on my flutter, i am following an outdated tutorial but found my way untill now. the code

import 'dart:io';

import 'package:carousel_slider/carousel_slider.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:multiple_images_picker/multiple_images_picker.dart';
import 'package:twitter_clone/common/common.dart';
import 'package:twitter_clone/constants/assets_consts.dart';
import 'package:twitter_clone/core/provider.dart';
import 'package:twitter_clone/core/utils.dart';
import 'package:twitter_clone/features/controller/auth_controller.dart';
import 'package:twitter_clone/theme/pallete.dart';

class TweetPage extends ConsumerStatefulWidget {
  static const routeId = '/tweetpage';
  const TweetPage({super.key});

  @override
  ConsumerState<ConsumerStatefulWidget> createState() => _TweetPageState();
}

class _TweetPageState extends ConsumerState<TweetPage> {
  @override
  Widget build(BuildContext context) {
    final userData = ref.watch(getCurrentUserDataProvider).value;
    final _tweetcontroller = TextEditingController();

    List images = [];

    @override
    void dispose() {
      _tweetcontroller.dispose();
      super.dispose();
    }

    void onPickImages() async {
      images = await getImages();

      setState(() {});
    }

    return Scaffold(
      appBar: AppBar(
        leading: IconButton(
          onPressed: () {
            Navigator.pop(context);
          },
          icon: Icon(Icons.close),
        ),
        actions: [
          RoundedSmallButton(
            onTap: () {},
            label: 'Tweet',
            backGroundColor: Pallete.blueColor,
            labelColor: Pallete.whiteColor,
          )
        ],
      ),
      body: userData == null
          ? const Loader()
          : SafeArea(
              child: SingleChildScrollView(
                child: Column(
                  children: [
                    Row(
                      children: [
                        CircleAvatar(
                          backgroundImage: NetworkImage(userData.profilePic),
                          radius: 30,
                        ),
                        const SizedBox(
                          width: 15,
                        ),
                        Expanded(
                          child: TextField(
                            controller: _tweetcontroller,
                            style: const TextStyle(fontSize: 22),
                            decoration: const InputDecoration(
                              hintText: "What's Happening?",
                              hintStyle: TextStyle(
                                color: Pallete.greyColor,
                                fontSize: 22,
                                fontWeight: FontWeight.w600,
                              ),
                              border: InputBorder.none,
                            ),
                            maxLines: null,
                          ),
                        ),
                      ],
                    ),
                    SizedBox(
                      height: 10,
                    ),
                    if (images.isNotEmpty)
                      CarouselSlider(
                        items: images.map(
                          (file) {
                            return Container(
                              width: MediaQuery.of(context).size.width,
                              margin: const EdgeInsets.symmetric(
                                horizontal: 5,
                              ),
                              child: kIsWeb
                                  ? Image.network(file)
                                  : Image.file(file),
                            );
                          },
                        ).toList(),
                        options: CarouselOptions(
                          height: 400,
                          enableInfiniteScroll: false,
                        ),
                      ),
                    Row(
                      children: [Text('data')],
                    )
                  ],
                ),
              ),
            ),
      bottomNavigationBar: Container(
        padding: EdgeInsets.only(bottom: 10),
        decoration: const BoxDecoration(
            border: Border(
          top: BorderSide(
            color: Pallete.greyColor,
            width: 0.4,
          ),
        )),
        child: Row(children: [
          Padding(
            padding: const EdgeInsets.all(8.0).copyWith(
              left: 15,
              right: 15,
            ),
            child: GestureDetector(
                onTap: onPickImages,
                child: SvgPicture.asset(AssetsConstants.galleryIcon)),
          ),
          Padding(
            padding: const EdgeInsets.all(8.0).copyWith(
              left: 15,
              right: 15,
            ),
            child: SvgPicture.asset(AssetsConstants.gifIcon),
          ),
          Padding(
            padding: const EdgeInsets.all(8.0).copyWith(
              left: 15,
              right: 15,
            ),
            child: SvgPicture.asset(AssetsConstants.emojiIcon),
          ),
          if (images.isNotEmpty)
            CarouselSlider(
              items: images.map(
                (file) {
                  return Container(
                    width: MediaQuery.of(context).size.width,
                    margin: const EdgeInsets.symmetric(
                      horizontal: 5,
                    ),
                    child: kIsWeb ? Image.network(file) : Image.file(file),
                  );
                },
              ).toList(),
              options: CarouselOptions(
                height: 400,
                enableInfiniteScroll: false,
              ),
            ),
        ]),
      ),
    );
  }
}

the error from debugger

Exception caught by widgets library ═══════════════════════════════════
The following assertion was thrown while rebuilding dirty elements:
Assertion failed:
stack_frame.dart:180
line != '===== asynchronous gap ==========================='
"Got a stack frame from package:stack_trace, where a vm or web frame was expected. This can happen if FlutterError.demangleStackTrace was not set in an environment that propagates non-standard stack traces to the framework, such as during tests."
The relevant error-causing widget was
TweetPage
main.dart:30
When the exception was thrown, this was the stack
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 288:49      throw_
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 29:3        assertFailed
packages/flutter/src/foundation/stack_frame.dart 180:15                           fromStackTraceLine
dart-sdk/lib/internal/iterable.dart 393:20                                        moveNext
dart-sdk/lib/internal/iterable.dart 871:20                                        moveNext
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 831:20  next
dart-sdk/lib/_internal/js_dev_runtime/patch/core_patch.dart 555:14                of
dart-sdk/lib/core/iterable.dart 494:7                                             toList
packages/flutter/src/foundation/stack_frame.dart 76:37                            fromStackString
packages/flutter/src/foundation/assertions.dart 1075:54                           defaultStackFilter
packages/flutter/src/foundation/assertions.dart 1269:43                           _applyStackFilter
packages/flutter/src/foundation/assertions.dart 1245:17                           new
packages/flutter/src/foundation/assertions.dart 732:22                            debugFillProperties
packages/flutter/src/foundation/diagnostics.dart 2891:17                          <fn>
packages/flutter/src/foundation/diagnostics.dart 2893:16                          get builder
packages/flutter/src/foundation/assertions.dart 1290:56                           get builder
packages/flutter/src/foundation/diagnostics.dart 2905:77                          get emptyBodyDescription
packages/flutter/src/foundation/diagnostics.dart 1621:13                          <fn>
packages/flutter/src/foundation/diagnostics.dart 1646:21                          <fn>
packages/flutter/src/foundation/diagnostics.dart 1646:21                          <fn>
packages/flutter/src/foundation/diagnostics.dart 1649:14                          toJsonMap
packages/flutter/src/widgets/widget_inspector.dart 1652:18                        [_nodeToJson]
packages/flutter/src/widgets/widget_inspector.dart 929:44                         [_reportStructuredError]
packages/flutter/src/foundation/assertions.dart 1185:14                           reportError
packages/flutter/src/widgets/framework.dart 6628:16                               _reportException$
packages/flutter/src/widgets/framework.dart 5095:9                                performRebuild
packages/flutter/src/widgets/framework.dart 5251:11                               performRebuild
packages/flutter/src/widgets/framework.dart 4805:7                                rebuild
packages/flutter/src/widgets/framework.dart 2780:18                               buildScope
packages/flutter/src/widgets/binding.dart 903:9                                   drawFrame
Packages/flutter/src/widgets/binding.dart 903:9                                   drawFrame
packages/flutter/src/rendering/binding.dart 358:5                                 [_handlePersistentFrameCallback]
packages/flutter/src/scheduler/binding.dart 1284:15                               [_invokeFrameCallback]
packages/flutter/src/scheduler/binding.dart 1214:9                                handleDrawFrame
packages/flutter/src/scheduler/binding.dart 1072:5                                [_handleDrawFrame]
lib/_engine/engine/platform_dispatcher.dart 1236:13                               invoke
lib/_engine/engine/platform_dispatcher.dart 244:5                                 invokeOnDrawFrame
lib/_engine/engine/initialization.dart 190:45                                     <fn>
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 367:37  _checkAndCall
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 372:39  dcall
The element being rebuilt at the time was index 10 of 21: TweetPage
    dependencies: [UncontrolledProviderScope]
    state: _TweetPageState#b1d5c
════════════════════════════════════

I suspected the "userdat == null" conditinal statement, when the page loads at first it continuing loading until i reload. Thinking now, i suppose it should never be null, or i find a way to await it and load while it get the data(just finding solutions not sure).

I am getting the account

Any help provided will be appreciated.

0

There are 0 best solutions below