GetStream / stream-chat-flutter

Flutter Chat SDK - Build your own chat app experience using Dart, Flutter and the Stream Chat Messaging API.
https://getstream.io/chat/sdk/flutter/
Other
907 stars 334 forks source link

StreamMessageInput was blocked with `You don't have permission to send message`. #1102

Closed yahu1031 closed 2 years ago

yahu1031 commented 2 years ago

Which packages are you using?

stream_chat_flutter

On what platforms did you experience the issue?

iOS

What version are you using?

  stream_chat_flutter: ^4.0.0-beta.2

What happened?

When I run the app initially, The chat screen shows You don't have permission to send messages. But when I hot-restart the app and navigate to the report screen(chat screen), Then I can able to send messages. Please LMK if anything was wrong.

Expected

It must allow the user to send messages by default.

Steps to reproduce

Followed the create chat application docs from the website. Using the latest beta version. Here is the chat screen code mentioned below.

Supporting info to reproduce

main.dart

import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:stream_chat_flutter/stream_chat_flutter.dart';
import 'package:stream_chat_persistence/stream_chat_persistence.dart';

import 'app/constants/constants.const.dart';
import 'app/constants/global.const.dart';
import 'app/constants/routes.names.const.dart';
import 'meta/components/extensions/logger.ext.dart';
import 'meta/development/error.dev.dart';
import 'meta/utils/route.util.dart';

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  AppLogger.rootLevel = 'finer';
  ErrorWidget.builder = codeErrorScreenBuilder;
  AppLogger('main').finer('App started');
  StreamChatClient client = StreamChatClient(
    'vt6p8c5va5j6',
    logLevel: Level.FINE,
  )..chatPersistenceClient = StreamChatPersistenceClient(
      logLevel: Level.FINE,
      connectionMode: ConnectionMode.background,
    );
  await client.connectUser(
    User(id: AppConstants.appName),
    'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoiTHVuY2hib3gtV2FsYSJ9.iaQXzUv3-hZUhZlGO-rAyihJh5f0rwnp6ZFV1nXSZM8',
  );
  await client
      .channel('messaging', id: 'reporting', extraData: <String, Object?>{
    'name': 'Lunchbox-Wala Report',
    'image':
        'https://cdn.pixabay.com/photo/2016/11/18/23/38/child-1837375_960_720.png',
  }).watch();
  runApp(
    MyApp(
      client: client,
    ),
  );
}

class MyApp extends StatelessWidget {
  MyApp({required this.client, Key? key}) : super(key: key);
  final StreamChatClient client;
  final AppLogger _logger = AppLogger('MyApp');
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData(
        highlightColor: Colors.transparent,
        hoverColor: Colors.transparent,
        splashColor: Colors.transparent,
        splashFactory: NoSplash.splashFactory,
        visualDensity: VisualDensity.adaptivePlatformDensity,
        fontFamily: GoogleFonts.sourceSansPro().fontFamily,
        primaryColor: Colors.green,
        primarySwatch: Colors.green,
      ),
      builder: (BuildContext context, Widget? child) => StreamChat(
        client: client,
        child: child!,
      ),
      initialRoute: RouteNames.splash,
      onGenerateRoute: onGenerateRoute,
      onUnknownRoute: (RouteSettings settings) {
        _logger.finer('Unknown route: ${settings.name}');
        return pageTransition(
          settings,
          Scaffold(
            body: Center(
              child: Text('Unknown route: ${settings.name}'),
            ),
          ),
        );
      },
    );
  }
}

report.screen.dart

import 'package:flutter/material.dart';
import 'package:stream_chat_flutter/stream_chat_flutter.dart';
import 'package:tabler_icons/tabler_icons.dart';

class ReportChat extends StatefulWidget {
  const ReportChat({
    Key? key,
  }) : super(key: key);

  @override
  State<ReportChat> createState() => _ReportChatState();
}

class _ReportChatState extends State<ReportChat> {
  @override
  Widget build(BuildContext context) {
    return StreamChannel(
      channel:
          StreamChat.of(context).client.channel('messaging', id: 'reporting'),
      child: Scaffold(
        appBar: StreamChannelHeader(
          showConnectionStateTile: true,
          showTypingIndicator: true,
          leading: IconButton(
            icon: const Icon(
              TablerIcons.chevron_left,
              color: Colors.black,
            ),
            onPressed: () => Navigator.pop(context),
          ),
        ),
        body: Column(
          children: const <Widget>[
            Expanded(
              child: StreamMessageListView(),
            ),
            StreamMessageInput(
              showCommandsButton: false,
            ),
          ],
        ),
      ),
    );
  }
}

What I got

simulator_screenshot_0CD413D9-9D31-486A-A096-3B41A5835151

what I'm expecting

simulator_screenshot_C7E80948-F9C1-470D-BB43-855B5C8EE1B2

Relevant log output

Before hot-restart

After hot-restart

Flutter analyze output

minnu@Minnus-Mac lunchboxwala % flutter analyze             
Analyzing lunchboxwala...                                               
No issues found! (ran in 3.2s)

### Flutter doctor output

```shell
minnu@Minnus-Mac lunchboxwala % flutter doctor --verbose
[✓] Flutter (Channel stable, 2.10.5, on macOS 12.3.1 21E258 darwin-arm, locale en-IN)
    • Flutter version 2.10.5 at /Users/minnu/Development/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 5464c5bac7 (7 days ago), 2022-04-18 09:55:37 -0700
    • Engine revision 57d3bac3dd
    • Dart version 2.16.2
    • DevTools version 2.9.2

[✓] Android toolchain - develop for Android devices (Android SDK version 32.1.0-rc1)
    • Android SDK at /Users/minnu/Library/Android/sdk
    • Platform android-32, build-tools 32.1.0-rc1
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6916264)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 13.3.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • CocoaPods version 1.11.3

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 4.2)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6916264)

[✓] VS Code (version 1.66.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.39.20220405

[✓] Connected device (3 available)
    • iPhone 12 (mobile) • D3EC02F1-A9CE-41B7-9B41-041D0C6F986B • ios            • com.apple.CoreSimulator.SimRuntime.iOS-15-4 (simulator)
    • macOS (desktop)    • macos                                • darwin-arm64   • macOS 12.3.1 21E258 darwin-arm
    • Chrome (web)       • chrome                               • web-javascript • Google Chrome 100.0.4896.127

[✓] HTTP Host Availability
    • All required HTTP hosts are available

• No issues found!

Code of Conduct

FCView commented 2 years ago

I am receiving this on 4.1.0. My users are getting the same "You don't have permission to send messages" error.

They can send messages again after restarting the app.

I see that this is added to Sprint 6, following for any updates/fixes.