alphanum_comparator 1.0.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 72

alphanum_comparator #

Porting of "The Alphanum Algorithm" in Dart.

The Problem #

Look at most sorted list of filenames, product names, or any other text that contains alphanumeric characters - both letters and numbers. Traditional sorting algorithms use ASCII comparisons to sort these items, which means the end-user sees an unfortunately ordered list that does not consider the numeric values within the strings.

For example, in a sorted list of files, "z100.html" is sorted before "z2.html". But obviously, 2 comes before 100!

Sorting algorithms should sort alphanumeric strings in the order that users would expect, especially as software becomes increasingly used by nontechnical people. Besides, it's the 21st Century; software engineers can do better than this.

The Solution #

I created the Alphanum Algorithm to solve this problem. The Alphanum Algorithm sorts strings containing a mix of letters and numbers. Given strings of mixed characters and numbers, it sorts the numbers in value order, while sorting the non-numbers in ASCII order. The end result is a natural sorting order.

Here's a list of sample filenames to illustrate the difference between sorting with the Alphanum algorithm and traditional ASCII sort. On the left is what you live with on a daily basis. On the right is what you could have, if more developers were motivated to sort lists as people would expect. Which list makes more sense to you? Which would be more comfortable to you as you're using an application?

Traditional z1.doc z10.doc z100.doc z101.doc z102.doc z11.doc z12.doc z13.doc z14.doc z15.doc z16.doc z17.doc z18.doc z19.doc z2.doc z20.doc z3.doc z4.doc z5.doc z6.doc z7.doc z8.doc z9.doc

Alphanum z1.doc z2.doc z3.doc z4.doc z5.doc z6.doc z7.doc z8.doc z9.doc z10.doc z11.doc z12.doc z13.doc z14.doc z15.doc z16.doc z17.doc z18.doc z19.doc z20.doc z100.doc z101.doc z102.doc

See for details

[0.0.1] - 2020-05-30 #

  • Initial commit

[1.0.0] - 2020-06-01 #

  • Added example

[1.0.1] - 2020-06-01 #

  • Added description


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

void main() {

  final List<String> _unsorted = ["Item 2", "Item 3", "Item 10", "Item 1"];
  final List<String> _sorted = _unsorted;

      home: Scaffold(
        body: ListView(
          children: <Widget>[
            ListTile(title: Text('Unsorted Strings')),
   => ListTile(title: Text('$i'))).toList(),
            ListTile(title: Text('Sorted Strings')),
   => ListTile(title: Text('$i'))).toList(),

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  alphanum_comparator: ^1.0.1

2. Install it

You can install packages from the command line:

with Flutter:

$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:alphanum_comparator/alphanum_comparator.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Jul 9, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.14
  • Flutter: 1.17.5

Analysis suggestions

Package not compatible with SDK dart


  • alphanum_comparator that is a package requiring null.

Health issues and suggestions

Document public APIs. (-1 points)

4 out of 4 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.7.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.12 1.14.13
meta 1.1.8 1.2.1
sky_engine 0.0.99
typed_data 1.1.6 1.2.0
vector_math 2.0.8 2.1.0-nullsafety
Dev dependencies