water_fx 1.0.11 copy "water_fx: ^1.0.11" to clipboard
water_fx: ^1.0.11 copied to clipboard

A library for adding water effects to Flutter apps. Wrap any widget with a WaterFXContainer, and it will seem to be under water when touched.

example/main.dart

// (c) 2023 - Jim Morrison
// You may use this code however you want, as long as you show my name and this
// link in your work: http://www.jimmorrison101.com/.

import 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:water_fx/water_fx.dart';
import 'dart:ui' as dart_ui;

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();

  // Add this image file in a assets/images folder, and reference this in your
  // pubspec.yaml file.
  runApp(WaterFXApp(await loadImageFromAsset('assets/images/london.jpg')));
}

Future<dart_ui.Image> loadImageFromAsset(String assetPath) async {
  ByteData assetData = await rootBundle.load(assetPath);
  List<int> assetBytes = assetData.buffer.asUint8List();
  Completer<dart_ui.Image> completer = Completer();
  dart_ui.decodeImageFromList(Uint8List.fromList(assetBytes),
      (dart_ui.Image img) => completer.complete(img));
  return completer.future;
}

class WaterFXApp extends StatefulWidget {
  final dart_ui.Image _sourceImage;

  const WaterFXApp(
    this._sourceImage, {
    super.key,
  });

  @override
  State<WaterFXApp> createState() => _WaterFXAppState();
}

class _WaterFXAppState extends State<WaterFXApp> {
  @override
  Widget build(BuildContext context) => MaterialApp(
        home: Center(
          child: WaterFXContainer.simpleImageInstanceForPointer(
              image: widget._sourceImage),
        ),
      );
}
5
likes
0
points
610
downloads

Publisher

unverified uploader

Weekly Downloads

A library for adding water effects to Flutter apps. Wrap any widget with a WaterFXContainer, and it will seem to be under water when touched.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter

More

Packages that depend on water_fx