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

Update Flutter sample to align closer with downstream DartPad version #77

Merged
merged 3 commits into from
Feb 28, 2024

Conversation

parlough
Copy link
Contributor

  • Allow ChatWidget to accept an API key, since we use a different method of specifying it, and users might want to as well.
  • Follow member ordering and variable style consistently between classes
  • Reduce max width of message slightly
  • Avoid reevaluating _chat.history iterable then running toList for each item in ListView.builder

Copy link
Collaborator

@devoncarew devoncarew left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@johnpryan - can you review this? (cc @natebosch for FYI)

@natebosch natebosch merged commit 112637e into google-gemini:main Feb 28, 2024
2 checks passed
@parlough parlough deleted the misc/update-flutter-sample branch February 28, 2024 01:48
///
/// To learn how to generate and specify this key,
/// check out the README file of this sample.
const String _apiKey = String.fromEnvironment('API_KEY');
Copy link
Contributor

@lrhn lrhn Feb 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could make this nullable, instead of the empty string, as:

const String? _apiKey = bool.hasEnvironment('API_KEY') ? String.fromEnvironment('API_KEY') : null;`

or

const String _envApiKey = String.fromEnvironment('API_KEY');
const String? _apiKey = _envApiKey == "" ? null : _envApiKey;

/// To learn how to generate and specify this key,
/// check out the README file of this sample.
const String _apiKey = String.fromEnvironment('API_KEY');

void main() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider providing the API key as a command line argument instead.

onst String _envApiKey = String.fromEnvironment('API_KEY');
final String? _apiKey = _envApiKey == "" ? null : _envApiKey;
void main(List<String> args) {
  String? apiKey = _apiKey;
  if (args.isNotEmpty) {
    apiKey = args.first;
  }
  if (apiKey == null) {
    stderr.writeln("No API key specified");
    exit(1);
  }
  // use it

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

Successfully merging this pull request may close these issues.

None yet

5 participants