parallax_bg 2.0.1 copy "parallax_bg: ^2.0.1" to clipboard
parallax_bg: ^2.0.1 copied to clipboard

Create beautiful & interactive parallax backgrounds

example/lib/main.dart

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

import 'package:parallax_bg/parallax_bg.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  double _planetOffset = 1;
  double _meteorOffset = 5;

  bool _loading = false;

  @override
  Widget build(BuildContext context) {
    SystemChrome.setEnabledSystemUIOverlays([]);
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: Scaffold(
        // appBar: AppBar(
        //   title: const Text('Sample App'),
        // ),
        body: Column(mainAxisSize: MainAxisSize.max, children: [
          Expanded(
              child: _loading
                  ? Center(child: CircularProgressIndicator())
                  : _parallaxBody()),
          Padding(
            padding: const EdgeInsets.symmetric(horizontal: 8.0),
            child: Row(
              mainAxisSize: MainAxisSize.max,
              children: [
                Text("Planet"),
                Expanded(
                  child: Slider(
                    value: _planetOffset,
                    onChanged: (val) {
                      setState(() {
                        _planetOffset = val;
                      });
                    },
                    min: 1,
                    max: 10,
                  ),
                ),
                Text(_planetOffset.toStringAsFixed(0)),
              ],
            ),
          ),
          Padding(
            padding: const EdgeInsets.symmetric(horizontal: 8.0),
            child: Row(
              children: [
                Text("Meteor"),
                Expanded(
                  child: Slider(
                    value: _meteorOffset,
                    onChanged: (val) {
                      setState(() {
                        _meteorOffset = val;
                      });
                    },
                    min: 5,
                    max: 20,
                  ),
                ),
                Text(_meteorOffset.toStringAsFixed(0)),
              ],
            ),
          ),
        ]),
      ),
    );
  }

  _parallaxBody() {
    return ParallaxBackground(
      backgroundImage: "assets/images/galaxy.jpg",
      foregroundChilds: [
        ParallaxItem(
            child: Image.asset("assets/images/planet.png"),
            offset: _planetOffset),
        ParallaxItem(
            child: Image.asset("assets/images/meteor.png"),
            offset: _meteorOffset),
      ],
      // fallback: true,
    );
  }
}
27
likes
110
pub points
20%
popularity

Publisher

verified publisherakidevelops.com

Create beautiful & interactive parallax backgrounds

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

flutter, sensors_plus

More

Packages that depend on parallax_bg