<p dir="auto"><code class="notranslate">firebase_database: 1.0.2</code></p>
<h2 dir="auto">Steps to Reproduce</h2>
<p dir="auto">Run a simple Flutter app:<br>
<a href="https://gist.github.com/dotdoom/5180eb27084afb3b71db44f2201c6877">https://gist.github.com/dotdoom/5180eb27084afb3b71db44f2201c6877</a></p>
<p dir="auto">Most important part is (for history purposes):</p>
<div class="highlight highlight-source-dart notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="(await FirebaseDatabase.instance
            .reference()
            .child(subpath)
            .orderByChild('year')
            .limitToFirst(3)
            .onValue
            .first)
        .snapshot
        .value
        .values
        .forEach((v) =&gt; debugPrint(v['year'].toString()));"><pre class="notranslate">(<span class="pl-k">await</span> <span class="pl-c1">FirebaseDatabase</span>.instance
            .<span class="pl-en">reference</span>()
            .<span class="pl-en">child</span>(subpath)
            .<span class="pl-en">orderByChild</span>(<span class="pl-s">'year'</span>)
            .<span class="pl-en">limitToFirst</span>(<span class="pl-c1">3</span>)
            .onValue
            .first)
        .snapshot
        .value
        .values
        .<span class="pl-en">forEach</span>((v) <span class="pl-k">=&gt;</span> <span class="pl-en">debugPrint</span>(v[<span class="pl-s">'year'</span>].<span class="pl-en">toString</span>()));</pre></div>
<p dir="auto">The output is indeed the first 3 entries of a sorted list, but the entries themselves are not sorted:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="I/flutter ( 6096): Sorted years:
I/flutter ( 6096): 1856
I/flutter ( 6096): 1867
I/flutter ( 6096): 1564"><pre class="notranslate"><code class="notranslate">I/flutter ( 6096): Sorted years:
I/flutter ( 6096): 1856
I/flutter ( 6096): 1867
I/flutter ( 6096): 1564
</code></pre></div>
<p dir="auto"><code class="notranslate">limitToFirst</code> does not affect the order and is only to demonstrate that Firebase server gets the correct request.</p>
<p dir="auto">I suspect there might be some issue when <a href="https://github.com/flutter/plugins/blob/cd4829a6cf3afcf687fd064f18a028b519644d66/packages/firebase_database/android/src/main/java/io/flutter/plugins/firebase/database/FirebaseDatabasePlugin.java#L185">transferring data between Java and Dart</a> where the map ordering is lost. Unfortunately it's buried too deep for me to find quickly, so I hope someone with more experience in the MethodChannel mechanism can help me out. The type of the map in Flutter app is <code class="notranslate">_InternalLinkedHashMap</code> which IIUC is supposed to be ordered.</p>
<h2 dir="auto">Logs</h2>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="[✓] Flutter (Channel beta, v0.5.1, on Linux, locale en_US.UTF-8)
    • Flutter version 0.5.1 at /home/artem/pkg/flutter
    • Framework revision c7ea3ca377 (7 weeks ago), 2018-05-29 21:07:33 +0200
    • Engine revision 1ed25ca7b7
    • Dart version 2.0.0-dev.58.0.flutter-f981f09760

[✓] Android toolchain - develop for Android devices (Android SDK 27.0.0)
    • Android SDK at /home/artem/Android/Sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-27, build-tools 27.0.0
    • Java binary at: /home/artem/pkg/android-studio/jre/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1024-b01)
    • All Android licenses accepted.

[✓] Android Studio (version 3.1)
    • Android Studio at /home/artem/pkg/android-studio
    ✗ Flutter plugin not installed; this adds Flutter specific functionality.
    ✗ Dart plugin not installed; this adds Dart specific functionality.
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1024-b01)

[!] VS Code (version 1.25.1)
    • VS Code at /usr/share/code
    • Flutter extension not installed; install from
      https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

[✓] Connected devices (1 available)
    • Android SDK built for x86 • emulator-5554 • android-x86 • Android 8.1.0 (API 27) (emulator)

! Doctor found issues in 1 category."><pre class="notranslate"><code class="notranslate">[✓] Flutter (Channel beta, v0.5.1, on Linux, locale en_US.UTF-8)
    • Flutter version 0.5.1 at /home/artem/pkg/flutter
    • Framework revision c7ea3ca377 (7 weeks ago), 2018-05-29 21:07:33 +0200
    • Engine revision 1ed25ca7b7
    • Dart version 2.0.0-dev.58.0.flutter-f981f09760

[✓] Android toolchain - develop for Android devices (Android SDK 27.0.0)
    • Android SDK at /home/artem/Android/Sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-27, build-tools 27.0.0
    • Java binary at: /home/artem/pkg/android-studio/jre/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1024-b01)
    • All Android licenses accepted.

[✓] Android Studio (version 3.1)
    • Android Studio at /home/artem/pkg/android-studio
    ✗ Flutter plugin not installed; this adds Flutter specific functionality.
    ✗ Dart plugin not installed; this adds Dart specific functionality.
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1024-b01)

[!] VS Code (version 1.25.1)
    • VS Code at /usr/share/code
    • Flutter extension not installed; install from
      https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

[✓] Connected devices (1 available)
    • Android SDK built for x86 • emulator-5554 • android-x86 • Android 8.1.0 (API 27) (emulator)

! Doctor found issues in 1 category.
</code></pre></div>
<p dir="auto">I believe that the cause is that the bar's state allocates animation controllers for each item when the state is first constructed, but it doesn't create new controllers when the state updates with more items.</p>
<h2 dir="auto">Steps to Reproduce</h2>
<p dir="auto">Create a nav bar with 3 items.</p>
<p dir="auto">Increase the number of items to 4.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="RangeError(index): invalid value: not in range 0..2, inclusive: 3."><pre class="notranslate"><code class="notranslate">RangeError(index): invalid value: not in range 0..2, inclusive: 3.
</code></pre></div>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="## Logs
I/flutter (27323): ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
I/flutter (27323): The following RangeError was thrown building BottomNavigationBar(dirty, state:
I/flutter (27323): _BottomNavigationBarState#68e58(tickers: tracking 3 tickers)):
I/flutter (27323): RangeError (index): Invalid value: Not in range 0..2, inclusive: 3
I/flutter (27323): 
I/flutter (27323): When the exception was thrown, this was the stack:
I/flutter (27323): #0      List.[] (dart:core-patch/dart:core/growable_array.dart:141)
I/flutter (27323): #1      _BottomNavigationBarState._createTiles (package:flutter/src/material/bottom_navigation_bar.dart:411:26)
I/flutter (27323): #2      _BottomNavigationBarState.build (package:flutter/src/material/bottom_navigation_bar.dart:477:45)
I/flutter (27323): #3      StatefulElement.build (package:flutter/src/widgets/framework.dart:3690:27)
I/flutter (27323): #4      ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3602:15)
I/flutter (27323): #5      Element.rebuild (package:flutter/src/widgets/framework.dart:3463:5)
I/flutter (27323): #6      StatefulElement.update (package:flutter/src/widgets/framework.dart:3737:5)
I/flutter (27323): #7      Element.updateChild (package:flutter/src/widgets/framework.dart:2667:15)
I/flutter (27323): #8      ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3613:16)
I/flutter (27323): #9      Element.rebuild (package:flutter/src/widgets/framework.dart:3463:5)
I/flutter (27323): #10     ProxyElement.update (package:flutter/src/widgets/framework.dart:3847:5)
I/flutter (27323): #11     Element.updateChild (package:flutter/src/widgets/framework.dart:2667:15)
I/flutter (27323): #12     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3613:16)
I/flutter (27323): #13     Element.rebuild (package:flutter/src/widgets/framework.dart:3463:5)
I/flutter (27323): #14     ProxyElement.update (package:flutter/src/widgets/framework.dart:3847:5)
I/flutter (27323): #15     Element.updateChild (package:flutter/src/widgets/framework.dart:2667:15)
I/flutter (27323): #16     RenderObjectElement.updateChildren (package:flutter/src/widgets/framework.dart:4317:32)
I/flutter (27323): #17     MultiChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4703:17)
I/flutter (27323): #18     Element.updateChild (package:flutter/src/widgets/framework.dart:2667:15)
I/flutter (27323): #19     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3613:16)
I/flutter (27323): #20     Element.rebuild (package:flutter/src/widgets/framework.dart:3463:5)
I/flutter (27323): #21     ProxyElement.update (package:flutter/src/widgets/framework.dart:3847:5)
I/flutter (27323): #22     Element.updateChild (package:flutter/src/widgets/framework.dart:2667:15)
I/flutter (27323): #23     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3613:16)
I/flutter (27323): #24     Element.rebuild (package:flutter/src/widgets/framework.dart:3463:5)
I/flutter (27323): #25     StatefulElement.update (package:flutter/src/widgets/framework.dart:3737:5)
I/flutter (27323): #26     Element.updateChild (package:flutter/src/widgets/framework.dart:2667:15)
I/flutter (27323): #27     SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4595:14)
I/flutter (27323): #28     Element.updateChild (package:flutter/src/widgets/framework.dart:2667:15)
I/flutter (27323): #29     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3613:16)
I/flutter (27323): #30     Element.rebuild (package:flutter/src/widgets/framework.dart:3463:5)
I/flutter (27323): #31     StatelessElement.update (package:flutter/src/widgets/framework.dart:3662:5)
I/flutter (27323): #32     Element.updateChild (package:flutter/src/widgets/framework.dart:2667:15)
I/flutter (27323): #33     SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4595:14)
I/flutter (27323): #34     Element.updateChild (package:flutter/src/widgets/framework.dart:2667:15)
I/flutter (27323): #35     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3613:16)
I/flutter (27323): #36     Element.rebuild (package:flutter/src/widgets/framework.dart:3463:5)
I/flutter (27323): #37     StatefulElement.update (package:flutter/src/widgets/framework.dart:3737:5)
I/flutter (27323): #38     Element.updateChild (package:flutter/src/widgets/framework.dart:2667:15)
I/flutter (27323): #39     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3613:16)
I/flutter (27323): #40     Element.rebuild (package:flutter/src/widgets/framework.dart:3463:5)
I/flutter (27323): #41     StatefulElement.update (package:flutter/src/widgets/framework.dart:3737:5)
I/flutter (27323): #42     Element.updateChild (package:flutter/src/widgets/framework.dart:2667:15)
I/flutter (27323): #43     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3613:16)
I/flutter (27323): #44     Element.rebuild (package:flutter/src/widgets/framework.dart:3463:5)
I/flutter (27323): #45     ProxyElement.update (package:flutter/src/widgets/framework.dart:3847:5)
I/flutter (27323): #46     Element.updateChild (package:flutter/src/widgets/framework.dart:2667:15)
I/flutter (27323): #47     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3613:16)
I/flutter (27323): #48     Element.rebuild (package:flutter/src/widgets/framework.dart:3463:5)
I/flutter (27323): #49     ProxyElement.update (package:flutter/src/widgets/framework.dart:3847:5)
I/flutter (27323): #50     Element.updateChild (package:flutter/src/widgets/framework.dart:2667:15)
I/flutter (27323): #51     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3613:16)
I/flutter (27323): #52     Element.rebuild (package:flutter/src/widgets/framework.dart:3463:5)
I/flutter (27323): #53     StatefulElement.update (package:flutter/src/widgets/framework.dart:3737:5)
I/flutter (27323): #54     Element.updateChild (package:flutter/src/widgets/framework.dart:2667:15)
I/flutter (27323): #55     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3613:16)
I/flutter (27323): #56     Element.rebuild (package:flutter/src/widgets/framework.dart:3463:5)
I/flutter (27323): #57     BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2210:33)
I/flutter (27323): #58     BindingBase&amp;GestureBinding&amp;ServicesBinding&amp;SchedulerBinding&amp;PaintingBinding&amp;RendererBinding&amp;WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:621:20)
I/flutter (27323): #59     BindingBase&amp;GestureBinding&amp;ServicesBinding&amp;SchedulerBinding&amp;PaintingBinding&amp;RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:208:5)
I/flutter (27323): #60     BindingBase&amp;GestureBinding&amp;ServicesBinding&amp;SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:990:15)
I/flutter (27323): #61     BindingBase&amp;GestureBinding&amp;ServicesBinding&amp;SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:930:9)
I/flutter (27323): #62     BindingBase&amp;GestureBinding&amp;ServicesBinding&amp;SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:842:5)
I/flutter (27323): #63     _invoke (file:///b/build/slave/Linux_Engine/build/src/flutter/lib/ui/hooks.dart:120)
I/flutter (27323): #64     _drawFrame (file:///b/build/slave/Linux_Engine/build/src/flutter/lib/ui/hooks.dart:109)
I/flutter (27323): ════════════════════════════════════════════════════════════════════════════════════════════════════"><pre class="notranslate"><code class="notranslate">## Logs
I/flutter (27323): ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
I/flutter (27323): The following RangeError was thrown building BottomNavigationBar(dirty, state:
I/flutter (27323): _BottomNavigationBarState#68e58(tickers: tracking 3 tickers)):
I/flutter (27323): RangeError (index): Invalid value: Not in range 0..2, inclusive: 3
I/flutter (27323): 
I/flutter (27323): When the exception was thrown, this was the stack:
I/flutter (27323): #0      List.[] (dart:core-patch/dart:core/growable_array.dart:141)
I/flutter (27323): #1      _BottomNavigationBarState._createTiles (package:flutter/src/material/bottom_navigation_bar.dart:411:26)
I/flutter (27323): #2      _BottomNavigationBarState.build (package:flutter/src/material/bottom_navigation_bar.dart:477:45)
I/flutter (27323): #3      StatefulElement.build (package:flutter/src/widgets/framework.dart:3690:27)
I/flutter (27323): #4      ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3602:15)
I/flutter (27323): #5      Element.rebuild (package:flutter/src/widgets/framework.dart:3463:5)
I/flutter (27323): #6      StatefulElement.update (package:flutter/src/widgets/framework.dart:3737:5)
I/flutter (27323): #7      Element.updateChild (package:flutter/src/widgets/framework.dart:2667:15)
I/flutter (27323): #8      ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3613:16)
I/flutter (27323): #9      Element.rebuild (package:flutter/src/widgets/framework.dart:3463:5)
I/flutter (27323): #10     ProxyElement.update (package:flutter/src/widgets/framework.dart:3847:5)
I/flutter (27323): #11     Element.updateChild (package:flutter/src/widgets/framework.dart:2667:15)
I/flutter (27323): #12     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3613:16)
I/flutter (27323): #13     Element.rebuild (package:flutter/src/widgets/framework.dart:3463:5)
I/flutter (27323): #14     ProxyElement.update (package:flutter/src/widgets/framework.dart:3847:5)
I/flutter (27323): #15     Element.updateChild (package:flutter/src/widgets/framework.dart:2667:15)
I/flutter (27323): #16     RenderObjectElement.updateChildren (package:flutter/src/widgets/framework.dart:4317:32)
I/flutter (27323): #17     MultiChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4703:17)
I/flutter (27323): #18     Element.updateChild (package:flutter/src/widgets/framework.dart:2667:15)
I/flutter (27323): #19     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3613:16)
I/flutter (27323): #20     Element.rebuild (package:flutter/src/widgets/framework.dart:3463:5)
I/flutter (27323): #21     ProxyElement.update (package:flutter/src/widgets/framework.dart:3847:5)
I/flutter (27323): #22     Element.updateChild (package:flutter/src/widgets/framework.dart:2667:15)
I/flutter (27323): #23     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3613:16)
I/flutter (27323): #24     Element.rebuild (package:flutter/src/widgets/framework.dart:3463:5)
I/flutter (27323): #25     StatefulElement.update (package:flutter/src/widgets/framework.dart:3737:5)
I/flutter (27323): #26     Element.updateChild (package:flutter/src/widgets/framework.dart:2667:15)
I/flutter (27323): #27     SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4595:14)
I/flutter (27323): #28     Element.updateChild (package:flutter/src/widgets/framework.dart:2667:15)
I/flutter (27323): #29     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3613:16)
I/flutter (27323): #30     Element.rebuild (package:flutter/src/widgets/framework.dart:3463:5)
I/flutter (27323): #31     StatelessElement.update (package:flutter/src/widgets/framework.dart:3662:5)
I/flutter (27323): #32     Element.updateChild (package:flutter/src/widgets/framework.dart:2667:15)
I/flutter (27323): #33     SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4595:14)
I/flutter (27323): #34     Element.updateChild (package:flutter/src/widgets/framework.dart:2667:15)
I/flutter (27323): #35     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3613:16)
I/flutter (27323): #36     Element.rebuild (package:flutter/src/widgets/framework.dart:3463:5)
I/flutter (27323): #37     StatefulElement.update (package:flutter/src/widgets/framework.dart:3737:5)
I/flutter (27323): #38     Element.updateChild (package:flutter/src/widgets/framework.dart:2667:15)
I/flutter (27323): #39     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3613:16)
I/flutter (27323): #40     Element.rebuild (package:flutter/src/widgets/framework.dart:3463:5)
I/flutter (27323): #41     StatefulElement.update (package:flutter/src/widgets/framework.dart:3737:5)
I/flutter (27323): #42     Element.updateChild (package:flutter/src/widgets/framework.dart:2667:15)
I/flutter (27323): #43     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3613:16)
I/flutter (27323): #44     Element.rebuild (package:flutter/src/widgets/framework.dart:3463:5)
I/flutter (27323): #45     ProxyElement.update (package:flutter/src/widgets/framework.dart:3847:5)
I/flutter (27323): #46     Element.updateChild (package:flutter/src/widgets/framework.dart:2667:15)
I/flutter (27323): #47     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3613:16)
I/flutter (27323): #48     Element.rebuild (package:flutter/src/widgets/framework.dart:3463:5)
I/flutter (27323): #49     ProxyElement.update (package:flutter/src/widgets/framework.dart:3847:5)
I/flutter (27323): #50     Element.updateChild (package:flutter/src/widgets/framework.dart:2667:15)
I/flutter (27323): #51     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3613:16)
I/flutter (27323): #52     Element.rebuild (package:flutter/src/widgets/framework.dart:3463:5)
I/flutter (27323): #53     StatefulElement.update (package:flutter/src/widgets/framework.dart:3737:5)
I/flutter (27323): #54     Element.updateChild (package:flutter/src/widgets/framework.dart:2667:15)
I/flutter (27323): #55     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3613:16)
I/flutter (27323): #56     Element.rebuild (package:flutter/src/widgets/framework.dart:3463:5)
I/flutter (27323): #57     BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2210:33)
I/flutter (27323): #58     BindingBase&amp;GestureBinding&amp;ServicesBinding&amp;SchedulerBinding&amp;PaintingBinding&amp;RendererBinding&amp;WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:621:20)
I/flutter (27323): #59     BindingBase&amp;GestureBinding&amp;ServicesBinding&amp;SchedulerBinding&amp;PaintingBinding&amp;RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:208:5)
I/flutter (27323): #60     BindingBase&amp;GestureBinding&amp;ServicesBinding&amp;SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:990:15)
I/flutter (27323): #61     BindingBase&amp;GestureBinding&amp;ServicesBinding&amp;SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:930:9)
I/flutter (27323): #62     BindingBase&amp;GestureBinding&amp;ServicesBinding&amp;SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:842:5)
I/flutter (27323): #63     _invoke (file:///b/build/slave/Linux_Engine/build/src/flutter/lib/ui/hooks.dart:120)
I/flutter (27323): #64     _drawFrame (file:///b/build/slave/Linux_Engine/build/src/flutter/lib/ui/hooks.dart:109)
I/flutter (27323): ════════════════════════════════════════════════════════════════════════════════════════════════════
</code></pre></div>
<h2 dir="auto">Doctor</h2>
<p dir="auto">Version of Flutter is the current g3 version.</p>