8

I know that dart:ui contains "Built-in types and core primitives for a Flutter application". I'd like to use Color and other functionality from this package (computeLuminance) in a command-line (Dart) application that converts some data files.

(I would also like to use estimateBrightnessForColor from Flutter Material, but I guess this is even harder, or impossible.)

I'm using the Dart SDK that is bundled with the Flutter SDK.

import 'dart:io';
import 'dart:ui';

I get Error: Not found: 'dart:ui'

As a side note, I can import and use dart:ui on DartPad.

TechAurelian
  • 5,561
  • 5
  • 50
  • 65

1 Answers1

0

If you want to use color-related functionality such as computeLuminance in a command-line Dart application, you can consider using the color package provided by the Dart ecosystem. This package offers color-related utilities and operations that can be used independently of the Flutter framework.

To use the color package in your command-line Dart application, follow these steps:

Open your project's pubspec.yaml file. Add the color package as a dependency:

dependencies:
  color: ^2.1.0

Save the file, and run flutter pub get or dart pub get in the terminal to fetch the package. In your Dart file, import the color package:

example:

import 'package:color/color.dart';

void main() {
  Color color = Color.rgb(128, 128, 128);
  double luminance = color.computeLuminance();
  
  if (luminance > 0.5) {
    print('Color is bright');
  } else {
    print('Color is dark');
  }
}

Now you can utilize color-related functionality from the color package, including computeLuminance, in your command-line Dart application.

Regarding estimateBrightnessForColor, it is tightly integrated with the Flutter Material framework and relies on the Flutter rendering engine. Therefore, it's not feasible to use estimateBrightnessForColor in a command-line Dart application.

Khubah
  • 44
  • 4
  • 1
    Welcome to Stack Overflow! Several of your answers from the last two days appear likely to have been entirely or partially written by AI (e.g., ChatGPT). Please be aware that [posting of AI-generated content is banned here](//meta.stackoverflow.com/q/421831). If you used an AI tool to assist with any answer, I would encourage you to delete it. Thanks! – NotTheDr01ds Jun 25 '23 at 00:44
  • 1
    **Readers should review this answer carefully and critically, as AI-generated information often contains fundamental errors and misinformation.** If you observe quality issues and/or have reason to believe that this answer was generated by AI, please leave feedback accordingly. The moderation team can use your help to identify quality issues. m – NotTheDr01ds Jun 25 '23 at 00:44
  • 1
    This answer looks like it was generated by an AI (like ChatGPT), not by an actual human being. You should be aware that [posting AI-generated output is officially **BANNED** on Stack Overflow](https://meta.stackoverflow.com/q/421831). If this answer was indeed generated by an AI, then I strongly suggest you delete it before you get yourself into even bigger trouble: **WE TAKE PLAGIARISM SERIOUSLY HERE.** Please read: [Why posting GPT and ChatGPT generated answers is not currently allowed](https://stackoverflow.com/help/gpt-policy). – tchrist Jul 10 '23 at 13:02