slowly_moving_widgets_field 0.1.2

  • Readme
  • Changelog
  • Example
  • Installing
  • 50

slowing_moving_widgets_field #

Pass in a list of arbitrary widgets and the slowing_moving_widgets_field widget moves them around the screen, like the old asteroids video game.

If collisionAmount is null then widgets float on top of each other (DON'T bounce).

If collisionAmount is non-null then widgets will bounce when they hit each other (collision detection). But, this is buggy (see below).

Returns a Stack() which contains all the "magic."

Example #

Screenshot

TODO #

  • specify background
  • specify a slight amount of randomness on every impact
  • specify how much overlap (positive or negative) to allow before bounce
  • specify speed
  • specify "soft bounce" mode that causes close widgets to repel off of each other rather than instantaneous bounce

Bugs #

  • will fail (undefined results) if you try to add too many widgets; there must be adequate room to add all widgets initially so they are not overlapping
  • if collision detection is enabled (collisionAmount != null), sometimes the movers overlap and get stuck on top of each other--not sure why

Design Flaws #

  • don't like having to specify width and height more than once (see example)

Usage #

Add a new dependency line to your project/pubspec.yaml file:

dependencies:
  ...
  slowing_moving_widgets_field: 0.1.2      # use latest version!

Don't forget to flutter pub get

Pull Requests #

Pull requests are welcome!

Changelog #

Version 0.1.2 (2020-01-08) #

  • documentation

Version 0.1.1 (2020-01-07) #

  • cleanup

Version 0.1.0 (2020-01-06) #

  • initial

example/lib/main.dart

import 'dart:math';

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

final r = new Random();

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  runApp(new MyApp());
}

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

class _MyAppState extends State<MyApp> {
  final List<Moving> list = [];

  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      home: Scaffold(body: Center(child: SlowlyMovingWidgetsField(list: list))),
    );
  }

  @override
  void dispose() {
    super.dispose();
  }

  @override
  void initState() {
    super.initState();

    int colorRotate = 0;
    Color color;
    for (int i = 0; i < 10; i++) {
      switch (colorRotate) {
        case 0:
          color =
              Color.fromARGB(255, 0, 200 + r.nextInt(56), 200 + r.nextInt(56));
          break;
        case 1:
          color =
              Color.fromARGB(255, 200 + r.nextInt(56), 0, 200 + r.nextInt(56));
          break;
        case 2:
          color =
              Color.fromARGB(255, 200 + r.nextInt(56), 200 + r.nextInt(56), 0);
          break;
      }

      colorRotate++;
      colorRotate %= 3;

      // wrap each of your widgets in a "Moving" container
      list.add(Moving(
        child: Container(
            child: Text("$i", style: TextStyle(fontSize: 40)),
            color: color,
            height: 50,
            width: 100),
        height: 50,
        width: 100,
      ));
    }
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  slowly_moving_widgets_field: ^0.1.2

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:slowly_moving_widgets_field/slowly_moving_widgets_field.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
0
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
50
Learn more about scoring.

We analyzed this package on Apr 7, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.6
  • Flutter: 1.12.13+hotfix.8

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
meta ^1.1.8 1.1.8
Transitive dependencies
collection 1.14.11 1.14.12
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test