8000 Missing spaces in streamChat, streamGenerateContent, and promptStream output in gemini_implement.dart · Issue #47 · babakcode/flutter_gemini · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Missing spaces in streamChat, streamGenerateContent, and promptStream output in gemini_implement.dart #47
Open
@nhao2003

Description

@nhao2003

Description of the Issue:

When using the methods streamChat, streamGenerateContent, and promptStream, the output is missing spaces between words, causing words to be concatenated incorrectly.

Example:

  1. Expected output: "Hello World"
  2. Actual output: "HelloWorld"

Location of the Issue:
File: gemini_implement.dart

Current code:

res = res.trim();

if (index == 0 && res.startsWith("[")) {
  res = res.replaceFirst('[', '');
}
if (res.startsWith(',')) {
  res = res.replaceFirst(',', '');
}
if (res.endsWith(']')) {
  res = res.substring(0, res.length - 1);
}

res = res.trim();

Proposed Fix:
Use a separate variable (trimmedRes) to check conditions before modifying res, preventing unintended modifications that could cause words to be concatenated incorrectly:

String trimmedRes = res.trim();

if (index == 0 && trimmedRes.startsWith("[")) {
  res = res.replaceFirst('[', '');
}
if (trimmedRes.startsWith(',')) {
  res = res.replaceFirst(',', '');
}
if (trimmedRes.endsWith(']')) {
  res = res.substring(0, res.length - 1);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0