Skip to content

Commit

Permalink
Add url_launcher to gemini sample
Browse files Browse the repository at this point in the history
  • Loading branch information
johnpryan committed Feb 13, 2024
1 parent c3cce67 commit 75984e6
Show file tree
Hide file tree
Showing 7 changed files with 122 additions and 68 deletions.
1 change: 1 addition & 0 deletions pkgs/dart_services/lib/src/project_templates.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ const Set<String> supportedFlutterPackages = {
'provider',
'riverpod_navigator',
'shared_preferences',
'url_launcher',
'video_player',
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,14 @@
"tuple": "2.0.2",
"typed_data": "1.3.2",
"unicode": "0.3.1",
"url_launcher": "6.2.4",
"url_launcher_android": "6.2.2",
"url_launcher_ios": "6.2.4",
"url_launcher_linux": "3.1.1",
"url_launcher_macos": "3.1.0",
"url_launcher_platform_interface": "2.3.1",
"url_launcher_web": "2.2.3",
"url_launcher_windows": "3.1.1",
"vector_graphics": "1.1.10+1",
"vector_graphics_codec": "1.1.10+1",
"vector_graphics_compiler": "1.1.10+1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,14 @@
"tuple": "2.0.2",
"typed_data": "1.3.2",
"unicode": "0.3.1",
"url_launcher": "6.2.4",
"url_launcher_android": "6.2.2",
"url_launcher_ios": "6.2.4",
"url_launcher_linux": "3.1.1",
"url_launcher_macos": "3.1.0",
"url_launcher_platform_interface": "2.3.1",
"url_launcher_web": "2.2.3",
"url_launcher_windows": "3.1.1",
"vector_graphics": "1.1.10+1",
"vector_graphics_codec": "1.1.10+1",
"vector_graphics_compiler": "1.1.10+1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,14 @@
"tuple": "2.0.2",
"typed_data": "1.3.2",
"unicode": "0.3.1",
"url_launcher": "6.2.4",
"url_launcher_android": "6.2.2",
"url_launcher_ios": "6.2.4",
"url_launcher_linux": "3.1.1",
"url_launcher_macos": "3.1.0",
"url_launcher_platform_interface": "2.3.1",
"url_launcher_web": "2.2.3",
"url_launcher_windows": "3.1.1",
"vector_graphics": "1.1.10+1",
"vector_graphics_codec": "1.1.10+1",
"vector_graphics_compiler": "1.1.10+1",
Expand Down
82 changes: 48 additions & 34 deletions pkgs/samples/lib/gemini.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import 'package:flutter/material.dart';
import 'package:flutter_markdown/flutter_markdown.dart';
import 'package:google_generative_ai/google_generative_ai.dart';
import 'package:url_launcher/link.dart';

void main() {
runApp(const GenerativeAISample());
Expand Down Expand Up @@ -48,15 +49,15 @@ class _ChatScreenState extends State<ChatScreen> {
),
body: apiKey == null
? ApiKeyWidget(
onSubmitted: (key) {
setState(() {
apiKey = key;
});
},
)
onSubmitted: (key) {
setState(() {
apiKey = key;
});
},
)
: ChatWidget(
apiKey: apiKey!,
),
apiKey: apiKey!,
),
);
}
}
Expand All @@ -69,31 +70,44 @@ class ApiKeyWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
mainAxisSize: MainAxisSize.min,
children: [
const Text('Enter your API key'),
Row(
children: [
Expanded(
child: TextField(
decoration:
textFieldDecoration(context, 'Enter your API key'),
controller: _textController,
onSubmitted: (value) {
onSubmitted(value);
body: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
const Text(
"To use the Gemini API, you'll need an API key. If you don't already have one, create a key in Google AI Studio."),
Link(
uri: Uri.parse('https://makersuite.google.com/app/apikey'),
builder: (context, followLink) {
return TextButton(
onPressed: followLink,
child: const Text('Get an API Key'),
);
},
),
Row(
children: [
Expanded(
child: TextField(
decoration:
textFieldDecoration(context, 'Enter your API key'),
controller: _textController,
onSubmitted: (value) {
onSubmitted(value);
},
),
),
TextButton(
onPressed: () {
onSubmitted(_textController.value.text);
},
child: const Text('Submit'),
),
),
TextButton(
onPressed: () {
onSubmitted(_textController.value.text);
},
child: const Text('Submit'),
),
],
),
],
],
),
],
),
),
);
}
Expand Down Expand Up @@ -127,7 +141,7 @@ class _ChatWidgetState extends State<ChatWidget> {

void _scrollDown() {
WidgetsBinding.instance.addPostFrameCallback(
(_) => _scrollController.animateTo(
(_) => _scrollController.animateTo(
_scrollController.position.maxScrollExtent,
duration: const Duration(
milliseconds: 750,
Expand Down Expand Up @@ -174,7 +188,7 @@ class _ChatWidgetState extends State<ChatWidget> {
autofocus: true,
focusNode: _textFieldFocus,
decoration:
textFieldDecoration(context, 'Enter a prompt...'),
textFieldDecoration(context, 'Enter a prompt...'),
controller: _textController,
onSubmitted: (String value) {
_sendChatMessage(value);
Expand Down Expand Up @@ -275,7 +289,7 @@ class MessageWidget extends StatelessWidget {
Widget build(BuildContext context) {
return Row(
mainAxisAlignment:
isFromUser ? MainAxisAlignment.end : MainAxisAlignment.start,
isFromUser ? MainAxisAlignment.end : MainAxisAlignment.start,
children: [
Flexible(
child: Container(
Expand Down
1 change: 1 addition & 0 deletions pkgs/samples/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ dev_dependencies:
path: ^1.8.0
flutter_markdown: any
google_generative_ai: any
url_launcher: any

flutter:
uses-material-design: true
82 changes: 48 additions & 34 deletions pkgs/sketch_pad/lib/samples.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 75984e6

Please sign in to comment.