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

Can't get data with await #5

Open
bubnenkoff opened this issue Sep 5, 2023 · 2 comments
Open

Can't get data with await #5

bubnenkoff opened this issue Sep 5, 2023 · 2 comments

Comments

@bubnenkoff
Copy link

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

import 'package:multiselect_dropdown_flutter/multiselect_dropdown_flutter.dart';

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

class Controller extends GetxController {

  var names = <Map<String, dynamic>>[].obs;

  @override
  void onInit() {
    super.onInit();
    fetchDataFromNetwork();
  }

  Future<void> fetchDataFromNetwork() async {
    // Эмулируем задержку, как будто данные загружаются из сети
    await Future.delayed(Duration(seconds: 1));

    // Получаем данные (в данном случае, данные получаются с сервера)
    final List<Map<String, dynamic>> data = [
      {'id': 'dog', 'label': 'Dog'},
      {'id': 'cat', 'label': 'Cat'},
      {'id': 'mouse', 'label': 'Mouse'},
      {'id': 'rabbit', 'label': 'Rabbit'},
    ];

    names.assignAll(data);
  }
}

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

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      title: 'MultiSelect Dropdown demo',
      home: MultiSelectExample(),
    );
  }
}

class MultiSelectExample extends StatelessWidget {
  
  const MultiSelectExample({super.key});
  
  @override
  Widget build(BuildContext context) {

    final Controller ctrl = Get.put(Controller());

    return Scaffold(
      body: Padding(
        padding: const EdgeInsets.all(20),
        child: Column(
          children: [
            MultiSelectDropdown(
              list: ctrl.names,
              initiallySelected: const [],
              onChange: (newList) {
                // your logic
                // typically setting state
              },
              numberOfItemsLabelToShow: 2, // label to be shown for 2 items
              whenEmpty:
                  'Choose from the list', // text to show when selected list is empty
            ),
          ],
        ),
      ),
    );
  }
}

pubspec.yaml:

dependencies:
  flutter:
    sdk: flutter
  multiselect_dropdown_flutter: ^0.0.7
  get: ^5.0.0-release-candidate-4
```

result: can't select anything from dropdown like it have no any data.
@bubnenkoff
Copy link
Author

it seems that widget do not check data update\changes

@AkshayAvhad23
Copy link

AkshayAvhad23 commented Jul 29, 2024

Populating data from network, and dropdown shows no values or what so ever. Checked for state refresh as well. State refresh call is given and it's not showing any data.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants