shader_graph 0.0.6 copy "shader_graph: ^0.0.6" to clipboard
shader_graph: ^0.0.6 copied to clipboard

A multi-pass render-graph framework for Flutter runtime shaders (FragmentProgram/RuntimeEffect), with Shadertoy-style buffers and feedback.

example/lib/main.dart

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'examples/game.dart';
import 'examples/games/bricks_game.dart';
import 'examples/float.dart';
import 'examples/iframe.dart';
import 'examples/keyboard_input.dart';
import 'examples/mouse_input.dart';
import 'examples/multi_pass.dart';
import 'examples/games/pacman_game.dart';
import 'examples/text_render.dart';
import 'examples/widget_input.dart';
import 'examples/wrap.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  runApp(MaterialApp(home: Scaffold(body: MyApp())));
}

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

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return CupertinoApp(
      title: 'Shader Graph Example',
      // theme: ThemeData(colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple)),
      theme: const CupertinoThemeData(
        brightness: Brightness.light,
        primaryColor: Color(0xff006aff),
      ),
      home: CupertinoPageScaffold(
        child: const RootPage(),
      ),
    );
  }
}

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

  @override
  State<RootPage> createState() => _RootPageState();
}

class _RootPageState extends State<RootPage> {
  int currentIndex = 4;

  @override
  Widget build(BuildContext context) {
    final tabs = [
      Text('Bricks Game'),
      Text('Pacman Game'),
      Text('Keyboard'),
      Text('Mouse'),
      Text('Wrap & Filter'),
      Text('Text Render'),
      Text('iFrame'),
      Text('Multi-Pass'),
      Text('Float Support'),
      '',
    ];
    final tabTitles = [
      'Game',
      'Widget Input',
      'Keyboard Input',
      'Mouse Input',
      'Wrap & Filter',
      'Text Render',
      'iFrame',
      'Multi-Pass Rendering',
      'Float Support Example',
    ];
    return CupertinoPageScaffold(
      backgroundColor: Color(0xfff3f5f9),
      navigationBar: CupertinoNavigationBar(
        middle: SingleChildScrollView(
          scrollDirection: Axis.horizontal,
          child: CupertinoSlidingSegmentedControl(
            // isMomentary: true,
            proportionalWidth: true,
            groupValue: currentIndex,
            onValueChanged: (int? value) {
              if (value != null) {
                currentIndex = value;
                setState(() {});
              }
            },
            children: {
              for (var i = 0; i < tabTitles.length; i++) i: Text(tabTitles[i]),
            },
          ),
        ),
      ),
      child: LayoutBuilder(
        builder: (context, constraints) {
          double width = constraints.maxWidth;
          double height = constraints.maxHeight;
          if (width < 400 && currentIndex != 0 && currentIndex != 1) {
            height = width * 0.75;
          }
          return SizedBox(
            width: width,
            height: height,
            child: [
              GameExample(),
              WidgetInputExample(),
              KeyboardExample(),
              MouseExample(),
              WrapExample(),
              TextRenderExample(),
              IframeExample(),
              MultiPassExample(),
              FloatExample(),
            ][currentIndex],
          );
        },
      ),
    );
  }
}
2
likes
140
points
554
downloads

Publisher

unverified uploader

Weekly Downloads

A multi-pass render-graph framework for Flutter runtime shaders (FragmentProgram/RuntimeEffect), with Shadertoy-style buffers and feedback.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter, path

More

Packages that depend on shader_graph