title: How do I sort items in a list by DateTime in Flutter/Dart?
body: <p>I'm making an app for my Uncle which he asked me to make to challenge me. I thought this was the perfect opportunity to learn Flutter/Dart. I have this code (below), but i need it to organise a list by DateTime (line 77). Each entry has a string id, a DateTime variable , a string name and some body text, at a bare minimum.</p>
  
  <pre><code>import 'package:flutter/material.dart';
  
  import 'package:gym_tracker/model/diary_entry.dart';
  import 'package:gym_tracker/utils/store.dart';
  
  class HomeScreen extends StatefulWidget {
    @override
    State&lt;StatefulWidget&gt; createState() =&gt; new HomeScreenState();
  }
  
  class HomeScreenState extends State&lt;HomeScreen&gt; {
    List&lt;Entry&gt; entries = getEntries();
    List&lt;String&gt; userFavorites = getFavoritesIDs();
  
    // Inactive widgets are going to call this method to
    // signalize the parent widget HomeScreen to refresh the list view.
    void _handleFavoritesListChanged(String entryID) {
      // Set new state and refresh the widget:
      setState(() {
        if (userFavorites.contains(entryID)) {
          userFavorites.remove(entryID);
        } else {
          userFavorites.add(entryID);
        }
      });
    }
  
    @override
    Widget build(BuildContext context) {
      Column _buildEntries(List&lt;Entry&gt; entriesList) {
        return Column(
          children: &lt;Widget&gt;[
            Expanded(
              child: ListView.builder(
                itemCount: entriesList.length,
                itemBuilder: (BuildContext context, int index) {
                  return ListTile(
                    title: Text(entriesList[index].name),
                  );
                },
              ),
            ),
          ],
        );
      }
  
      const double _iconSize = 20.0;
  
      return DefaultTabController(
        length: 4,
        child: Scaffold(
          appBar: PreferredSize(
            // We set Size equal to passed height (50.0) and infinite width:
            preferredSize: Size.fromHeight(50.0),
            child: AppBar(
              backgroundColor: Colors.white,
              elevation: 2.0,
              bottom: TabBar(
                labelColor: Theme.of(context).indicatorColor,
                tabs: [
                  Tab(icon: Icon(Icons.wb_sunny, size: _iconSize)),
                  Tab(icon: Icon(Icons.date_range, size: _iconSize)),
                  Tab(icon: Icon(Icons.bookmark, size: _iconSize)),
                  Tab(icon: Icon(Icons.settings, size: _iconSize)),
                ],
              ),
            ),
          ),
          body: Padding(
            padding: EdgeInsets.all(5.0),
            child: TabBarView(
              // Replace placeholders:
              children: [
                // Display entries today:
                _buildEntries(entries.where((entry) =&gt; entry.dateTime.day == DateTime.now().day &amp;&amp; entry.dateTime.month == DateTime.now().month &amp;&amp; entry.dateTime.year == DateTime.now().year).toList()),
                // Display all entries:
                _buildEntries(entries.where((entry) =&gt; ).toList()), //Help Here Please!
                // Display favorite entries:
                _buildEntries(entries.where((entry) =&gt; userFavorites.contains(entry.id)).toList()),
                Center(child: Icon(Icons.settings)),
              ],
            ),
          ),
        ),
      );
    }
  }
  </code></pre>