wheel_expand_list 0.2.1 copy "wheel_expand_list: ^0.2.1" to clipboard
wheel_expand_list: ^0.2.1 copied to clipboard

outdated

It works in 3D with horizontal scrolling. If the area is exceeded, vertical scrolling occurs.

example/lib/main.dart

import 'dart:async';
import 'dart:ffi';
import 'dart:math';

import 'package:flutter/material.dart';
import 'package:wheel_expand_list/wheel_expand_list.dart';
import 'package:wheel_expand_list/wheel_logic.dart';
import 'package:wheel_expand_list/wheel_swipe_type.dart';
import 'package:wheel_expand_list_example/wheel_data_set.dart';
import 'package:wheel_expand_list_example/wheel_example2.dart';
import 'package:wheel_expand_list_example/wheel_extension_logic.dart';
import 'package:wheel_expand_list_example/wheel_widget.dart';

void main() {
  runApp(const WheelExample());
}

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const WheelPage(),
    );
  }
}

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

  @override
  State<WheelPage> createState() => _WheelPageState();
}

class _WheelPageState extends State<WheelPage> {
  var wheelLogic = WheelLogic();
  late WheelDataSet wheelDataSet;
  late WheelWidget wheelWidget;
  var slideActionFlg = false;

  /// Example
  void _updateData(bool flg) {
    setState(() {
      wheelLogic.textList.clear();
      wheelLogic.pageList.clear();
      for (var i = 1; i < 11; i++) {
        wheelLogic.textList
            .add(''.generateRandomString(i * 0.randomIntWithRange(1, 100)));
        wheelLogic.pageList.add(0.randomIntWithRange(1, 9));
      }
      wheelLogic.valueSet = wheelLogic.pageList.first;
      wheelLogic.fontSize = 0.randomIntWithRange(10, 50).toDouble();
      wheelLogic.margin = 0.randomIntWithRange(50, 200).toDouble();

      _setHeightValue(flg);
    });
  }

  void _setHeightValue(bool flg) {
    if (flg) {
      wheelLogic.initSet(
        marginSet: wheelLogic.fontSize,
        fontSizeSet: wheelLogic.margin,
        again: true,
      );
    }

    wheelDataSet = WheelDataSet(
      logic: wheelLogic,
      slideActionFlg: slideActionFlg,
    );
    wheelWidget = WheelWidget(
      marginSet: wheelLogic.margin,
      fontSizeSet: wheelLogic.fontSize,
    );
    if (!flg) {
      Future.delayed(const Duration(milliseconds: 100), () {
        wheelLogic.initSet(
          marginSet: wheelLogic.fontSize,
          fontSizeSet: wheelLogic.margin,
          again: false,
        );
      });
    }
  }

  /// Example
  void _updateSwipeType() {
    setState(() {
      if (wheelDataSet.swipeType == WheelSwipeType.left) {
        wheelLogic.swipeType = WheelSwipeType.right;
      } else {
        wheelLogic.swipeType = WheelSwipeType.left;
      }
      wheelDataSet = WheelDataSet(
        logic: wheelLogic,
        slideActionFlg: slideActionFlg,
      );
      wheelWidget = WheelWidget(
        marginSet: wheelLogic.margin,
        fontSizeSet: wheelLogic.fontSize,
      );
      wheelLogic.initSet(
        marginSet: wheelLogic.fontSize,
        fontSizeSet: wheelLogic.margin,
        again: false,
      );
    });
  }

  Widget _rightOfRightButton() {
    return IconButton(
      icon: const Icon(Icons.arrow_forward),
      onPressed: () => {
        setState(
          () {
            Navigator.push(
              context,
              MaterialPageRoute(
                builder: (context) => const WheelExample2(),
              ),
            );
          },
        ),
      },
    );
  }

  Widget _rightOfLeftButton() {
    return IconButton(
      icon: wheelDataSet.swipeType == WheelSwipeType.right
          ? const Icon(Icons.keyboard_arrow_left)
          : const Icon(Icons.keyboard_arrow_right),
      onPressed: () => {
        setState(() {
          _updateSwipeType();
        }),
      },
    );
  }

  @override
  void initState() {
    _updateData(true);
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        leadingWidth: 100,
        title:
            Text('index${wheelLogic.indexCount}: page${wheelLogic.pageCount}'),
        actions: [
          Row(
            children: [
              _rightOfLeftButton(),
              _rightOfRightButton(),
            ],
          ),
        ],
        leading: Row(
          children: [
            IconButton(
              icon: const Icon(Icons.update),
              onPressed: () => {
                setState(() {
                  _updateData(false);
                }),
              },
            ),
            IconButton(
              icon: const Icon(Icons.cached_outlined),
              onPressed: () => {
                setState(() {
                  slideActionFlg = !slideActionFlg;
                  wheelDataSet = WheelDataSet(
                    logic: wheelLogic,
                    slideActionFlg: slideActionFlg,
                  );
                }),
              },
            ),
          ],
        ),
      ),
      body: Stack(
        children: [
          wheelWidget.loopWidget(
            context,
            wheelLogic.globalKeys,
            wheelLogic.textList,
            wheelLogic.margin,
            wheelLogic.fontSize,
          ),
          StreamBuilder(
            stream: wheelLogic.streamController.stream,
            builder: (
              BuildContext context,
              AsyncSnapshot<List<double>> snapshot,
            ) {
              if (snapshot.hasData) {
                return SingleChildScrollView(
                  child: Column(
                    children: [
                      WheelExpandList(
                        callBack: (index) {
                          Future(() {
                            setState(() {
                              wheelLogic.indexCount = index;
                            });
                          });
                        },
                        pageStart: (index) {
                          slideActionFlg
                              ? wheelDataSet.startController(
                                  index,
                                  300,
                                  wheelLogic.controller,
                                  Curves.slowMiddle,
                                )
                              : wheelDataSet.startController(
                                  index,
                                  300,
                                  wheelLogic.controller,
                                  Curves.easeOut,
                                );
                        },
                        pageEnd: (value) {
                          setState(() {
                            Future(() {
                              wheelLogic.indexCount = 0;
                              wheelLogic.pageCount = value;
                            });
                          });
                        },
                        wheelDataModel: wheelDataSet,
                        wheelPrimitiveWidget: wheelWidget,
                        wheelLogic: wheelLogic,
                      ),
                    ],
                  ),
                );
              } else {
                return Container();
              }
            },
          ),
        ],
      ),
    );
  }
}
7
likes
0
points
74
downloads

Publisher

verified publishereverydaysoft.co.jp

Weekly Downloads

It works in 3D with horizontal scrolling. If the area is exceeded, vertical scrolling occurs.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on wheel_expand_list