Skip to main content

dartool_flutter 0.1.0 copy "dartool_flutter: ^0.1.0" to clipboard
dartool_flutter: ^0.1.0 copied to clipboard

Flutter extensions for dartool: platform detection, logging, form validation and more.

dartool_flutter #

pub version 中文文档

Flutter-specific extensions for dartool.

dartool_flutter provides utilities that depend on Flutter SDK (platform detection, logging, widget shorthands, etc.). Use it together with the pure-Dart dartool core package.

Features #

  • Separate package -- pure Dart projects do not need this dependency
  • Web-safe platform detection -- correctly handles Web where dart:io is unavailable
  • Lightweight logger -- level-based filtering with tags and swappable output channel
  • Widget shorthands -- concise wrappers for common Flutter widgets
  • Dart 3 + null-safe -- built on Dart 3.9 SDK / Flutter 3.22+

Installation #

dependencies:
  dartool: ^0.1.0-dev.2
  dartool_flutter: ^0.1.0-dev.2
flutter pub get

Quick Start #

import 'package:dartool/dartool.dart';
import 'package:dartool_flutter/dartool_flutter.dart';

void main() {
  // Platform detection (Web-safe, never throws)
  if (PlatformUtil.isAndroid) {
    LogUtil.info('running on Android');
  }
  if (PlatformUtil.isMobile) {
    LogUtil.debug('mobile device detected');
  }
  if (PlatformUtil.isDesktop) {
    LogUtil.warn('desktop platform');
  }

  // Tagged logging
  LogUtil.error('network failed', tag: 'NetworkService');

  // Customize minimum log level (e.g. suppress debug in release)
  LogUtil.minLevel = LogLevel.info;

  // Pipe logs to a custom destination
  LogUtil.output = (line) => myRemoteLogger.send(line);
}

// Widget shorthands in Flutter widgets
class MyWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Column(
        children: [
          WidgetUtil.sizedBoxH(16),
          WidgetUtil.paddingAll(child: Text('hi'), value: 8),
          WidgetUtil.expanded(child: ListView()),
          WidgetUtil.safeArea(child: HomePage()),
        ],
      ),
    );
  }
}

API Overview #

Class Description
PlatformUtil Platform detection (Android, iOS, Web, macOS, Windows, Linux, Mobile, Desktop) -- Web-safe
LogUtil Leveled logging (debug, info, warn, error) with tags, level filter and swappable output
WidgetUtil Common widget shorthands (SizedBox, Padding, Expanded, SafeArea, etc.)

Development #

# Install melos (from workspace root)
dart pub global activate melos
melos bootstrap

# Develop inside this package
cd packages/dartool_flutter
flutter analyze
flutter test

Documentation #

  • API docs are generated by dart doc
  • Source code contains detailed documentation comments
  • 中文文档

Contributing #

Issues and PRs are welcome. Follow Conventional Commits, respect the lints rules, and add tests for new features.

License #

MIT

1
likes
160
points
410
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

Flutter extensions for dartool: platform detection, logging, form validation and more.

Homepage
Repository (GitHub)
View/report issues

License

MIT (license)

Dependencies

dartool, flutter

More

Packages that depend on dartool_flutter