|
| 1 | +// Copyright 2025 The Flutter Authors. All rights reserved. |
| 2 | +// Use of this source code is governed by a BSD-style license that can be |
| 3 | +// found in the LICENSE file. |
| 4 | + |
| 5 | +import 'package:firebase_ai/firebase_ai.dart'; |
| 6 | +import 'package:firebase_core/firebase_core.dart'; |
| 7 | +import 'package:flutter/material.dart'; |
| 8 | +import 'package:flutter_ai_toolkit/flutter_ai_toolkit.dart'; |
| 9 | + |
| 10 | +import '../firebase_options.dart'; |
| 11 | + |
| 12 | +void main() async { |
| 13 | + WidgetsFlutterBinding.ensureInitialized(); |
| 14 | + await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform); |
| 15 | + runApp(const App()); |
| 16 | +} |
| 17 | + |
| 18 | +class App extends StatelessWidget { |
| 19 | + static const title = 'Example: Google Gemini AI'; |
| 20 | + |
| 21 | + const App({super.key}); |
| 22 | + |
| 23 | + @override |
| 24 | + Widget build(BuildContext context) => |
| 25 | + const MaterialApp(title: title, home: CustomStringsExample()); |
| 26 | +} |
| 27 | + |
| 28 | +class CustomStringsExample extends StatelessWidget { |
| 29 | + static const title = 'Custom Chat Strings'; |
| 30 | + |
| 31 | + const CustomStringsExample({super.key}); |
| 32 | + |
| 33 | + @override |
| 34 | + Widget build(BuildContext context) { |
| 35 | + final customStrings = const LlmChatViewStrings( |
| 36 | + addAttachment: 'Add', |
| 37 | + attachFile: 'Attach File', |
| 38 | + takePhoto: 'Take Photo', |
| 39 | + stop: '⏹️ Stop', |
| 40 | + close: '❌ Close', |
| 41 | + cancel: '❌ Cancel', |
| 42 | + copyToClipboard: '📋 Copy', |
| 43 | + editMessage: '✏️ Edit', |
| 44 | + attachImage: '🖼️ Add Image', |
| 45 | + recordAudio: '🎤 Record', |
| 46 | + submitMessage: '📤 Send', |
| 47 | + closeMenu: '❌ Close Menu', |
| 48 | + |
| 49 | + // Message related |
| 50 | + typeAMessage: 'Type your message here...', |
| 51 | + recording: '🔴 Recording...', |
| 52 | + tapToStop: 'Tap to stop', |
| 53 | + tapToRecord: 'Tap to record', |
| 54 | + releaseToCancel: 'Release to cancel', |
| 55 | + slideToCancel: 'Slide to cancel', |
| 56 | + |
| 57 | + submit: 'Submit', |
| 58 | + send: 'Send', |
| 59 | + delete: '🗑️ Delete', |
| 60 | + edit: '✏️ Edit', |
| 61 | + copy: '📋 Copy', |
| 62 | + share: '↗️ Share', |
| 63 | + retry: '🔄 Retry', |
| 64 | + yes: '✅ Yes', |
| 65 | + no: '❌ No', |
| 66 | + clear: '🗑️ Clear', |
| 67 | + search: '🔍 Search', |
| 68 | + |
| 69 | + // Messages and errors |
| 70 | + messageCopiedToClipboard: '📋 Copied to clipboard!', |
| 71 | + editing: '✏️ Editing', |
| 72 | + error: '❌ Error', |
| 73 | + cancelMessage: 'Cancel', |
| 74 | + confirmDelete: 'Confirm Delete', |
| 75 | + areYouSureYouWantToDeleteThisMessage: |
| 76 | + 'Are you sure you want to delete this message?', |
| 77 | + errorSendingMessage: '❌ Failed to send message', |
| 78 | + errorLoadingMessages: '❌ Failed to load messages', |
| 79 | + noMessagesYet: 'No messages yet. Start the conversation!', |
| 80 | + tapToRetry: 'Tap to retry', |
| 81 | + noResultsFound: 'No results found', |
| 82 | + unableToRecordAudio: 'Unable to record audio', |
| 83 | + unsupportedImageSource: 'Unsupported image source', |
| 84 | + unableToPickImage: 'Unable to pick image', |
| 85 | + unableToPickFile: 'Unable to pick file', |
| 86 | + unableToPickUrl: 'Unable to process URL', |
| 87 | + ); |
| 88 | + |
| 89 | + return Scaffold( |
| 90 | + appBar: AppBar(title: const Text(App.title)), |
| 91 | + body: LlmChatView( |
| 92 | + provider: FirebaseProvider( |
| 93 | + model: FirebaseAI.googleAI().generativeModel( |
| 94 | + model: 'gemini-2.0-flash', |
| 95 | + ), |
| 96 | + ), |
| 97 | + strings: customStrings, |
| 98 | + style: LlmChatViewStyle(strings: customStrings), |
| 99 | + ), |
| 100 | + ); |
| 101 | + } |
| 102 | +} |
0 commit comments