heroiclabs / nakama-dart

Pure Dart Client for Nakama Server
https://heroiclabs.com/docs/nakama/client-libraries/dart
166 stars 51 forks source link

client.listGroups is not work #81

Closed zhangyc closed 9 months ago

zhangyc commented 9 months ago

Describe the bug I can see the group I created at http://127.0.0.1:7351/#/groups. But when I query, the group[] returned by the client is empty Reproduction Code Note: This is mandatory! If your issue does not contain it, it will be closed.

Example:

import 'package:flutter/material.dart';
import 'package:my_anime/utils/nakama_util.dart';
import 'package:nakama/nakama.dart';

class GroupListPage extends StatefulWidget {
  const GroupListPage({super.key});
  static const routeName = 'group_list';

  @override
  State<GroupListPage> createState() => _GroupListState();
}

class _GroupListState extends State<GroupListPage> {
  TextEditingController _groupNameController = TextEditingController();
  TextEditingController _groupDescriptionController = TextEditingController();

  // 校验群名称
  String? _validateGroupName(String? value) {
    if (value==null) {
      return 'Group Name is required';
    }
    if (value.isEmpty) {
      return 'Group Name is required';
    }
    // 可以添加其他校验逻辑
    return null;
  }

  // 校验群描述
  String? _validateGroupDescription(String? value) {
    if (value==null) {
      return 'Group Name is required';
    }
    if (value.isEmpty) {
      return 'Group Description is required';
    }
    // 可以添加其他校验逻辑
    return null;
  }
  List<Group> groups=[];
  @override
  void initState() {
    getGroupList().then((value){
      groups=value.groups;
      setState(() {

      });
    });
    super.initState();
  }
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Group'),
      ),
      floatingActionButton: ElevatedButton(onPressed: ()async{
         Group? g=await _showGroupDialog(context);
         if(g!=null){
           getGroupList().then((value){
             groups=value.groups;
             setState(() {

             });
           });
         }
       }, child: Icon(Icons.add)),
      body: ListView.separated(itemBuilder: (_,i){
        return ListTile(
          title: Text(groups[i].name??'',style: TextStyle(
            color: Colors.black
          ),),
        );
      }, separatorBuilder: (_,__){
        return SizedBox(
          height: 16,
        );
      }, itemCount: groups.length),

    );
  }
  Future<Group?> _showGroupDialog(BuildContext context) async {
    return showDialog<Group?>(
      context: context,
      builder: (BuildContext context) {
        return AlertDialog(
          title: Text('Create Group'),
          content: Column(
            children: [
              // 群名称输入框
              TextFormField(
                controller: _groupNameController,
                decoration: InputDecoration(labelText: 'Group Name'),
                validator: _validateGroupName,
              ),
              SizedBox(height: 16.0),
              // 群描述输入框
              TextFormField(
                controller: _groupDescriptionController,
                decoration: InputDecoration(labelText: 'Group Description'),
                validator: _validateGroupDescription,
              ),
            ],
          ),
          actions: <Widget>[
            TextButton(
              onPressed: () {
                Navigator.of(context).pop();
              },
              child: Text('Cancel'),
            ),
            TextButton(
              onPressed: () async{
                // 验证通过才执行操作
                if (_validateGroupName(_groupNameController.text) == null &&
                    _validateGroupDescription(_groupDescriptionController.text) == null) {
                  print('Group Name: ${_groupNameController.text}');
                  print('Group Description: ${_groupDescriptionController.text}');
                  Group group=await createGroup(_groupNameController.text, _groupDescriptionController.text);
                  Navigator.of(context).pop(group);
                }
              },
              child: Text('Create'),
            ),
          ],
        );
      },
    );
  }
  @override
  void dispose() {
    _groupNameController.dispose();
    _groupDescriptionController.dispose();
    super.dispose();
  }
}
///查询群列表
Future<GroupList> getGroupList({String? filters,int? pageSize}) async{
 return await client.listGroups(
    session: userSession!,
    limit: pageSize??20,
  );
}

Expected behavior You can return to the group list Screenshots image

Flutter Doctor

[✓] Flutter (Channel stable, 3.16.0, on macOS 14.1.1 23B81 darwin-arm64, locale zh-Hans-CN)
[!] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    ✗ cmdline-tools component is missing
      Run `path/to/sdkmanager --install "cmdline-tools;latest"`
      See https://developer.android.com/studio/command-line for more details.
    ✗ Android license status unknown.
      Run `flutter doctor --android-licenses` to accept the SDK licenses.
      See https://flutter.dev/docs/get-started/install/macos#android-setup for more details.
[✓] Xcode - develop for iOS and macOS (Xcode 15.0.1)
[✗] Chrome - develop for the web (Cannot find Chrome executable at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome)
    ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.
[✓] Android Studio (version 2022.3)
[✓] VS Code (version 1.85.1)
[✓] VS Code (version 1.85.1)
[✓] Connected device (3 available)
[!] Network resources
    ✗ A cryptographic error occurred while checking "https://pub.dev/": Connection terminated during handshake
      You may be experiencing a man-in-the-middle attack, your network may be compromised, or you may have malware installed on your computer.
    ✗ A cryptographic error occurred while checking "https://storage.googleapis.com/": Connection terminated during handshake
      You may be experiencing a man-in-the-middle attack, your network may be compromised, or you may have malware installed on your computer.
    ✗ A cryptographic error occurred while checking "https://maven.google.com/": Connection terminated during handshake
      You may be experiencing a man-in-the-middle attack, your network may be compromised, or you may have malware installed on your computer.
    ✗ A cryptographic error occurred while checking "https://github.com/": Connection terminated during handshake
      You may be experiencing a man-in-the-middle attack, your network may be compromised, or you may have malware installed on your computer.

! Doctor found issues in 3 categories.

pubspec.yaml

nakama: ^1.0.4

Additional context Add any other context about the problem here.

zhangyc commented 9 months ago

add params session: userSession!, limit: pageSize??20, open: true, members: 1 it's work

zhangyc commented 9 months ago

oh ...it's not work.

zhangyc commented 9 months ago

Future getGroupList({String? filters,int? pageSize}) async{ return await client.listGroups( session: userSession!, limit: pageSize??20, open: true, members: 2 ); } When I delete members: 2 When this attribute is used, grouplist returns [] empty. Why is the current number of group members a query condition?

obrunsmann commented 9 months ago

@zhangyc

Please use code blocks next time. Code as text is really unreadable.

There was a problem that the result could not be parsed if cursor is null. I have fixed that. I guess that was the cause of your problem. Please let me know if the problem remains.

Releasing v1.0.5 soon.