Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Unwanted vibrations on init or onSelect #603

Open
im-sacha-cohen opened this issue Sep 15, 2024 · 0 comments
Open

[Bug] Unwanted vibrations on init or onSelect #603

im-sacha-cohen opened this issue Sep 15, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@im-sacha-cohen
Copy link

Steps to reproduce

  1. Run the code on an iPhone

Expected results

The component should initialize, show the list and select an item without the device vibration.

Actual results

On iOS (not tested yet on Android's real device), when the TypeAheadField component is initiated or the list shown, or an item selected, it triggers un unwanted Haptick Feedback.

Package Version

5.2.0

Platform

iOS

Code sample

Code sample
import 'dart:convert';
import 'package:auralib/screens/professional/insitutes.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_typeahead/flutter_typeahead.dart';

class HomeJob extends StatefulWidget {
  const HomeJob({
    super.key,
    required this.onSelect,
  });

  final void Function(Map<String, dynamic>) onSelect;

  @override
  State<HomeJob> createState() => _HomeJobState();
}

class _HomeJobState extends State<HomeJob> {
  List<Map<String, dynamic>> _jobs = [];
  final _selectedJob = TextEditingController();

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

  void _findJobs() async {
    final jobs = await request.get('/job-referential');
    setState(() {
      _jobs = List<Map<String, dynamic>>.from(json.decode(jobs.body)['object']);
    });
  }

  Widget _getColumn(controller, focusNode) {
    return Column(
      mainAxisAlignment: MainAxisAlignment.start,
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Text(
          'What are you searching for ?',
          style: Theme.of(context).textTheme.titleSmall,
        ),
        const SizedBox(height: 5),
        CupertinoTextField(
          placeholder: 'Search for a job type',
          controller: controller,
          autofocus: false,
          focusNode: focusNode,
          padding: const EdgeInsets.all(10),
          decoration: BoxDecoration(
            borderRadius: BorderRadius.circular(8),
            border: Border.all(
              color: Colors.grey[200]!,
            ),
          ),
        )
      ],
    );
  }

  @override
  Widget build(BuildContext context) {
    return _jobs.isNotEmpty
        ? TypeAheadField(
            controller: _selectedJob,
            decorationBuilder: (context, child) {
              return Container(
                decoration: BoxDecoration(
                  color: Colors.white,
                  borderRadius: BorderRadius.circular(8),
                  border: Border.all(
                    color: Colors.grey[200]!,
                  ),
                ),
                child: child,
              );
            },
            suggestionsCallback: (search) {
              return _jobs.where((job) {
                return job['name'].toLowerCase().contains(search.toLowerCase());
              }).toList();
            },
            builder: (context, controller, focusNode) {
              return _getColumn(controller, focusNode);
            },
            itemBuilder: (context, job) {
              return ListTile(
                title: Text(
                  job['name'],
                  style: Theme.of(context).textTheme.bodyMedium,
                ),
              );
            },
            onSelected: (job) {
              widget.onSelect(job);

              setState(() {
                _selectedJob.text = job['name'];
              });
            },
          )
        : _getColumn(_selectedJob, null);
  }
}

Logs

Logs
[Paste your logs here]

Screenshots or Video

Screenshots / Video demonstration [Upload media here]
@im-sacha-cohen im-sacha-cohen added the bug Something isn't working label Sep 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant