Skip to content

Instantly share code, notes, and snippets.

@Adem68
Last active April 15, 2025 15:55
Show Gist options
  • Save Adem68/a98feed31ad1ce38b9733f5d548526a9 to your computer and use it in GitHub Desktop.
Save Adem68/a98feed31ad1ce38b9733f5d548526a9 to your computer and use it in GitHub Desktop.
How many lines does your Flutter project have?
  • Open terminal and go to your project's lib folder. After that run the command below.
  • find . -name '*.dart' ! -name '*.g.dart' ! -name '*.freezed.dart' ! -name '*.gr.dart' ! -name '*.gen.dart' | xargs wc -l

Thanks @AcetylsalicylicAcid for excluding generated files.

@osamamohammed98
Copy link

how to get count with out library code

@karmazinkd
Copy link

don't forget that you may have a lot of generated files in dart

@Adem68
Copy link
Author

Adem68 commented Oct 17, 2022

Hi @karmazinkd, I'm updated the command. Thanks to @AcetylsalicylicAcid 🙌

@danialothman
Copy link

sort by numbers of lines of code
find . -name '*.dart' ! -name '*.g.dart' ! -name '*.freezed.dart' ! -name '*.gr.dart' ! -name '*.gen.dart' | xargs wc -l | sort -n

@Nikzed
Copy link

Nikzed commented Dec 27, 2023

for anyone who wonders how to make this in Windows 10 PowerShell.

$totalLines = 0
Get-ChildItem -Recurse -Filter "*.dart" | Where-Object {!($_.Name -like "*.g.dart" -or $_.Name -like "*.freezed.dart" -or $_.Name -like "*.gr.dart" -or $_.Name -like "*.gen.dart")} | ForEach-Object {
    $lineCount = (Get-Content $_.FullName | Measure-Object -Line).Lines
    $totalLines += $lineCount
    Write-Host "$($_.Name): $lineCount lines"
}

Write-Host "Total lines: $totalLines"

@RRohitM
Copy link

RRohitM commented Mar 24, 2024

Hi @Adem68 I am getting error like this

xargs : The term 'xargs' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if
a path was included, verify that the path is correct and try again.
At line:1 char:110

  • ... .freezed.dart' ! -name '.gr.dart' ! -name '.gen.dart' | xargs wc -l
  •                                                           ~~~~~
    
    • CategoryInfo : ObjectNotFound: (xargs:String) [], CommandNotFoundException
    • FullyQualifiedErrorId : CommandNotFoundException

@famasf1
Copy link

famasf1 commented Mar 27, 2024

Hi @Adem68 I am getting error like this

xargs : The term 'xargs' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:1 char:110

* ... .freezed.dart' ! -name '_.gr.dart' ! -name '_.gen.dart' | xargs wc -l

* ```
                                                            ~~~~~
  ```
  
  
  
  * CategoryInfo          : ObjectNotFound: (xargs:String) [], CommandNotFoundException
  * FullyQualifiedErrorId : CommandNotFoundException

This is linux command-line. If you use Windows, you will need to install WSL.

@Ayu219
Copy link

Ayu219 commented Sep 8, 2024

For Windows :

$files = Get-ChildItem -Recurse -Filter *.dart | Where-Object { $_.Name -notmatch '\.g\.dart$|\.freezed\.dart$|\.gr\.dart$|\.gen\.dart$' }
$totalLines = 0
foreach ($file in $files) {
    $lines = (Get-Content $file.FullName | Measure-Object -Line).Lines
    $totalLines += $lines
    Write-Output "$($file.FullName): $lines lines"
}
Write-Output "Total lines: $totalLines" 

@djsimp
Copy link

djsimp commented Apr 15, 2025

Why not this?:
$ find . -name '*.dart' ! -name '*.*.dart' | xargs wc -l

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment