flutter - PlatformAppBar remains transparent until scrolling, even with explicit backgroundColor [iOS] - Stack Overflow

admin2025-04-17  2

Description

Note: This issue began occurring after I updated Flutter to version 3.27.3.

I'm encountering an issue on iOS where the CupertinoNavigationBar (provided by PlatformAppBar) remains transparent or partially transparent until the user scrolls. Once scrolling begins, the specified background color appears as expected.

I've tried the following, but the issue persists:

  • Setting a fully opaque backgroundColor directly in the cupertino: (_, __) => CupertinoNavigationBarData(...).
  • Using transitionBetweenRoutes: false.
  • Removing extra SafeArea widgets and ensuring no overlapping content.
  • Confirming I'm not using a large-title CupertinoSliverNavigationBar.
  • Disabling extendBodyBehindAppBar.
  • Testing a minimal code snippet with just PlatformScaffold + PlatformAppBar.

Despite all these steps, the bar still appears transparent on the initial frame until the user scrolls.


Screenshots

Here you can see the navigation bar appears transparent at first and After scrolling, it becomes fully colored.

Before Scrolling

After Scrolling

Steps to Reproduce

  1. Create a Flutter project with flutter_platform_widgets (version 7.0.1).
  2. Use the following minimal code as your home page:
import 'package:flutter/material.dart';
import 'package:flutter_platform_widgets/flutter_platform_widgets.dart';
class TestPage extends StatelessWidget {
  const TestPage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return PlatformScaffold(
      appBar: PlatformAppBar(
        cupertino: (_, __) => CupertinoNavigationBarData(
          backgroundColor: Colors.blueGrey,
          transitionBetweenRoutes: false,
          title: const Text('iOS Title'),
        ),
      ),
      body: ListView(
        children: List.generate(
          30,
          (index) => SizedBox(
            height: 50,
            child: Center(
              child: Text('Item $index'),
            ),
          ),
        ),
      ),
    );
  }
}

Environment

  • Flutter version: 3.27.3
  • Dart version: 3.6.1
  • flutter_platform_widgets version: 7.0.1
  • Target platform: iOS (tested on iOS simulator and/or real device)
  • Device/Simulator version: iPhone 14, iOS 16 (for example)

Expected Behavior

The navigation bar should appear with the specified background color immediately when the page loads—fully opaque and without any translucent effect.


Actual Behavior

On iOS, the navigation bar looks transparent (the list items can be seen behind it) until the user starts to scroll. Once scrolling begins, the navbar background color becomes fully opaque.

转载请注明原文地址:http://anycun.com/QandA/1744884060a88984.html