Skip to main content

w_tools_ui 4.7.0 copy "w_tools_ui: ^4.7.0" to clipboard
w_tools_ui: ^4.7.0 copied to clipboard

w_tools 的 UI 组件层:提供文本、图片、按钮、布局、导航与常用扩展,支持响应式尺寸、图片缓存与重试,帮助快速构建一致的界面。

example/lib/main.dart

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

import 'buttons_page.dart';
import 'components_page.dart';
import 'playground_page.dart';
import 'recipes_page.dart';
import 'states_page.dart';

void main() {
  WidgetsFlutterBinding.ensureInitialized();

  // 进程级缓存预算;占位符/错误占位默认值交给 WImageDefaultsScope。
  PaintingBinding.instance.imageCache
    ..maximumSize = 300
    ..maximumSizeBytes = 300 * 1024 * 1024;

  runApp(
    WImageDefaultsScope(
      defaults: WImageLoadConfig(
        placeholderBuilder: (context, data) => const Center(child: CircularProgressIndicator()),
        errorWidgetBuilder: (context, data, error) => const Icon(Icons.broken_image),
      ),
      child: const WUiExampleApp(),
    ),
  );
}

class WUiExampleApp extends StatelessWidget {
  const WUiExampleApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'w_tools_ui · 示例',
      // 一次装好 TextTheme 与 WTextStyles:Material 组件(form/toast/async)
      // 与 WText 看到同一套字号。
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.indigo),
        useMaterial3: true,
      ).withWTextStyles(
        WTextStyles.fromTextTheme(ThemeData.light().textTheme),
      ),
      home: const HomeShell(),
    );
  }
}

class HomeShell extends StatefulWidget {
  const HomeShell({super.key});

  @override
  State<HomeShell> createState() => _HomeShellState();
}

class _HomeShellState extends State<HomeShell> with TickerProviderStateMixin {
  late final WNavController _navController;

  static const _pages = <Widget>[
    PlaygroundPage(),
    StatesPage(),
    RecipesPage(),
    ButtonsPage(),
    ComponentsPage(),
  ];

  static const _destinations = <({IconData icon, String label})>[
    (icon: Icons.tune, label: 'Playground'),
    (icon: Icons.grid_view, label: '状态矩阵'),
    (icon: Icons.receipt_long, label: '常用配方'),
    (icon: Icons.smart_button, label: '按钮'),
    (icon: Icons.widgets, label: '组件'),
  ];

  @override
  void initState() {
    super.initState();
    // 让 WImage.asset('demo.png', prefix: true) 指向 example/assets/demo.png。
    WAssets.imagePath = 'assets/';
    _navController = WNavController(
      length: _destinations.length,
      vsync: this,
    );
  }

  @override
  void dispose() {
    _navController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return WScaffold(
      title: 'w_tools_ui 示例',
      body: ListenableBuilder(
        listenable: _navController,
        builder: (context, _) => IndexedStack(
          index: _navController.currentIndex,
          children: _pages,
        ),
      ),
      bottomNavigationBar: WNavBar(
        config: const WNavBarConfig(),
        controller: _navController,
        itemBuilder: (context, index, selected) {
          final item = _destinations[index];
          final color = selected ? Colors.indigo : Colors.grey;
          return Column(
            mainAxisSize: MainAxisSize.min,
            children: [
              Icon(item.icon, color: color, size: 22),
              const SizedBox(height: 2),
              WText(
                text: item.label,
                variant: WTextVariant.caption,
                color: color,
              ),
            ],
          );
        },
      ),
    );
  }
}
0
likes
0
points
2.23k
downloads

Publisher

unverified uploader

Weekly Downloads

w_tools 的 UI 组件层:提供文本、图片、按钮、布局、导航与常用扩展,支持响应式尺寸、图片缓存与重试,帮助快速构建一致的界面。

Homepage
Repository (GitHub)
View/report issues

Topics

#flutter #ui #widget #components

License

unknown (license)

Dependencies

badges, cached_network_image, flutter

More

Packages that depend on w_tools_ui