Skip to content

Ink Widget without Material Ancestor  #171667

@HachichaRacem

Description

@HachichaRacem

Steps to reproduce

  1. Implement a simple nested navigation example
  2. Add a ListView with custom cards widget created by Ink, InkWell and a container

Expected results

It is expected that the custom widget not to "decompose" as the video shows below which is clearly seen in the transition between the screens

NOTE
Separately adding Materialor Scaffold to the _HomeScreenMain and _HomeScreenSecond widgets is a workaround but in a production app with a deeper nested navigation it would be unpractical to keep adding scaffolds and/or materials and it doesn't seem right, or am I missing something here?

Actual results

With image

scroll_behavior.mp4

Without image

Replaced Container's child with a SizedBox(height: 200)

scroll_behavior_2.mp4

Code sample

Code sample

homeScreen.dart

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

final homeNavigationKey = GlobalKey<NavigatorState>();

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

  @override
  Widget build(BuildContext context) {
    return Navigator(
      key: homeNavigationKey,
      onGenerateRoute: (settings) {
        WidgetBuilder builder;
        switch (settings.name) {
          case '/':
            builder = (_) => const _HomeScreenMain();
          case '/second':
            builder = (_) => const _HomeScreenSecond();
          default:
            builder = (_) => const _HomeScreenMain();
        }
        return CupertinoPageRoute<void>(settings: settings, builder: builder);
      },
    );
  }
}

class _HomeScreenSecond extends StatelessWidget {
  const _HomeScreenSecond();
  @override
  Widget build(BuildContext context) {
    return Center(
      child: TextButton(
        onPressed: () => homeNavigationKey.currentState?.pop(),
        child: const Text("Return back"),
      ),
    );
  }
}

class _CustomCard extends StatelessWidget {
  final int index;
  static const BorderRadius _borderRadius = BorderRadius.all(
    Radius.circular(16),
  );
  const _CustomCard(this.index);
  @override
  Widget build(BuildContext context) {
    return Ink(
      decoration: BoxDecoration(
        borderRadius: _borderRadius,
        color: Theme.of(context).colorScheme.primaryContainer,
        boxShadow: kElevationToShadow[3],
      ),
      child: InkWell(
        onTap: () => homeNavigationKey.currentState?.pushNamed('/second'),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Container(
              clipBehavior: Clip.hardEdge,
              decoration: BoxDecoration(borderRadius: _borderRadius),
              child: Image.asset(
                "assets/image.jpg",
                fit: BoxFit.cover,
                height: 200,
                cacheHeight: 200,
                cacheWidth: MediaQuery.of(context).size.width.toInt(),
              ),
            ),
            Padding(
              padding: const EdgeInsets.all(22),
              child: Text(
                "$index",
                style: Theme.of(context).textTheme.titleMedium?.copyWith(
                  fontWeight: FontWeight.bold,
                  color: Theme.of(context).colorScheme.onPrimaryContainer,
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}

class _HomeScreenMain extends StatelessWidget {
  const _HomeScreenMain();
  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: const EdgeInsets.all(16.0),
      child: ListView.separated(
        itemCount: 10,
        separatorBuilder: (context, index) => const SizedBox(height: 16),
        itemBuilder: (_, index) {
          return _CustomCard(index + 1);
        },
      ),
    );
  }
}

main.dart

void main() {
  runApp(const MainApp());
}

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

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      home: Scaffold(body: SafeArea(child: HomeScreen())),
    );
  }
}

Screenshots or Video

Logs

No response

Flutter Doctor output

Doctor output
[✓] Flutter (Channel stable, 3.32.5, on Microsoft Windows [Version 10.0.26100.4351], locale en-US) [465ms]
    • Flutter version 3.32.5 on channel stable at C:\Flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision fcf2c11572 (11 days ago), 2025-06-24 11:44:07 -0700
    • Engine revision dd93de6fb1
    • Dart version 3.8.1
    • DevTools version 2.45.1

[✓] Windows Version (11 Pro 64-bit, 24H2, 2009) [2.4s]

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0) [1,764ms]
    • Android SDK at C:\Users\hrace\AppData\Local\Android\sdk
    • Platform android-35, build-tools 34.0.0
    • Java binary at: C:\Program Files\Android Studio\jbr\bin\java
      This is the JDK bundled with the latest Android Studio installation on this machine.
      To manually set the JDK path, use: `flutter config --jdk-dir="path/to/jdk"`.
    • Java version OpenJDK Runtime Environment (build 17.0.9+0--11185874)
    • All Android licenses accepted.

[✓] Chrome - develop for the web [212ms]
    • CHROME_EXECUTABLE = C:\Program Files\BraveSoftware\Brave-Browser\Application\brave.exe

[✓] Visual Studio - develop Windows apps (Visual Studio Build Tools 2022 17.13.6) [212ms]
    • Visual Studio at C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools
    • Visual Studio Build Tools 2022 version 17.13.35931.197
    • Windows 10 SDK version 10.0.22621.0

[✓] Android Studio (version 2023.2) [13ms]
    • Android Studio at C:\Program Files\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 17.0.9+0--11185874)

[✓] VS Code (version 1.101.2) [12ms]
    • VS Code at C:\Users\hrace\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.114.0

[✓] Connected device (4 available) [251ms]
    • CPH1937 (mobile)  • 79ace227 • android-arm64  • Android 11 (API 30)
    • Windows (desktop) • windows  • windows-x64    • Microsoft Windows [Version 10.0.26100.4351]
    • Chrome (web)      • chrome   • web-javascript • unknown
    • Edge (web)        • edge     • web-javascript • Microsoft Edge 138.0.3351.55

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

• No issues found!

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Issues that are less important to the Flutter projectc: proposalA detailed proposal for a change to Flutterd: api docsIssues with https://api.flutter.dev/f: material designflutter/packages/flutter/material repository.frameworkflutter/packages/flutter repository. See also f: labels.team-designOwned by Design Languages teamtriaged-designTriaged by Design Languages teamworkaround availableThere is a workaround available to overcome the issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy