Skip to content

Got An Issue With SliverAppBar 'needsCompositing': is not true. #135486

Closed

Description

@AnkitFlutterDev

Is there an existing issue for this?

Steps to reproduce

I have implimanted SliverAppBar with CustomScrollView,in sometime(like once in 30)whenever i tried to navigate that page and tried to scroll i got ERROR:

══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
The following assertion was thrown during paint():
'package:flutter/src/material/flexible_space_bar.dart': Failed assertion: line 464 pos 12:
'needsCompositing': is not true.

Either the assertion indicates an error in the framework itself, or we should provide substantially
more information in this error message to help you determine and fix the underlying cause.
In either case, please report this assertion by filing a bug on GitHub:
  https://github.com/flutter/flutter/issues/new?template=2_bug.yml

The relevant error-causing widget was:
  FlexibleSpaceBar 

Expected results

Got the Expected result,the problem is i got error inside Debug console,UI works smoothly

Actual results

Got the Expected result,the problem is i got error inside Debug console,UI works smoothly

Code sample

Code

@override
  Widget build(BuildContext context) {
    return Consumer<ArticalProvider>(
      builder: (context, articalP, child) {
        return articalP.isLoading || articalP.articalData == null
            ? Scaffold(body: Center(child: CircularProgressIndicator()))
            : Builder(builder: (context) {
                final articalData = articalP.articalData!;
                final category = articalData.category;
                return Scaffold(
                    floatingActionButtonLocation:
                        FloatingActionButtonLocation.centerDocked,
                    floatingActionButton: _floatingButton(context, widget.id),
                    body: CustomScrollView(
                      controller: _scrollController,
                      physics: BouncingScrollPhysics(),
                      slivers: <Widget>[
                        SliverAppBar(
                          shadowColor: color00.withOpacity(.25),
                          pinned: true,
                          snap: false,
                          floating: false,
                          flexibleSpace: FlexibleSpaceBar(
                            background: MyCachedNetworkWidget(
                                imageUrl: articalData.thumbnailImage),
                          ),
                          expandedHeight: 308,
                          backgroundColor: primaryColor,
                          leading: IconButton(
                              onPressed: () {
                                Navigator.pop(context);
                              },
                              icon: Icon(Icons.arrow_back)),
                          title: Transform.translate(
                            offset: Offset(-20, 0),
                            child: Text(articalData.title, style: whiteBold18),
                          ),
                          actions: <Widget>[
                            Transform.translate(
                              offset: Offset(10, 0),
                              child: IconButton(
                                  onPressed: () {},
                                  icon: Icon(
                                    Icons.share_outlined,
                                    color: white,
                                  )),
                            ),
                            Consumer<BookmarkProvider>(
                              builder: (context, bookmarkP, child) =>
                                  IconButton(
                                      onPressed: () => Functionality.bookMark(
                                          context: context, id: widget.id),
                                      icon: Icon(
                                        bookmarkP.isBookmarked(widget.id)
                                            ? Icons.bookmark_outlined
                                            : Icons.bookmark_outline,
                                        color: white,
                                      )),
                            )
                          ],
                        ),
                        SliverList(
                            delegate: SliverChildListDelegate([
                          ListView(
                            shrinkWrap: true,
                            physics: NeverScrollableScrollPhysics(),
                            padding: EdgeInsets.zero,
                            children: [
                              Padding(
                                padding: const EdgeInsets.all(20)
                                    .copyWith(bottom: 0),
                                child: Column(
                                  children: [
                                    IntrinsicHeight(
                                      child: Row(
                                        children: [
                                          Container(
                                              width: vDividerSize,
                                              color: secColor),
                                          widthSpace10,
                                          Expanded(
                                            child: Text(articalData.title,
                                                style: blackSemiBold16),
                                          ),
                                        ],
                                      ),
                                    ),
                                    heightSpace5,
                                    Row(
                                      children: [
                                        MyCachedNetworkWidget(
                                          imageUrl: category.image,
                                          height: 2.15.h,
                                          width: 2.h,
                                        ),
                                        Padding(
                                          padding: const EdgeInsets.symmetric(
                                              horizontal: 5),
                                          child: Text(category.name,
                                              style: color94Medium14),
                                        ),
                                        Image.asset(clockIcon,
                                            height: IconSize.tiny),
                                        Padding(
                                          padding: const EdgeInsets.symmetric(
                                              horizontal: 5),
                                          child: Text(
                                              formatTimeAgo(
                                                  articalData.createdAt),
                                              style: color94Medium14),
                                        ),
                                        Image.asset(viewIcon,
                                            height: IconSize.tiny),
                                        Padding(
                                          padding: const EdgeInsets.symmetric(
                                              horizontal: 5),
                                          child: Text(
                                              '${articalData.viewCount} view',
                                              style: color94Medium14),
                                        ),
                                      ],
                                    ),
                                    heightSpace20,
                                    HtmlWidget(articalData.description),
                                    heightSpace20,
                                  ],
                                ),
                              ),
                              ..._relatedNews(articalP)
                            ],
                          )
                        ]))
                      ],
                    ));
              });
      },
    );
  }

Screenshots or Video

Screenshots / Video demonstration

[Upload media here]

Logs

Log

══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
The following assertion was thrown during paint():
'package:flutter/src/material/flexible_space_bar.dart': Failed assertion: line 464 pos 12:
'needsCompositing': is not true.

Either the assertion indicates an error in the framework itself, or we should provide substantially
more information in this error message to help you determine and fix the underlying cause.
In either case, please report this assertion by filing a bug on GitHub:
  https://github.com/flutter/flutter/issues/new?template=2_bug.yml

The relevant error-causing widget was:
  FlexibleSpaceBar
  FlexibleSpaceBar:file:///Users/ankitthummar/Desktop/fl_news_feed/lib/pages/home/artical_detail/image_artical.dart:62:42

When the exception was thrown, this was the stack:
#2      _RenderFlexibleSpaceHeaderOpacity.paint (package:flutter/src/material/flexible_space_bar.dart:464:12)
flexible_space_bar.dart:464
#3      RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:3155:7)
object.dart:3155
#4      PaintingContext.paintChild (package:flutter/src/rendering/object.dart:252:13)
object.dart:252
#5      RenderBoxContainerDefaultsMixin.defaultPaint (package:flutter/src/rendering/box.dart:2875:15)
box.dart:2875
#6      RenderStack.paintStack (package:flutter/src/rendering/stack.dart:639:5)
stack.dart:639
#7      PaintingContext.pushClipRect.<anonymous closure> (package:flutter/src/rendering/object.dart:535:83)
object.dart:535
#8      ClipContext._clipAndPaint (package:flutter/src/painting/clip.dart:25:12)
clip.dart:25
#9      ClipContext.clipRectAndPaint (package:flutter/src/painting/clip.dart:53:5)
clip.dart:53
#10     PaintingContext.pushClipRect (package:flutter/src/rendering/object.dart:535:7)
object.dart:535
#11     RenderStack.paint (package:flutter/src/rendering/stack.dart:645:38)
stack.dart:645
#12     RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:3155:7)
object.dart:3155
#13     PaintingContext.paintChild (package:flutter/src/rendering/object.dart:252:13)
object.dart:252
#14     RenderProxyBoxMixin.paint (package:flutter/src/rendering/proxy_box.dart:129:13)
proxy_box.dart:129
#15     PaintingContext.pushClipRect.<anonymous closure> (package:flutter/src/rendering/object.dart:535:83)
object.dart:535
#16     ClipContext._clipAndPaint (package:flutter/src/painting/clip.dart:25:12)
clip.dart:25
#17     ClipContext.clipRectAndPaint (package:flutter/src/painting/clip.dart:53:5)
clip.dart:53
#18     PaintingContext.pushClipRect (package:flutter/src/rendering/object.dart:535:7)
object.dart:535
#19     RenderClipRect.paint (package:flutter/src/rendering/proxy_box.dart:1530:25)
proxy_box.dart:1530
#20     RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:3155:7)
object.dart:3155
#21     PaintingContext.paintChild (package:flutter/src/rendering/object.dart:252:13)
object.dart:252
#22     _RenderLayoutBuilder.paint (package:flutter/src/widgets/layout_builder.dart:338:15)
layout_builder.dart:338
#23     RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:3155:7)
object.dart:3155
#24     PaintingContext.paintChild (package:flutter/src/rendering/object.dart:252:13)
object.dart:252
#25     RenderProxyBoxMixin.paint (package:flutter/src/rendering/proxy_box.dart:129:13)
proxy_box.dart:129
#26     RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:3155:7)
object.dart:3155
#27     PaintingContext.paintChild (package:flutter/src/rendering/object.dart:252:13)
object.dart:252
#28     RenderBoxContainerDefaultsMixin.defaultPaint (package:flutter/src/rendering/box.dart:2875:15)
box.dart:2875

Flutter Doctor output

flutter doctor -v


[✓] Flutter (Channel stable, 3.13.2, on macOS 13.5.1 22G90 darwin-arm64, locale
    en-IN)
    • Flutter version 3.13.2 on channel stable at /Users/ankitthummar/Flutter
      Install/Flutter 3.13.2/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision ff5b5b5fa6 (5 weeks ago), 2023-08-24 08:12:28 -0500
    • Engine revision b20183e040
    • Dart version 3.1.0
    • DevTools version 2.25.0

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.2)
    • Android SDK at /Users/ankitthummar/Library/Android/sdk
    • Platform android-33, build-tools 33.0.2
    • Java binary at: /Applications/Android
      Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build
      17.0.6+0-17.0.6b802.4-9586694)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.3)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14E222b
    • CocoaPods version 1.12.1

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2022.2)
    • Android Studio at /Applications/Android Studio.app/Contents
    • 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
      17.0.6+0-17.0.6b802.4-9586694)

[✓] VS Code (version 1.82.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.72.0

[✓] Connected device (3 available)
    • iPhone 14 Pro Max (mobile) • 72B79D2F-D187-4C2F-B4B6-DB5E73BFA232 • ios            • com.apple.CoreSimulator.SimRuntime.iOS-16-4 (simulator)
    • macOS (desktop)            • macos                                • darwin-arm64   • macOS 13.5.1 22G90 darwin-arm64
    • Chrome (web)               • chrome                               • web-javascript • Google Chrome 117.0.5938.92

[✓] Network resources
    • All expected network resources are available.

• No issues found!
ankitthummar@192 ~ % 

Activity

  1. changed the title [-]Got An Issue With SliverAppBar [/-] [+]Got An Issue With SliverAppBar 'needsCompositing': is not true.[/+] on Sep 26, 2023
  2. dam-ease commented on Sep 26, 2023

    @dam-ease

    Hi @At738343. Please can you provide a minimal complete reproducible code sample that doesn’t include 3rd party plugins or complex production code (a single main.dart file)?
    Thank you

  3. added
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Sep 26, 2023
  4. AnkitFlutterDev commented on Sep 26, 2023

    @AnkitFlutterDev
    Author

    @dam-ease sure,

    import 'utils/global.dart' as global;

    void main() async {
    WidgetsFlutterBinding.ensureInitialized();
    SystemChrome.setPreferredOrientations(
    [DeviceOrientation.portraitUp, DeviceOrientation.portraitDown]);
    await Firebase.initializeApp();
    SharedPreferences prefs = await SharedPreferences.getInstance();
    global.token = prefs.getString('token');
    global.hasSeenOnBoard = prefs.getBool("hasSeenOnBoard") ?? false;

    runApp(MultiProvider(providers: [
    ChangeNotifierProvider(create: () => BottomNavigationProvider()),
    ChangeNotifierProvider(create: (
    ) => HelperProvider()),
    ChangeNotifierProvider(create: () => HomeProvider()),
    ChangeNotifierProvider(create: (
    ) => SearchProvider()),
    ChangeNotifierProvider(create: () => BookmarkProvider()),
    ChangeNotifierProvider(create: (
    ) => ArticalProvider()),
    ChangeNotifierProvider(create: (_) => CommentProvider()),
    ], child: MyApp()));
    }

    class MyApp extends StatelessWidget {
    const MyApp({super.key});

    @OverRide
    Widget build(BuildContext context) {
    return Sizer(
    builder: (context, orientation, deviceType) => AnnotatedRegion(
    value: SystemUiOverlayStyle(statusBarBrightness: Brightness.dark),
    child: MaterialApp(
    debugShowCheckedModeBanner: false,
    title: 'Flutter Demo',
    theme: ThemeData(
    scaffoldBackgroundColor: scaffoldColor,
    primarySwatch: createMaterialColor(primaryColor),
    splashColor: transparent,
    highlightColor: transparent,
    iconTheme: IconThemeData(size: IconSize.regular),
    ),
    initialRoute: '/SplashPage',
    // initialRoute: '/BottomNavigation',
    onGenerateRoute: (settings) {
    final args = settings.arguments;
    switch (settings.name) {
    case '/SplashPage':
    return PageTransition(
    isIos: true,
    child: SplashPage(),
    type: PageTransitionType.rightToLeft,
    );
    case '/OnBoardingPage':
    return PageTransition(
    isIos: true,
    child: const OnBoardingPage(),
    type: PageTransitionType.rightToLeft,
    );
    etc...

  5. removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Sep 26, 2023
  6. AnkitFlutterDev commented on Sep 26, 2023

    @AnkitFlutterDev
    Author

    i have used this plugins in my project

    flutter_spinkit: ^5.2.0
    page_transition: ^2.0.9
    sizer: ^2.0.15
    smooth_page_indicator: ^1.1.0
    intl_phone_number_input: ^0.7.3+1
    pinput: ^3.0.1
    timer_count_down: ^2.2.2
    provider: ^6.0.5
    carousel_slider: ^4.2.1
    shared_preferences: ^2.2.1
    intl: ^0.18.1
    cached_network_image: ^3.2.3
    firebase_auth: ^4.9.0
    firebase_core: ^2.15.1
    google_sign_in: ^6.1.5
    sign_in_with_apple: ^5.0.0
    flutter_widget_from_html: ^0.10.5+3

  7. dam-ease commented on Sep 27, 2023

    @dam-ease

    Hi @At738343. Thanks for your response. The code sample you attached makes use of some 3rd party plugins. I tried coming up with one using a part of the code in the original comment that seems to cause this issue but can't seem to reproduce this on my end. Can you try ou this sample to see if this issue produces on your end? If not kindly adjust to your use case that produces the error.
    Thank you.

    Code Sample

    import 'package:flutter/material.dart';
    
    void main() {
      runApp(const MyApp());
    }
    
    class MyApp extends StatelessWidget {
      const MyApp({super.key});
    
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          title: 'Flutter Demo',
          theme: ThemeData(
            colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
            useMaterial3: true,
          ),
          home: const MyHomePage(title: 'Flutter Demo Home Page'),
        );
      }
    }
    
    class MyHomePage extends StatefulWidget {
      const MyHomePage({super.key, required this.title});
    
      final String title;
    
      @override
      State<MyHomePage> createState() => _MyHomePageState();
    }
    
    class _MyHomePageState extends State<MyHomePage> {
      ScrollController _scrollController = ScrollController();
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
          body: CustomScrollView(
              controller: _scrollController,
              physics: const BouncingScrollPhysics(),
              slivers: <Widget>[
                SliverAppBar(
                    pinned: true,
                    snap: false,
                    floating: false,
                    flexibleSpace: FlexibleSpaceBar(
                        background: Image.asset("assets/images/img.png")),
                    expandedHeight: 308,
                    leading: IconButton(
                        onPressed: () {}, icon: const Icon(Icons.arrow_back)),
                    title: Transform.translate(
                      offset: const Offset(-20, 0),
                      child: const Text("articalData.title",
                          style: TextStyle(color: Colors.white)),
                    ),
                    actions: <Widget>[
                      Transform.translate(
                        offset: const Offset(10, 0),
                        child: IconButton(
                            onPressed: () {},
                            icon: const Icon(
                              Icons.share_outlined,
                              color: Colors.white,
                            )),
                      )
                    ])
              ]),
        );
      }
    }

    flutter doctor -v

    [✓] Flutter (Channel stable, 3.13.5, on macOS 13.0 22A380 darwin-arm64, locale
        en-NG)
        • Flutter version 3.13.5 on channel stable at
          /Users/damilolaalimi/sdks/flutter
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision 12fccda598 (8 days ago), 2023-09-19 13:56:11 -0700
        • Engine revision bd986c5ed2
        • Dart version 3.1.2
        • DevTools version 2.25.0
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
        • Android SDK at /Users/damilolaalimi/Library/Android/sdk
        • Platform android-34, build-tools 34.0.0
        • ANDROID_HOME = /Users/damilolaalimi/Library/Android/sdk
        • Java binary at: /Applications/Android
          Studio.app/Contents/jbr/Contents/Home/bin/java
        • Java version OpenJDK Runtime Environment (build
          17.0.6+0-17.0.6b802.4-9586694)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 14.3.1)
        • Xcode at /Applications/Xcode.app/Contents/Developer
        • Build 14E300c
        • CocoaPods version 1.12.1
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] Android Studio (version 2022.2)
        • Android Studio at /Applications/Android Studio.app/Contents
        • 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
          17.0.6+0-17.0.6b802.4-9586694)
    
    [✓] VS Code (version 1.82.2)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.50.0
    
    [✓] Connected device (4 available)
        • sdk gphone64 arm64 (mobile) • emulator-5554                        •
          android-arm64  • Android 14 (API 34) (emulator)
        • iPhone 14 Pro (mobile)      • 6548B0D1-7674-4306-9852-198C465F1104 • ios
          • com.apple.CoreSimulator.SimRuntime.iOS-16-4 (simulator)
        • macOS (desktop)             • macos                                •
          darwin-arm64   • macOS 13.0 22A380 darwin-arm64
        • Chrome (web)                • chrome                               •
          web-javascript • Google Chrome 116.0.5845.187
    
    [✓] Network resources
        • All expected network resources are available.
    
    • No issues found!
    

  8. added
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Sep 27, 2023
  9. AnkitFlutterDev commented on Sep 27, 2023

    @AnkitFlutterDev
    Author

    I have got the Solution,Tnx for ur Support @dam-ease

  10. removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Sep 27, 2023
  11. CardosoShlomo commented on Sep 27, 2023

    @CardosoShlomo

    @At738343 can you share the solution?

  12. added
    r: solvedIssue is closed as solved
    and removed
    in triagePresently being triaged by the triage team
    on Sep 28, 2023
  13. github-actions commented on Oct 12, 2023

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  14. locked as resolved and limited conversation to collaborators on Oct 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    r: solvedIssue is closed as solved

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions