Skip to content

NavigationRailDestination icons are incorrectly aligned with labelType set to NavigationRailLabelType.none #97753

@CodesbyRobot

Description

@CodesbyRobot

Steps to Reproduce

This was checked inside DartPad and the behaviour is the same so it doesn't require me to run 'flutter doctor' or any flutter commands; the bug is also quite simple.

  1. Use the Stack widget inside the icon label in the NavigationRailDestionation in a NavigationRail Widget.
  2. Ensure that the labeltype of NavigationRail is set to none (labelType: NavigationRailLabelType.none). See code below for more details.
  3. The Stack Widget creates an unwanted spacing and doesn't behave as expected.
  4. See the code below in dartpad for a visual demostration. Code is Commented.

Expected results:
Run Dart Pad linked below.

Actual results:
Run Dart Pad linked below.

Code sample
import 'package:flutter/material.dart';

const Color darkBlue = Color.fromARGB(255, 18, 32, 47);

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData.dark().copyWith(
        scaffoldBackgroundColor: darkBlue,
      ),
      debugShowCheckedModeBanner: false,
      home: const Scaffold(
        body: Center(
          child: TestScreenBody(),
        ),
      ),
    );
  }
}
class TestScreenBody extends StatelessWidget {
  const TestScreenBody({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Column(
      mainAxisSize: MainAxisSize.min,
      children: [
        const Spacer(
          flex: 1,
        ),
        Flexible(
          flex: 9,
          child: Row(
            mainAxisSize: MainAxisSize.min,
            children: [
              Flexible(
                flex: 9,
                child: Padding(
                  padding: const EdgeInsets.all(15),
                  /*
                  We see the Stack Widget behaving properly when using inside a generic 'icon:'
                  In this example an IconButton.
                  */
                  child: IconButton(
                    onPressed: null,
                    icon: Stack(
                      children: const [
                        Icon(Icons.umbrella),
                        Positioned(
                          top: 0,
                          right: 0,
                          child: Text(
                            'Test',
                            style: TextStyle(fontSize: 10, color: Colors.red),
                          ),
                        ),
                      ],
                    ),
                  ),
                ),
              ),
              Flexible(
                flex: 3,
                child: NavigationRail(
                    labelType: NavigationRailLabelType.none, /* <-------------- ONLY HAPPENS WHEN LABEL TYPE IS NONE */
                    destinations: [
                      NavigationRailDestination(
                        /*
                  We are inside the NavigationRail.
                  We see the Stack Widget behaving in an unwanted way inside the 'icon:', 
                  there exist some unwanted spacing.
                  */
                        icon: Stack(
                          children: const [
                            Icon(Icons.umbrella),
                            Positioned(
                              top: 0,
                              right: 0,
                              child: Text(
                                'Test',
                                style:
                                    TextStyle(fontSize: 10, color: Colors.red),
                              ),
                            ),
                          ],
                        ),
                        label: const Text('Bugged'),
                      ),
                      const NavigationRailDestination(
                        /*
                   We are inside the NavigationRail.
                   Normal Icon given to the 'icon:' widget behaves as expected.
                  */
                        icon: Icon(Icons.umbrella),
                        label: Text('Umbrella'),
                      ),
                      NavigationRailDestination(
                        /*
                  We are inside the NavigationRail.
                  Temporary Fix is to wrap it inside a Center Widget
                  */
                        icon: Center(
                          child: Stack(
                            children: const [
                              Icon(Icons.umbrella),
                              Positioned(
                                top: 0,
                                right: 0,
                                child: Text(
                                  'Test',
                                  style: TextStyle(
                                      fontSize: 10, color: Colors.red),
                                ),
                              ),
                            ],
                          ),
                        ),
                        label: const Text('Bug'),
                      ),
                    ],
                    selectedIndex: 0),
              ),
            ],
          ),
        ),
      ],
    );
  }
}
DartPad Link

https://dartpad.dev/?id=d1766c74b8bfe2bd81d09905063845a3

Temporary Solution
Wrap the Stack Widget inside a Center Widget.

Metadata

Metadata

Assignees

Labels

c: regressionIt was better in the past than it is nowf: material designflutter/packages/flutter/material repository.found in release: 2.10Found to occur in 2.10found in release: 2.11Found to occur in 2.11frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onr: fixedIssue is closed as already fixed in a newer version

Type

No type

Projects

Status

Done (PR merged)

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions