appinioGmbH / flutter_packages

Dart and Flutter plugins/packages used and maintained by @appinioGmbH
193 stars 224 forks source link

[appinio_swiper] Can I use async methods? #85

Closed kzrnm closed 1 year ago

kzrnm commented 1 year ago

If onSwipe is an async method, onEnd will be executed before onSwipe is completed.

Code

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

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

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

  static const String _title = 'Swiper';

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: _title,
      home: Scaffold(
        appBar: AppBar(title: const Text(_title)),
        body: Center(
          child: AppinioSwiper(
            onSwipe: (index, direction) async {
              await Future.delayed(const Duration(milliseconds: 200));
              print({"name": "onSwipe", "index": index});
            },
            onEnd: () async {
              await Future.delayed(const Duration(milliseconds: 100));
              print({"name": "onEnd"});
            },
            cardsCount: 3,
            cardsBuilder: (BuildContext context, int index) {
              return Container(
                alignment: Alignment.center,
                color: Colors.blue,
                child: Text(index.toString()),
              );
            },
          ),
        ),
      ),
    );
  }
}

Console

{name: onSwipe, index: 1} {name: onSwipe, index: 2} {name: onEnd} {name: onSwipe, index: 3}

khanmujeeb687 commented 1 year ago

Hey @kzrnm yes you can.