You can use the extension function in the path package to get the extension
from a file path:
import 'package:path/path.dart' as p;
final path = '/some/path/to/file/file.dart';
final extension = p.extension(path); // '.dart'
If your file has multiple extensions, like file.dart.js, you can specify the
optional level parameter:
final extension = p.extension('file.dart.js', 2); // '.dart.js'