Skip to main content

liquid_glass_vivid 0.1.0-dev.2 copy "liquid_glass_vivid: ^0.1.0-dev.2" to clipboard
liquid_glass_vivid: ^0.1.0-dev.2 copied to clipboard

Liquid glass navigation and buttons for Flutter, with draggable lenses, bottom and side layouts, background refraction, and renderer fallbacks.

example/lib/main.dart

import 'dart:ui' as ui;

import 'package:liquid_glass_vivid/liquid_glass_vivid.dart';

import 'src/material_compat.dart';
import 'button_demo.dart';

void main() => runApp(const GlassExample());

/// 独立示例的背景、路由与偏好均由宿主自行组织。
class GlassExample extends StatefulWidget {
  const GlassExample({super.key});

  @override
  State<GlassExample> createState() => _GlassExampleState();
}

class _GlassExampleState extends State<GlassExample> {
  int _selected = 0;
  double _tint = .25;
  bool _dark = false;
  bool _rail = false;
  bool _rtl = false;
  bool _labels = true;
  bool _reduceMotion = false;
  bool _balanced = false;
  static const _destinations = [
    LiquidGlassDestination(label: '首页', icon: Icons.home_rounded),
    LiquidGlassDestination(label: '时钟', icon: Icons.watch_later_rounded),
    LiquidGlassDestination(label: '发现', icon: Icons.explore_rounded),
    LiquidGlassDestination(label: '设置', icon: Icons.settings_rounded),
  ];

  @override
  Widget build(BuildContext context) => MaterialApp(
    title: '液态玻璃示例',
    debugShowCheckedModeBanner: false,
    theme: ThemeData(
      colorScheme: ColorScheme.fromSeed(
        seedColor: const Color(0xFF70B82F),
        brightness: _dark ? Brightness.dark : Brightness.light,
      ),
    ),
    home: Builder(
      builder: (context) => Directionality(
        textDirection: _rtl ? TextDirection.rtl : TextDirection.ltr,
        child: MediaQuery(
          data: MediaQuery.of(
            context,
          ).copyWith(disableAnimations: _reduceMotion),
          child: Scaffold(
            appBar: AppBar(title: const Text('液态玻璃示例')),
            body: Column(
              children: [
                Padding(
                  padding: const EdgeInsets.symmetric(horizontal: 16),
                  child: Wrap(
                    spacing: 8,
                    children: [
                      ActionChip(
                        label: const Text('按钮示例'),
                        onPressed: () => Navigator.of(context).push(
                          MaterialPageRoute<void>(
                            builder: (_) => const GlassButtonExample(),
                          ),
                        ),
                      ),
                      FilterChip(
                        label: const Text('深色'),
                        selected: _dark,
                        onSelected: (v) => setState(() => _dark = v),
                      ),
                      FilterChip(
                        label: const Text('侧栏'),
                        selected: _rail,
                        onSelected: (v) => setState(() => _rail = v),
                      ),
                      FilterChip(
                        label: const Text('从右到左'),
                        selected: _rtl,
                        onSelected: (v) => setState(() => _rtl = v),
                      ),
                      FilterChip(
                        label: const Text('标签'),
                        selected: _labels,
                        onSelected: (v) => setState(() => _labels = v),
                      ),
                      FilterChip(
                        label: const Text('节能采样'),
                        selected: _balanced,
                        onSelected: (v) => setState(() => _balanced = v),
                      ),
                      FilterChip(
                        label: const Text('减少动态'),
                        selected: _reduceMotion,
                        onSelected: (v) => setState(() => _reduceMotion = v),
                      ),
                    ],
                  ),
                ),
                Padding(
                  padding: const EdgeInsets.symmetric(horizontal: 16),
                  child: Row(
                    children: [
                      const Icon(Icons.filter_none),
                      Expanded(
                        child: Slider(
                          value: _tint,
                          label: '${(_tint * 100).round()}%',
                          onChanged: (v) => setState(() => _tint = v),
                        ),
                      ),
                      const Icon(Icons.filter),
                    ],
                  ),
                ),
                Text('当前页面:${_destinations[_selected].label}'),
                Padding(
                  padding: const EdgeInsets.all(8),
                  child: Text(
                    ui.ImageFilter.isShaderFilterSupported
                        ? '当前后端支持背景着色器折射'
                        : '当前后端使用背景纹理折射',
                  ),
                ),
                Expanded(
                  child: LiquidGlassLayout(
                    axis: _rail ? Axis.vertical : Axis.horizontal,
                    quality: _balanced
                        ? LiquidGlassCaptureQuality.balanced
                        : LiquidGlassCaptureQuality.full,
                    navigation: _navigation(),
                    body: ListView.builder(
                      padding: const EdgeInsets.fromLTRB(20, 12, 20, 140),
                      itemCount: 50,
                      itemBuilder: (context, index) => Container(
                        height: 92,
                        margin: const EdgeInsets.only(bottom: 12),
                        padding: const EdgeInsets.all(16),
                        decoration: BoxDecoration(
                          color: Colors
                              .primaries[index % Colors.primaries.length]
                              .withValues(alpha: .15),
                          borderRadius: BorderRadius.circular(20),
                        ),
                        child: Text(
                          '${index + 1} · 页面内容随滚动实时透过玻璃\n按住导航慢滑,松手才切换页面',
                          style: Theme.of(context).textTheme.titleMedium,
                        ),
                      ),
                    ),
                  ),
                ),
              ],
            ),
          ),
        ),
      ),
    ),
  );

  Widget _navigation() => LiquidGlassNavigation(
    destinations: _destinations,
    selectedIndex: _selected,
    axis: _rail ? Axis.vertical : Axis.horizontal,
    showLabels: _labels,
    tint: _tint,
    onSelected: (index) => setState(() => _selected = index),
  );
}
0
likes
0
points
131
downloads

Publisher

unverified uploader

Weekly Downloads

Liquid glass navigation and buttons for Flutter, with draggable lenses, bottom and side layouts, background refraction, and renderer fallbacks.

Homepage
Repository (GitHub)
View/report issues

Topics

#liquid-glass #navigation #widget

License

unknown (license)

Dependencies

flutter

More

Packages that depend on liquid_glass_vivid