Home > Mobile >  How to add mulitiple event linsteners in GestureDetector class?
How to add mulitiple event linsteners in GestureDetector class?

Time:08-22

I'm setting onTap() event noted //here below and want to add focus event at the same time. I could not find such event on docs, and could somebody help me how can I set such focused event liteners and multiply as well.

import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

void showPicker(context, controller) {
  var year = DateTime.now().year;
  final list = [];
  for (var i = (year - 100); i < (year   1); i  ) {
    list.add(i.toString());
  }

  final pickerItems = list.map((item) => Text(item)).toList();
  var selectedIndex = 0;

  showCupertinoModalPopup<void>(
    context: context,
    builder: (BuildContext context) {
      return Container(
        height: 216,
        child: GestureDetector(
          onTap: () {//here
            Navigator.pop(context);
          },
          child: CupertinoPicker(
            backgroundColor: Colors.white,
            itemExtent: 32,
            children: pickerItems,
            scrollController: FixedExtentScrollController(//初期開始位置
              initialItem: 90,
            ),
            onSelectedItemChanged: (int index) {
              selectedIndex = index;
              print(selectedIndex);
            },
          ),
        ),
      );
    },
  ).then((_) {
    if (selectedIndex != null) {
      controller.value = TextEditingValue(text: list[selectedIndex]);
    }
  });
  ;
}

CodePudding user response:

Try to use FocusableActionDetector. In your case it should be looks like:

GestureDetector(
  onTap: () {},
  child: FocusableActionDetector(
    child: CupertinoPicker(),
  ),
),
  • Related