parallax_image 0.3.1+1 copy "parallax_image: ^0.3.1+1" to clipboard
parallax_image: ^0.3.1+1 copied to clipboard

A Flutter widget that paints an image and moves it at a slower speed than the main scrolling content.

example/lib/main.dart

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

void main() => runApp(new MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      title: 'Parallax Image Demo',
      theme: new ThemeData(primarySwatch: Colors.blueGrey),
      home: new MyHomePage(title: 'Parallax Image Demo'),
    );
  }
}

class MyHomePage extends StatelessWidget {
  MyHomePage({Key key, this.title}) : super(key: key);
  final String title;

  @override
  Widget build(BuildContext context) {
    final theme = Theme.of(context);
    return new Scaffold(
      appBar: new AppBar(title: new Text(title)),
      body: new Column(
        children: <Widget>[
          new Container(
            padding: const EdgeInsets.all(20.0),
            child: new Text(
              'Horizontal scroll parallax',
              style: theme.textTheme.title,
            ),
          ),
          new Container(
            padding: const EdgeInsets.symmetric(vertical: 10.0),
            constraints: const BoxConstraints(maxHeight: 200.0),
            child: new ListView.builder(
              scrollDirection: Axis.horizontal,
              itemBuilder: _buildHorizontalChild,
            ),
          ),
          new Container(
            padding: const EdgeInsets.all(20.0),
            child: new Text(
              'Vertical scroll parallax',
              style: theme.textTheme.title,
            ),
          ),
          new Expanded(
            child: new ListView.builder(
              itemBuilder: _buildVerticalChild,
            ),
          )
        ],
      ),
    );
  }

  Widget _buildVerticalChild(BuildContext context, int index) {
    index++;
    if (index > 7) return null;
    return new Padding(
      padding: const EdgeInsets.only(bottom: 10.0),
      child: new GestureDetector(
        onTap: () {
          print('Tapped $index');
        },
        child: new ParallaxImage(
          extent: 150.0,
          image: new ExactAssetImage(
            'images/img$index.jpg',
          ),
        ),
      ),
    );
  }

  Widget _buildHorizontalChild(BuildContext context, int index) {
    index++;
    if (index > 7) return null;
    return new Padding(
      padding: const EdgeInsets.only(right: 10.0),
      child: new ParallaxImage(
        extent: 100.0,
        image: new ExactAssetImage(
          'images/img$index.jpg',
        ),
      ),
    );
  }
}
94
likes
40
pub points
74%
popularity

Publisher

unverified uploader

A Flutter widget that paints an image and moves it at a slower speed than the main scrolling content.

Repository (GitHub)
View/report issues

License

BSD-3-Clause (LICENSE)

Dependencies

flutter

More

Packages that depend on parallax_image