diff --git a/CHANGELOG.md b/CHANGELOG.md index 974cdf7a..d935d658 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,12 @@ +## 1.2.0 + +- Migrated `package:flutter/material.dart` and `package:flutter/cupertino.dart` + imports to `package:material_ui/material_ui.dart` (`^1.11.1`) and + `package:cupertino_ui/cupertino_ui.dart` (`^1.1.7`). +- Raised minimum SDK constraints to Dart `^3.13.0` and Flutter `>=3.47.0`. +- Updated the `vertex` example from `FirebaseAI.vertexAI()` to + `FirebaseAI.agentPlatform()`. + ## 1.1.0 - **BREAKING CHANGE**: Suppressed Markdown images in `LlmMessageView` by default diff --git a/example/lib/callbacks/on_cancel.dart b/example/lib/callbacks/on_cancel.dart index cdab8e53..1e7bc4e3 100644 --- a/example/lib/callbacks/on_cancel.dart +++ b/example/lib/callbacks/on_cancel.dart @@ -4,7 +4,7 @@ import 'package:firebase_ai/firebase_ai.dart'; import 'package:firebase_core/firebase_core.dart'; -import 'package:flutter/material.dart'; +import 'package:material_ui/material_ui.dart'; import 'package:flutter_ai_toolkit/flutter_ai_toolkit.dart'; // from `flutterfire config`: https://firebase.google.com/docs/flutter/setup @@ -30,9 +30,8 @@ class ChatPage extends StatelessWidget { const ChatPage({super.key}); void _onCancel(BuildContext context) { - ScaffoldMessenger.of( - context, - ).showSnackBar(const SnackBar(content: Text('Chat cancelled'))); + ScaffoldMessenger.of(context) + .showSnackBar(const SnackBar(content: Text('Chat cancelled'))); } @override diff --git a/example/lib/callbacks/on_error.dart b/example/lib/callbacks/on_error.dart index 41759012..f2f569d5 100644 --- a/example/lib/callbacks/on_error.dart +++ b/example/lib/callbacks/on_error.dart @@ -4,7 +4,7 @@ import 'package:firebase_ai/firebase_ai.dart'; import 'package:firebase_core/firebase_core.dart'; -import 'package:flutter/material.dart'; +import 'package:material_ui/material_ui.dart'; import 'package:flutter_ai_toolkit/flutter_ai_toolkit.dart'; // from `flutterfire config`: https://firebase.google.com/docs/flutter/setup @@ -30,9 +30,8 @@ class ChatPage extends StatelessWidget { const ChatPage({super.key}); void _onError(BuildContext context, LlmException error) { - ScaffoldMessenger.of( - context, - ).showSnackBar(SnackBar(content: Text('Error: ${error.message}'))); + ScaffoldMessenger.of(context) + .showSnackBar(SnackBar(content: Text('Error: ${error.message}'))); } @override diff --git a/example/lib/cupertino/cupertino.dart b/example/lib/cupertino/cupertino.dart index ebdefd76..339b31bc 100644 --- a/example/lib/cupertino/cupertino.dart +++ b/example/lib/cupertino/cupertino.dart @@ -4,7 +4,7 @@ import 'package:firebase_ai/firebase_ai.dart'; import 'package:firebase_core/firebase_core.dart'; -import 'package:flutter/cupertino.dart'; +import 'package:cupertino_ui/cupertino_ui.dart'; import 'package:flutter_ai_toolkit/flutter_ai_toolkit.dart'; // from `flutterfire config`: https://firebase.google.com/docs/flutter/setup diff --git a/example/lib/custom_strings/custom_strings.dart b/example/lib/custom_strings/custom_strings.dart index da1749a8..cdb14026 100644 --- a/example/lib/custom_strings/custom_strings.dart +++ b/example/lib/custom_strings/custom_strings.dart @@ -4,7 +4,7 @@ import 'package:firebase_ai/firebase_ai.dart'; import 'package:firebase_core/firebase_core.dart'; -import 'package:flutter/material.dart'; +import 'package:material_ui/material_ui.dart'; import 'package:flutter_ai_toolkit/flutter_ai_toolkit.dart'; import '../firebase_options.dart'; diff --git a/example/lib/custom_stt/custom_stt.dart b/example/lib/custom_stt/custom_stt.dart index 6fbab793..46a8fcb0 100644 --- a/example/lib/custom_stt/custom_stt.dart +++ b/example/lib/custom_stt/custom_stt.dart @@ -5,7 +5,7 @@ import 'package:cross_file/cross_file.dart'; import 'package:firebase_ai/firebase_ai.dart'; import 'package:firebase_core/firebase_core.dart'; -import 'package:flutter/material.dart'; +import 'package:material_ui/material_ui.dart'; import 'package:flutter_ai_toolkit/flutter_ai_toolkit.dart'; // from `flutterfire config`: https://firebase.google.com/docs/flutter/setup diff --git a/example/lib/custom_styles/custom_styles.dart b/example/lib/custom_styles/custom_styles.dart index d90225ec..8d806985 100644 --- a/example/lib/custom_styles/custom_styles.dart +++ b/example/lib/custom_styles/custom_styles.dart @@ -4,7 +4,7 @@ import 'package:firebase_ai/firebase_ai.dart'; import 'package:firebase_core/firebase_core.dart'; -import 'package:flutter/material.dart'; +import 'package:material_ui/material_ui.dart'; import 'package:flutter_ai_toolkit/flutter_ai_toolkit.dart'; import 'package:flutter_markdown_plus/flutter_markdown_plus.dart'; import 'package:google_fonts/google_fonts.dart'; @@ -86,35 +86,34 @@ class _ChatPageState extends State ), body: AnimatedBuilder( animation: _animationController, - builder: - (context, child) => Stack( - children: [ - SizedBox( - height: double.infinity, - width: double.infinity, - child: Image.asset( - 'assets/halloween-bg.png', - fit: BoxFit.cover, - opacity: _animationController, - ), - ), - LlmChatView( - provider: _provider, - welcomeMessage: - 'Welcome to the Custom Styles Example! Use the ' - 'butons on the action bar at the top right of the app to ' - 'explore light and dark styles in combination with normal ' - 'and Halloween-themed styles. Enjoy!', - suggestions: [ - 'I\'m a Star Wars fan. What should I wear for Halloween?', - 'I\'m allergic to peanuts. What candy should I avoid at ' - 'Halloween?', - 'What\'s the difference between a pumpkin and a squash?', - ], - style: style, - ), + builder: (context, child) => Stack( + children: [ + SizedBox( + height: double.infinity, + width: double.infinity, + child: Image.asset( + 'assets/halloween-bg.png', + fit: BoxFit.cover, + opacity: _animationController, + ), + ), + LlmChatView( + provider: _provider, + welcomeMessage: + 'Welcome to the Custom Styles Example! Use the ' + 'butons on the action bar at the top right of the app to ' + 'explore light and dark styles in combination with normal ' + 'and Halloween-themed styles. Enjoy!', + suggestions: [ + 'I\'m a Star Wars fan. What should I wear for Halloween?', + 'I\'m allergic to peanuts. What candy should I avoid at ' + 'Halloween?', + 'What\'s the difference between a pumpkin and a squash?', ], + style: style, ), + ], + ), ), ); } @@ -156,10 +155,9 @@ class _ChatPageState extends State ), ), chatInputStyle: ChatInputStyle( - backgroundColor: - _animationController.isAnimating - ? Colors.transparent - : Colors.black, + backgroundColor: _animationController.isAnimating + ? Colors.transparent + : Colors.black, decoration: BoxDecoration( color: Colors.yellow, border: Border.all(color: Colors.orange), diff --git a/example/lib/dark_mode/dark_mode.dart b/example/lib/dark_mode/dark_mode.dart index 9847d067..a973a0a7 100644 --- a/example/lib/dark_mode/dark_mode.dart +++ b/example/lib/dark_mode/dark_mode.dart @@ -4,7 +4,7 @@ import 'package:firebase_ai/firebase_ai.dart'; import 'package:firebase_core/firebase_core.dart'; -import 'package:flutter/material.dart'; +import 'package:material_ui/material_ui.dart'; import 'package:flutter_ai_toolkit/flutter_ai_toolkit.dart'; import '../dark_style.dart'; @@ -26,8 +26,8 @@ class App extends StatelessWidget { @override Widget build(BuildContext context) => ValueListenableBuilder( valueListenable: themeMode, - builder: - (BuildContext context, ThemeMode mode, Widget? child) => MaterialApp( + builder: (BuildContext context, ThemeMode mode, Widget? child) => + MaterialApp( title: title, theme: ThemeData.light(), darkTheme: ThemeData.dark(), @@ -59,16 +59,13 @@ class _ChatPageState extends State { title: const Text(App.title), actions: [ IconButton( - onPressed: - () => - App.themeMode.value = - App.themeMode.value == ThemeMode.light - ? ThemeMode.dark - : ThemeMode.light, - tooltip: - App.themeMode.value == ThemeMode.light - ? 'Dark Mode' - : 'Light Mode', + onPressed: () => + App.themeMode.value = App.themeMode.value == ThemeMode.light + ? ThemeMode.dark + : ThemeMode.light, + tooltip: App.themeMode.value == ThemeMode.light + ? 'Dark Mode' + : 'Light Mode', icon: const Icon(Icons.brightness_4_outlined), ), ], diff --git a/example/lib/dark_style.dart b/example/lib/dark_style.dart index 7b599e4f..96455de0 100644 --- a/example/lib/dark_style.dart +++ b/example/lib/dark_style.dart @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import 'package:flutter/material.dart'; +import 'package:material_ui/material_ui.dart'; import 'package:flutter_ai_toolkit/flutter_ai_toolkit.dart'; import 'package:flutter_markdown_plus/flutter_markdown_plus.dart'; import 'package:google_fonts/google_fonts.dart'; @@ -133,15 +133,14 @@ SuggestionStyle _darkSuggestionStyle() { const Color _greyBackground = Color(0xFF535353); -Color? _invertColor(Color? color) => - color != null - ? Color.from( - alpha: color.a, - red: 1 - color.r, - green: 1 - color.g, - blue: 1 - color.b, - ) - : null; +Color? _invertColor(Color? color) => color != null + ? Color.from( + alpha: color.a, + red: 1 - color.r, + green: 1 - color.g, + blue: 1 - color.b, + ) + : null; Decoration _invertDecoration(Decoration? decoration) => switch (decoration!) { final BoxDecoration d => d.copyWith(color: _invertColor(d.color)), diff --git a/example/lib/demo/demo.dart b/example/lib/demo/demo.dart index 9edd0cd4..62df48b7 100644 --- a/example/lib/demo/demo.dart +++ b/example/lib/demo/demo.dart @@ -4,7 +4,7 @@ import 'package:firebase_ai/firebase_ai.dart'; import 'package:firebase_core/firebase_core.dart'; -import 'package:flutter/material.dart'; +import 'package:material_ui/material_ui.dart'; import 'package:flutter_ai_toolkit/flutter_ai_toolkit.dart'; import 'package:flutter_markdown_plus/flutter_markdown_plus.dart'; import 'package:google_fonts/google_fonts.dart'; @@ -33,15 +33,14 @@ class _AppState extends State { @override Widget build(BuildContext context) => ValueListenableBuilder( valueListenable: App.themeMode, - builder: - (context, mode, child) => MaterialApp( - title: App.title, - theme: ThemeData.light(), - darkTheme: ThemeData.dark(), - themeMode: mode, - home: ChatPage(), - debugShowCheckedModeBanner: false, - ), + builder: (context, mode, child) => MaterialApp( + title: App.title, + theme: ThemeData.light(), + darkTheme: ThemeData.dark(), + themeMode: mode, + home: ChatPage(), + debugShowCheckedModeBanner: false, + ), ); } @@ -87,70 +86,63 @@ class _ChatPageState extends State @override Widget build(BuildContext context) => ValueListenableBuilder( valueListenable: _halloweenMode, - builder: - (context, halloween, child) => Scaffold( - appBar: AppBar( - title: const Text(App.title), - actions: [ - IconButton( - onPressed: _clearHistory, - tooltip: 'Clear History', - icon: const Icon(Icons.history), - ), - IconButton( - onPressed: - () => - App.themeMode.value = - App.themeMode.value == ThemeMode.light - ? ThemeMode.dark - : ThemeMode.light, - tooltip: - App.themeMode.value == ThemeMode.light - ? 'Dark Mode' - : 'Light Mode', - icon: const Icon(Icons.brightness_4_outlined), - ), - IconButton( - onPressed: () { - _halloweenMode.value = !_halloweenMode.value; - if (_halloweenMode.value) _resetAnimation(); - }, - tooltip: - _halloweenMode.value ? 'Normal Mode' : 'Halloween Mode', - icon: Text('🎃'), - ), - ], + builder: (context, halloween, child) => Scaffold( + appBar: AppBar( + title: const Text(App.title), + actions: [ + IconButton( + onPressed: _clearHistory, + tooltip: 'Clear History', + icon: const Icon(Icons.history), + ), + IconButton( + onPressed: () => + App.themeMode.value = App.themeMode.value == ThemeMode.light + ? ThemeMode.dark + : ThemeMode.light, + tooltip: App.themeMode.value == ThemeMode.light + ? 'Dark Mode' + : 'Light Mode', + icon: const Icon(Icons.brightness_4_outlined), ), - body: AnimatedBuilder( - animation: _animationController, - builder: - (context, child) => Stack( - children: [ - SizedBox( - height: double.infinity, - width: double.infinity, - child: Image.asset( - 'assets/halloween-bg.png', - fit: BoxFit.cover, - opacity: _animationController, - ), - ), - LlmChatView( - provider: _provider, - style: style, - welcomeMessage: - 'Hello and welcome to the Flutter AI Toolkit!', - suggestions: [ - 'I\'m a Star Wars fan. What should I wear for Halloween?', - 'I\'m allergic to peanuts. What candy should I avoid at ' - 'Halloween?', - 'What\'s the difference between a pumpkin and a squash?', - ], - ), - ], - ), + IconButton( + onPressed: () { + _halloweenMode.value = !_halloweenMode.value; + if (_halloweenMode.value) _resetAnimation(); + }, + tooltip: _halloweenMode.value ? 'Normal Mode' : 'Halloween Mode', + icon: Text('🎃'), ), + ], + ), + body: AnimatedBuilder( + animation: _animationController, + builder: (context, child) => Stack( + children: [ + SizedBox( + height: double.infinity, + width: double.infinity, + child: Image.asset( + 'assets/halloween-bg.png', + fit: BoxFit.cover, + opacity: _animationController, + ), + ), + LlmChatView( + provider: _provider, + style: style, + welcomeMessage: 'Hello and welcome to the Flutter AI Toolkit!', + suggestions: [ + 'I\'m a Star Wars fan. What should I wear for Halloween?', + 'I\'m allergic to peanuts. What candy should I avoid at ' + 'Halloween?', + 'What\'s the difference between a pumpkin and a squash?', + ], + ), + ], ), + ), + ), ); void _clearHistory() { @@ -212,10 +204,9 @@ class _ChatPageState extends State ), ), chatInputStyle: ChatInputStyle( - backgroundColor: - _animationController.isAnimating - ? Colors.transparent - : Colors.black, + backgroundColor: _animationController.isAnimating + ? Colors.transparent + : Colors.black, decoration: BoxDecoration( color: Colors.yellow, border: Border.all(color: Colors.orange), diff --git a/example/lib/echo/echo.dart b/example/lib/echo/echo.dart index 385724e5..ad3bff64 100644 --- a/example/lib/echo/echo.dart +++ b/example/lib/echo/echo.dart @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import 'package:flutter/material.dart'; +import 'package:material_ui/material_ui.dart'; import 'package:flutter_ai_toolkit/flutter_ai_toolkit.dart'; void main() => runApp(App()); diff --git a/example/lib/file_upload/file_upload.dart b/example/lib/file_upload/file_upload.dart index f50bcab0..c033bb3a 100644 --- a/example/lib/file_upload/file_upload.dart +++ b/example/lib/file_upload/file_upload.dart @@ -3,7 +3,7 @@ // found in the LICENSE file. import 'package:firebase_core/firebase_core.dart'; -import 'package:flutter/material.dart'; +import 'package:material_ui/material_ui.dart'; import 'package:flutter_ai_toolkit/flutter_ai_toolkit.dart'; // from `flutterfire config`: https://firebase.google.com/docs/flutter/setup diff --git a/example/lib/function_calls/function_calls.dart b/example/lib/function_calls/function_calls.dart index 2e0f5add..17262839 100644 --- a/example/lib/function_calls/function_calls.dart +++ b/example/lib/function_calls/function_calls.dart @@ -4,7 +4,7 @@ import 'package:firebase_ai/firebase_ai.dart'; import 'package:firebase_core/firebase_core.dart'; -import 'package:flutter/material.dart'; +import 'package:material_ui/material_ui.dart'; import 'package:flutter_ai_toolkit/flutter_ai_toolkit.dart'; // from `flutterfire config`: https://firebase.google.com/docs/flutter/setup diff --git a/example/lib/gemini/gemini.dart b/example/lib/gemini/gemini.dart index 999ae1d4..9eff464e 100644 --- a/example/lib/gemini/gemini.dart +++ b/example/lib/gemini/gemini.dart @@ -4,7 +4,7 @@ import 'package:firebase_ai/firebase_ai.dart'; import 'package:firebase_core/firebase_core.dart'; -import 'package:flutter/material.dart'; +import 'package:material_ui/material_ui.dart'; import 'package:flutter_ai_toolkit/flutter_ai_toolkit.dart'; // from `flutterfire config`: https://firebase.google.com/docs/flutter/setup diff --git a/example/lib/history/history.dart b/example/lib/history/history.dart index 196025cc..093b47c3 100644 --- a/example/lib/history/history.dart +++ b/example/lib/history/history.dart @@ -7,7 +7,7 @@ import 'dart:io' as io; import 'package:firebase_ai/firebase_ai.dart'; import 'package:firebase_core/firebase_core.dart'; -import 'package:flutter/material.dart'; +import 'package:material_ui/material_ui.dart'; import 'package:flutter_ai_toolkit/flutter_ai_toolkit.dart'; import 'package:path/path.dart' as path; import 'package:path_provider/path_provider.dart' as pp; @@ -138,20 +138,19 @@ class _ChatPageState extends State { void _clearHistory() async { final ok = await showDialog( context: context, - builder: - (context) => AlertDialog( - title: const Text('Clear history?'), - actions: [ - ElevatedButton( - onPressed: () => Navigator.pop(context, true), - child: const Text('Clear'), - ), - OutlinedButton( - onPressed: () => Navigator.pop(context, false), - child: const Text('Cancel'), - ), - ], + builder: (context) => AlertDialog( + title: const Text('Clear history?'), + actions: [ + ElevatedButton( + onPressed: () => Navigator.pop(context, true), + child: const Text('Clear'), ), + OutlinedButton( + onPressed: () => Navigator.pop(context, false), + child: const Text('Cancel'), + ), + ], + ), ); if (ok != true) return; diff --git a/example/lib/logging/logging.dart b/example/lib/logging/logging.dart index c9a5ee87..84e0be92 100644 --- a/example/lib/logging/logging.dart +++ b/example/lib/logging/logging.dart @@ -4,7 +4,7 @@ import 'package:firebase_ai/firebase_ai.dart'; import 'package:firebase_core/firebase_core.dart'; -import 'package:flutter/material.dart'; +import 'package:material_ui/material_ui.dart'; import 'package:flutter_ai_toolkit/flutter_ai_toolkit.dart'; // from `flutterfire config`: https://firebase.google.com/docs/flutter/setup diff --git a/example/lib/main.dart b/example/lib/main.dart index 999ae1d4..9eff464e 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -4,7 +4,7 @@ import 'package:firebase_ai/firebase_ai.dart'; import 'package:firebase_core/firebase_core.dart'; -import 'package:flutter/material.dart'; +import 'package:material_ui/material_ui.dart'; import 'package:flutter_ai_toolkit/flutter_ai_toolkit.dart'; // from `flutterfire config`: https://firebase.google.com/docs/flutter/setup diff --git a/example/lib/recipes/data/recipe_data.dart b/example/lib/recipes/data/recipe_data.dart index e00edfa6..5b9be6f0 100644 --- a/example/lib/recipes/data/recipe_data.dart +++ b/example/lib/recipes/data/recipe_data.dart @@ -62,7 +62,8 @@ class Recipe { } @override - String toString() => '''# $title + String toString() => + '''# $title $description ## Ingredients diff --git a/example/lib/recipes/data/recipe_repository.dart b/example/lib/recipes/data/recipe_repository.dart index bafdac0e..ac328028 100644 --- a/example/lib/recipes/data/recipe_repository.dart +++ b/example/lib/recipes/data/recipe_repository.dart @@ -71,10 +71,9 @@ class RecipeRepository { late final String contents; if (!kIsWeb) { final recipeFile = await _recipeFile; - contents = - await recipeFile.exists() - ? await recipeFile.readAsString() - : await rootBundle.loadString(_assetFileName); + contents = await recipeFile.exists() + ? await recipeFile.readAsString() + : await rootBundle.loadString(_assetFileName); } else { contents = await rootBundle.loadString(_assetFileName); } diff --git a/example/lib/recipes/pages/edit_recipe_page.dart b/example/lib/recipes/pages/edit_recipe_page.dart index 7af422a8..41b902e2 100644 --- a/example/lib/recipes/pages/edit_recipe_page.dart +++ b/example/lib/recipes/pages/edit_recipe_page.dart @@ -5,7 +5,7 @@ import 'dart:convert'; import 'package:firebase_ai/firebase_ai.dart'; -import 'package:flutter/material.dart'; +import 'package:material_ui/material_ui.dart'; import 'package:flutter_ai_toolkit/flutter_ai_toolkit.dart'; import 'package:go_router/go_router.dart'; import 'package:uuid/uuid.dart'; @@ -112,11 +112,9 @@ When you generate a recipe, you should generate a JSON object. labelText: 'Title', hintText: 'Enter a name for your recipe...', ), - validator: - (value) => - (value == null || value.isEmpty) - ? 'Recipe title is requires' - : null, + validator: (value) => (value == null || value.isEmpty) + ? 'Recipe title is requires' + : null, ), TextField( controller: _descriptionController, @@ -192,28 +190,27 @@ When you generate a recipe, you should generate a JSON object. final accept = await showDialog( // ignore: use_build_context_synchronously context: context, - builder: - (context) => AlertDialog( - title: Text(recipe.title), - content: Column( - crossAxisAlignment: CrossAxisAlignment.start, - spacing: 16, - children: [ - const Text('Modifications:'), - Text(_wrapText(modifications)), - ], - ), - actions: [ - TextButton( - onPressed: () => context.pop(true), - child: const Text('Accept'), - ), - TextButton( - onPressed: () => context.pop(false), - child: const Text('Reject'), - ), - ], + builder: (context) => AlertDialog( + title: Text(recipe.title), + content: Column( + crossAxisAlignment: CrossAxisAlignment.start, + spacing: 16, + children: [ + const Text('Modifications:'), + Text(_wrapText(modifications)), + ], + ), + actions: [ + TextButton( + onPressed: () => context.pop(true), + child: const Text('Accept'), ), + TextButton( + onPressed: () => context.pop(false), + child: const Text('Reject'), + ), + ], + ), ); if (accept == true) { @@ -229,17 +226,16 @@ When you generate a recipe, you should generate a JSON object. showDialog( // ignore: use_build_context_synchronously context: context, - builder: - (context) => AlertDialog( - title: const Text('Error'), - content: Text(ex.toString()), - actions: [ - TextButton( - onPressed: () => context.pop(), - child: const Text('OK'), - ), - ], + builder: (context) => AlertDialog( + title: const Text('Error'), + content: Text(ex.toString()), + actions: [ + TextButton( + onPressed: () => context.pop(), + child: const Text('OK'), ), + ], + ), ); } } diff --git a/example/lib/recipes/pages/home_page.dart b/example/lib/recipes/pages/home_page.dart index 207a3480..a4354bfe 100644 --- a/example/lib/recipes/pages/home_page.dart +++ b/example/lib/recipes/pages/home_page.dart @@ -1,5 +1,5 @@ import 'package:firebase_ai/firebase_ai.dart'; -import 'package:flutter/material.dart'; +import 'package:material_ui/material_ui.dart'; import 'package:flutter_ai_toolkit/flutter_ai_toolkit.dart'; import 'package:go_router/go_router.dart'; @@ -112,7 +112,10 @@ well as any trailing text commentary you care to provide: builder: (context) => SettingsDrawer(onSave: _onSettingsSave), ), body: SplitOrTabs( - tabs: const [Tab(text: 'Recipes'), Tab(text: 'Chat')], + tabs: const [ + Tab(text: 'Recipes'), + Tab(text: 'Chat'), + ], children: [ Column( children: [ diff --git a/example/lib/recipes/pages/split_or_tabs.dart b/example/lib/recipes/pages/split_or_tabs.dart index dd4068b9..ecc1b164 100644 --- a/example/lib/recipes/pages/split_or_tabs.dart +++ b/example/lib/recipes/pages/split_or_tabs.dart @@ -1,4 +1,4 @@ -import 'package:flutter/material.dart'; +import 'package:material_ui/material_ui.dart'; import 'package:split_view/split_view.dart'; class SplitOrTabs extends StatefulWidget { @@ -27,32 +27,31 @@ class _SplitOrTabsState extends State } @override - Widget build(BuildContext context) => - MediaQuery.of(context).size.width > 600 - ? SplitView( + Widget build(BuildContext context) => MediaQuery.of(context).size.width > 600 + ? SplitView( + viewMode: SplitViewMode.Horizontal, + gripColor: Colors.transparent, + indicator: SplitIndicator( viewMode: SplitViewMode.Horizontal, - gripColor: Colors.transparent, - indicator: SplitIndicator( - viewMode: SplitViewMode.Horizontal, - color: Colors.grey, - ), - gripColorActive: Colors.transparent, - activeIndicator: SplitIndicator( - viewMode: SplitViewMode.Horizontal, - isActive: true, - color: Colors.black, - ), - children: widget.children, - ) - : Column( - children: [ - TabBar(controller: _tabController, tabs: widget.tabs), - Expanded( - child: TabBarView( - controller: _tabController, - children: widget.children, - ), + color: Colors.grey, + ), + gripColorActive: Colors.transparent, + activeIndicator: SplitIndicator( + viewMode: SplitViewMode.Horizontal, + isActive: true, + color: Colors.black, + ), + children: widget.children, + ) + : Column( + children: [ + TabBar(controller: _tabController, tabs: widget.tabs), + Expanded( + child: TabBarView( + controller: _tabController, + children: widget.children, ), - ], - ); + ), + ], + ); } diff --git a/example/lib/recipes/recipes.dart b/example/lib/recipes/recipes.dart index 4b6c19ac..a0198b37 100644 --- a/example/lib/recipes/recipes.dart +++ b/example/lib/recipes/recipes.dart @@ -3,7 +3,7 @@ // found in the LICENSE file. import 'package:firebase_core/firebase_core.dart'; -import 'package:flutter/material.dart'; +import 'package:material_ui/material_ui.dart'; import 'package:go_router/go_router.dart'; // from `flutterfire config`: https://firebase.google.com/docs/flutter/setup diff --git a/example/lib/recipes/views/recipe_content_view.dart b/example/lib/recipes/views/recipe_content_view.dart index ef452929..835be246 100644 --- a/example/lib/recipes/views/recipe_content_view.dart +++ b/example/lib/recipes/views/recipe_content_view.dart @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import 'package:flutter/material.dart'; +import 'package:material_ui/material_ui.dart'; import '../data/recipe_data.dart'; @@ -16,27 +16,25 @@ class RecipeContentView extends StatelessWidget { Widget build(BuildContext context) => Padding( padding: const EdgeInsets.all(16), child: LayoutBuilder( - builder: - (context, constraints) => - constraints.maxWidth < mobileBreakpoint - ? SingleChildScrollView( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - spacing: 16, - children: [ - _RecipeIngredientsView(recipe), - _RecipeInstructionsView(recipe), - ], - ), - ) - : Row( - crossAxisAlignment: CrossAxisAlignment.start, - spacing: 16, - children: [ - Expanded(child: _RecipeIngredientsView(recipe)), - Expanded(child: _RecipeInstructionsView(recipe)), - ], - ), + builder: (context, constraints) => constraints.maxWidth < mobileBreakpoint + ? SingleChildScrollView( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + spacing: 16, + children: [ + _RecipeIngredientsView(recipe), + _RecipeInstructionsView(recipe), + ], + ), + ) + : Row( + crossAxisAlignment: CrossAxisAlignment.start, + spacing: 16, + children: [ + Expanded(child: _RecipeIngredientsView(recipe)), + Expanded(child: _RecipeInstructionsView(recipe)), + ], + ), ), ); } diff --git a/example/lib/recipes/views/recipe_list_view.dart b/example/lib/recipes/views/recipe_list_view.dart index e962a58c..d194cd93 100644 --- a/example/lib/recipes/views/recipe_list_view.dart +++ b/example/lib/recipes/views/recipe_list_view.dart @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import 'package:flutter/material.dart'; +import 'package:material_ui/material_ui.dart'; import 'package:go_router/go_router.dart'; import '../data/recipe_data.dart'; @@ -61,8 +61,8 @@ class _RecipeListViewState extends State { key: ValueKey(recipeId), recipe: recipe, expanded: _expanded[recipeId] == true, - onExpansionChanged: - (expanded) => _onExpand(recipe.id, expanded), + onExpansionChanged: (expanded) => + _onExpand(recipe.id, expanded), onEdit: () => _onEdit(recipe), onDelete: () => _onDelete(recipe), ); @@ -80,23 +80,22 @@ class _RecipeListViewState extends State { void _onDelete(Recipe recipe) async { final shouldDelete = await showDialog( context: context, - builder: - (context) => AlertDialog( - title: const Text('Delete Recipe'), - content: Text( - 'Are you sure you want to delete the recipe "${recipe.title}"?', - ), - actions: [ - TextButton( - onPressed: () => Navigator.pop(context, false), - child: const Text('Cancel'), - ), - TextButton( - onPressed: () => Navigator.pop(context, true), - child: const Text('Delete'), - ), - ], + builder: (context) => AlertDialog( + title: const Text('Delete Recipe'), + content: Text( + 'Are you sure you want to delete the recipe "${recipe.title}"?', + ), + actions: [ + TextButton( + onPressed: () => Navigator.pop(context, false), + child: const Text('Cancel'), ), + TextButton( + onPressed: () => Navigator.pop(context, true), + child: const Text('Delete'), + ), + ], + ), ); if (shouldDelete == true) await RecipeRepository.deleteRecipe(recipe); diff --git a/example/lib/recipes/views/recipe_response_view.dart b/example/lib/recipes/views/recipe_response_view.dart index 453fb37d..3f8c5b19 100644 --- a/example/lib/recipes/views/recipe_response_view.dart +++ b/example/lib/recipes/views/recipe_response_view.dart @@ -1,6 +1,6 @@ import 'dart:convert'; -import 'package:flutter/material.dart'; +import 'package:material_ui/material_ui.dart'; import 'package:flutter_markdown_plus/flutter_markdown_plus.dart'; import '../data/recipe_data.dart'; diff --git a/example/lib/recipes/views/recipe_view.dart b/example/lib/recipes/views/recipe_view.dart index 7dde0d3c..a38367e2 100644 --- a/example/lib/recipes/views/recipe_view.dart +++ b/example/lib/recipes/views/recipe_view.dart @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import 'package:flutter/material.dart'; +import 'package:material_ui/material_ui.dart'; import '../data/recipe_data.dart'; import 'recipe_content_view.dart'; diff --git a/example/lib/recipes/views/search_box.dart b/example/lib/recipes/views/search_box.dart index ed3e4b3b..7b2a6a5a 100644 --- a/example/lib/recipes/views/search_box.dart +++ b/example/lib/recipes/views/search_box.dart @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import 'package:flutter/material.dart'; +import 'package:material_ui/material_ui.dart'; class SearchBox extends StatefulWidget { final Function(String) onSearchChanged; diff --git a/example/lib/recipes/views/settings_drawer.dart b/example/lib/recipes/views/settings_drawer.dart index 1f19739a..6d6ce5fb 100644 --- a/example/lib/recipes/views/settings_drawer.dart +++ b/example/lib/recipes/views/settings_drawer.dart @@ -1,4 +1,4 @@ -import 'package:flutter/material.dart'; +import 'package:material_ui/material_ui.dart'; import '../data/settings.dart'; diff --git a/example/lib/restricted/restricted.dart b/example/lib/restricted/restricted.dart index decb993c..4f9b05c1 100644 --- a/example/lib/restricted/restricted.dart +++ b/example/lib/restricted/restricted.dart @@ -4,7 +4,7 @@ import 'package:firebase_ai/firebase_ai.dart'; import 'package:firebase_core/firebase_core.dart'; -import 'package:flutter/material.dart'; +import 'package:material_ui/material_ui.dart'; import 'package:flutter_ai_toolkit/flutter_ai_toolkit.dart'; // from `flutterfire config`: https://firebase.google.com/docs/flutter/setup diff --git a/example/lib/styles/styles.dart b/example/lib/styles/styles.dart index c77bf7d1..e621e00b 100644 --- a/example/lib/styles/styles.dart +++ b/example/lib/styles/styles.dart @@ -4,7 +4,7 @@ import 'package:firebase_ai/firebase_ai.dart'; import 'package:firebase_core/firebase_core.dart'; -import 'package:flutter/material.dart'; +import 'package:material_ui/material_ui.dart'; import 'package:flutter_ai_toolkit/flutter_ai_toolkit.dart'; import 'package:flutter_markdown_plus/flutter_markdown_plus.dart'; import 'package:google_fonts/google_fonts.dart'; @@ -105,154 +105,148 @@ class _ChatPageState extends State ), body: AnimatedBuilder( animation: _controller, - builder: - (context, child) => Stack( - children: [ - SizedBox( - height: double.infinity, - width: double.infinity, - child: Image.asset( - 'assets/halloween-bg.png', - fit: BoxFit.cover, - opacity: _controller, + builder: (context, child) => Stack( + children: [ + SizedBox( + height: double.infinity, + width: double.infinity, + child: Image.asset( + 'assets/halloween-bg.png', + fit: BoxFit.cover, + opacity: _controller, + ), + ), + LlmChatView( + provider: _provider!, + style: LlmChatViewStyle( + padding: const EdgeInsets.symmetric(horizontal: 16.0), + margin: const EdgeInsets.only(bottom: 8.0), + messageSpacing: 12.0, + backgroundColor: Colors.transparent, + progressIndicatorColor: Colors.purple, + chatInputStyle: ChatInputStyle( + backgroundColor: _controller.isAnimating + ? Colors.transparent + : Colors.black, + decoration: BoxDecoration( + color: Colors.yellow, + border: Border.all(color: Colors.orange), + ), + textStyle: halloweenTextStyle.copyWith(color: Colors.black), + hintText: 'good evening...', + hintStyle: halloweenTextStyle.copyWith( + color: Colors.orange.withAlpha(128), ), ), - LlmChatView( - provider: _provider!, - style: LlmChatViewStyle( - padding: const EdgeInsets.symmetric(horizontal: 16.0), - margin: const EdgeInsets.only(bottom: 8.0), - messageSpacing: 12.0, - backgroundColor: Colors.transparent, - progressIndicatorColor: Colors.purple, - chatInputStyle: ChatInputStyle( - backgroundColor: - _controller.isAnimating - ? Colors.transparent - : Colors.black, - decoration: BoxDecoration( - color: Colors.yellow, - border: Border.all(color: Colors.orange), - ), - textStyle: halloweenTextStyle.copyWith( - color: Colors.black, - ), - hintText: 'good evening...', - hintStyle: halloweenTextStyle.copyWith( - color: Colors.orange.withAlpha(128), - ), - ), - userMessageStyle: UserMessageStyle( - textStyle: halloweenTextStyle.copyWith( - color: Colors.black, - ), - decoration: BoxDecoration( - gradient: LinearGradient( - begin: Alignment.topLeft, - end: Alignment.bottomRight, - colors: [ - Colors.white, - Colors.grey.shade300, - Colors.grey.shade400, - ], - ), - borderRadius: BorderRadius.circular(20), - boxShadow: [ - BoxShadow( - color: Colors.grey.withAlpha(128), - blurRadius: 10, - spreadRadius: 2, - ), - ], - ), + userMessageStyle: UserMessageStyle( + textStyle: halloweenTextStyle.copyWith(color: Colors.black), + decoration: BoxDecoration( + gradient: LinearGradient( + begin: Alignment.topLeft, + end: Alignment.bottomRight, + colors: [ + Colors.white, + Colors.grey.shade300, + Colors.grey.shade400, + ], ), - llmMessageStyle: LlmMessageStyle( - maxWidth: 800.0, - minWidth: 300.0, - flex: 8, - padding: const EdgeInsets.all(16.0), - margin: const EdgeInsets.symmetric(vertical: 8.0), - icon: Icons.sentiment_very_satisfied, - iconColor: Colors.black, - iconDecoration: BoxDecoration( - color: Colors.orange, - borderRadius: BorderRadius.only( - topLeft: Radius.circular(8), - bottomLeft: Radius.circular(8), - topRight: Radius.zero, - bottomRight: Radius.circular(8), - ), - border: Border.all(color: Colors.black), - ), - decoration: BoxDecoration( - gradient: LinearGradient( - begin: Alignment.topLeft, - end: Alignment.bottomRight, - colors: [ - Colors.deepOrange.shade900, - Colors.orange.shade800, - Colors.purple.shade900, - ], - ), - borderRadius: BorderRadius.only( - topLeft: Radius.zero, - bottomLeft: Radius.circular(20), - topRight: Radius.circular(20), - bottomRight: Radius.circular(20), - ), - boxShadow: [ - BoxShadow( - color: Colors.black.withAlpha(76), - blurRadius: 8, - offset: Offset(2, 2), - ), - ], - ), - markdownStyle: MarkdownStyleSheet( - p: halloweenTextStyle, - listBullet: halloweenTextStyle, + borderRadius: BorderRadius.circular(20), + boxShadow: [ + BoxShadow( + color: Colors.grey.withAlpha(128), + blurRadius: 10, + spreadRadius: 2, ), + ], + ), + ), + llmMessageStyle: LlmMessageStyle( + maxWidth: 800.0, + minWidth: 300.0, + flex: 8, + padding: const EdgeInsets.all(16.0), + margin: const EdgeInsets.symmetric(vertical: 8.0), + icon: Icons.sentiment_very_satisfied, + iconColor: Colors.black, + iconDecoration: BoxDecoration( + color: Colors.orange, + borderRadius: BorderRadius.only( + topLeft: Radius.circular(8), + bottomLeft: Radius.circular(8), + topRight: Radius.zero, + bottomRight: Radius.circular(8), ), - recordButtonStyle: halloweenActionButtonStyle, - stopButtonStyle: halloweenActionButtonStyle, - submitButtonStyle: halloweenActionButtonStyle, - addButtonStyle: halloweenActionButtonStyle, - attachFileButtonStyle: halloweenMenuButtonStyle, - cameraButtonStyle: halloweenMenuButtonStyle, - closeButtonStyle: halloweenActionButtonStyle, - cancelButtonStyle: halloweenActionButtonStyle, - closeMenuButtonStyle: halloweenActionButtonStyle, - copyButtonStyle: halloweenMenuButtonStyle, - editButtonStyle: halloweenMenuButtonStyle, - galleryButtonStyle: halloweenMenuButtonStyle, - actionButtonBarDecoration: BoxDecoration( - color: Colors.orange, - borderRadius: BorderRadius.circular(8), + border: Border.all(color: Colors.black), + ), + decoration: BoxDecoration( + gradient: LinearGradient( + begin: Alignment.topLeft, + end: Alignment.bottomRight, + colors: [ + Colors.deepOrange.shade900, + Colors.orange.shade800, + Colors.purple.shade900, + ], ), - fileAttachmentStyle: FileAttachmentStyle( - decoration: BoxDecoration(color: Colors.black), - iconDecoration: BoxDecoration( - color: Colors.orange, - borderRadius: BorderRadius.circular(8), - ), - filenameStyle: halloweenTextStyle, - filetypeStyle: halloweenTextStyle.copyWith( - color: Colors.green, - fontSize: 18, - ), + borderRadius: BorderRadius.only( + topLeft: Radius.zero, + bottomLeft: Radius.circular(20), + topRight: Radius.circular(20), + bottomRight: Radius.circular(20), ), - voiceNoteRecorderStyle: VoiceNoteRecorderStyle( - height: 60.0, - waveColor: Colors.orange, - durationTextStyle: halloweenTextStyle.copyWith( - color: Colors.black, - fontSize: 16, + boxShadow: [ + BoxShadow( + color: Colors.black.withAlpha(76), + blurRadius: 8, + offset: Offset(2, 2), ), - ), + ], + ), + markdownStyle: MarkdownStyleSheet( + p: halloweenTextStyle, + listBullet: halloweenTextStyle, + ), + ), + recordButtonStyle: halloweenActionButtonStyle, + stopButtonStyle: halloweenActionButtonStyle, + submitButtonStyle: halloweenActionButtonStyle, + addButtonStyle: halloweenActionButtonStyle, + attachFileButtonStyle: halloweenMenuButtonStyle, + cameraButtonStyle: halloweenMenuButtonStyle, + closeButtonStyle: halloweenActionButtonStyle, + cancelButtonStyle: halloweenActionButtonStyle, + closeMenuButtonStyle: halloweenActionButtonStyle, + copyButtonStyle: halloweenMenuButtonStyle, + editButtonStyle: halloweenMenuButtonStyle, + galleryButtonStyle: halloweenMenuButtonStyle, + actionButtonBarDecoration: BoxDecoration( + color: Colors.orange, + borderRadius: BorderRadius.circular(8), + ), + fileAttachmentStyle: FileAttachmentStyle( + decoration: BoxDecoration(color: Colors.black), + iconDecoration: BoxDecoration( + color: Colors.orange, + borderRadius: BorderRadius.circular(8), + ), + filenameStyle: halloweenTextStyle, + filetypeStyle: halloweenTextStyle.copyWith( + color: Colors.green, + fontSize: 18, + ), + ), + voiceNoteRecorderStyle: VoiceNoteRecorderStyle( + height: 60.0, + waveColor: Colors.orange, + durationTextStyle: halloweenTextStyle.copyWith( + color: Colors.black, + fontSize: 16, ), ), - ], + ), ), + ], + ), ), ); } diff --git a/example/lib/suggestions/suggestions.dart b/example/lib/suggestions/suggestions.dart index 1c52a44c..5a941e73 100644 --- a/example/lib/suggestions/suggestions.dart +++ b/example/lib/suggestions/suggestions.dart @@ -4,7 +4,7 @@ import 'package:firebase_ai/firebase_ai.dart'; import 'package:firebase_core/firebase_core.dart'; -import 'package:flutter/material.dart'; +import 'package:material_ui/material_ui.dart'; import 'package:flutter_ai_toolkit/flutter_ai_toolkit.dart'; // from `flutterfire config`: https://firebase.google.com/docs/flutter/setup diff --git a/example/lib/vertex/vertex.dart b/example/lib/vertex/vertex.dart index fec9f6ba..a080e1ff 100644 --- a/example/lib/vertex/vertex.dart +++ b/example/lib/vertex/vertex.dart @@ -4,7 +4,7 @@ import 'package:firebase_ai/firebase_ai.dart'; import 'package:firebase_core/firebase_core.dart'; -import 'package:flutter/material.dart'; +import 'package:material_ui/material_ui.dart'; import 'package:flutter_ai_toolkit/flutter_ai_toolkit.dart'; // from `flutterfire config`: https://firebase.google.com/docs/flutter/setup @@ -33,7 +33,9 @@ class ChatPage extends StatelessWidget { appBar: AppBar(title: const Text(App.title)), body: LlmChatView( provider: FirebaseProvider( - model: FirebaseAI.vertexAI().generativeModel(model: 'gemini-2.0-flash'), + model: FirebaseAI.agentPlatform().generativeModel( + model: 'gemini-2.0-flash', + ), ), ), ); diff --git a/example/lib/welcome/welcome.dart b/example/lib/welcome/welcome.dart index 83c567fa..ffdbda14 100644 --- a/example/lib/welcome/welcome.dart +++ b/example/lib/welcome/welcome.dart @@ -4,7 +4,7 @@ import 'package:firebase_ai/firebase_ai.dart'; import 'package:firebase_core/firebase_core.dart'; -import 'package:flutter/material.dart'; +import 'package:material_ui/material_ui.dart'; import 'package:flutter_ai_toolkit/flutter_ai_toolkit.dart'; // from `flutterfire config`: https://firebase.google.com/docs/flutter/setup diff --git a/example/pubspec.yaml b/example/pubspec.yaml index d8a18182..d83ac1ce 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -5,28 +5,30 @@ publish_to: none version: 1.0.0+1 environment: - sdk: ^3.7.0 - flutter: '>=3.27.0-0' + sdk: ^3.13.0 + flutter: '>=3.47.0' dependencies: + cross_file: ^0.3.5+2 + cupertino_icons: ^1.0.9 + cupertino_ui: ^1.1.7 + firebase_ai: ^3.12.2 + firebase_core: ^4.10.0 flutter: sdk: flutter flutter_ai_toolkit: path: .. - cupertino_icons: ^1.0.9 - shared_preferences: ^2.5.5 - url_launcher: ^6.3.2 + flutter_markdown_plus: ^1.0.7 + future_builder_ex: ^5.0.0 go_router: ^17.3.0 - uuid: ^4.5.3 + google_fonts: ^8.1.0 + material_ui: ^1.11.1 path: ^1.9.1 path_provider: ^2.1.5 - flutter_markdown_plus: ^1.0.7 - google_fonts: ^8.1.0 - future_builder_ex: ^5.0.0 + shared_preferences: ^2.5.5 split_view: ^3.2.2 - firebase_core: ^4.10.0 - firebase_ai: ^3.12.2 - cross_file: ^0.3.5+2 + url_launcher: ^6.3.2 + uuid: ^4.5.3 dev_dependencies: flutter_test: diff --git a/lib/src/chat_view_model/chat_view_model_provider.dart b/lib/src/chat_view_model/chat_view_model_provider.dart index e136fbc8..1b548623 100644 --- a/lib/src/chat_view_model/chat_view_model_provider.dart +++ b/lib/src/chat_view_model/chat_view_model_provider.dart @@ -43,10 +43,9 @@ class ChatViewModelProvider extends InheritedWidget { /// Returns null if no [ChatViewModelProvider] is found. /// /// [context] must not be null. - static ChatViewModel? maybeOf(BuildContext context) => - context - .dependOnInheritedWidgetOfExactType() - ?.viewModel; + static ChatViewModel? maybeOf(BuildContext context) => context + .dependOnInheritedWidgetOfExactType() + ?.viewModel; @override bool updateShouldNotify(ChatViewModelProvider oldWidget) => diff --git a/lib/src/dialogs/adaptive_dialog.dart b/lib/src/dialogs/adaptive_dialog.dart index 9d92729c..5f7fdbca 100644 --- a/lib/src/dialogs/adaptive_dialog.dart +++ b/lib/src/dialogs/adaptive_dialog.dart @@ -2,9 +2,10 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import 'package:flutter/cupertino.dart' +import 'package:cupertino_ui/cupertino_ui.dart' show CupertinoAlertDialog, CupertinoDialogAction, showCupertinoDialog; -import 'package:flutter/material.dart' show AlertDialog, TextButton, showDialog; +import 'package:material_ui/material_ui.dart' + show AlertDialog, TextButton, showDialog; import 'package:flutter/widgets.dart'; import '../utility.dart'; @@ -34,40 +35,37 @@ class AdaptiveAlertDialog { required BuildContext context, required Widget content, bool showOK = false, - }) => - isCupertinoApp(context) - ? showCupertinoDialog( - context: context, - barrierDismissible: !showOK, - builder: - (context) => CupertinoAlertDialog( - content: content, - actions: [ - if (showOK) - CupertinoDialogAction( - onPressed: () => Navigator.pop(context), - child: const Text('OK'), - ), - ], + }) => isCupertinoApp(context) + ? showCupertinoDialog( + context: context, + barrierDismissible: !showOK, + builder: (context) => CupertinoAlertDialog( + content: content, + actions: [ + if (showOK) + CupertinoDialogAction( + onPressed: () => Navigator.pop(context), + child: const Text('OK'), ), - ) - : showDialog( - context: context, - barrierDismissible: !showOK, - builder: - (context) => Builder( - builder: (context) { - return AlertDialog( - content: content, - actions: [ - if (showOK) - TextButton( - onPressed: () => Navigator.pop(context), - child: const Text('OK'), - ), - ], - ); - }, - ), - ); + ], + ), + ) + : showDialog( + context: context, + barrierDismissible: !showOK, + builder: (context) => Builder( + builder: (context) { + return AlertDialog( + content: content, + actions: [ + if (showOK) + TextButton( + onPressed: () => Navigator.pop(context), + child: const Text('OK'), + ), + ], + ); + }, + ), + ); } diff --git a/lib/src/dialogs/adaptive_snack_bar/adaptive_snack_bar.dart b/lib/src/dialogs/adaptive_snack_bar/adaptive_snack_bar.dart index 164519f3..51cf611e 100644 --- a/lib/src/dialogs/adaptive_snack_bar/adaptive_snack_bar.dart +++ b/lib/src/dialogs/adaptive_snack_bar/adaptive_snack_bar.dart @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import 'package:flutter/material.dart' show ScaffoldMessenger, SnackBar; +import 'package:material_ui/material_ui.dart' show ScaffoldMessenger, SnackBar; import 'package:flutter/widgets.dart'; import '../../utility.dart'; @@ -27,9 +27,8 @@ class AdaptiveSnackBar { if (isCupertinoApp(context)) { _showCupertinoSnackBar(context: context, message: message); } else { - ScaffoldMessenger.of( - context, - ).showSnackBar(SnackBar(content: Text(message))); + ScaffoldMessenger.of(context) + .showSnackBar(SnackBar(content: Text(message))); } } @@ -40,12 +39,11 @@ class AdaptiveSnackBar { }) { const animationDurationMillis = 200; final overlayEntry = OverlayEntry( - builder: - (context) => CupertinoSnackBar( - message: message, - animationDurationMillis: animationDurationMillis, - waitDurationMillis: durationMillis, - ), + builder: (context) => CupertinoSnackBar( + message: message, + animationDurationMillis: animationDurationMillis, + waitDurationMillis: durationMillis, + ), ); Future.delayed( Duration(milliseconds: durationMillis + 2 * animationDurationMillis), diff --git a/lib/src/dialogs/adaptive_snack_bar/cupertino_snack_bar.dart b/lib/src/dialogs/adaptive_snack_bar/cupertino_snack_bar.dart index dee6b234..e253a011 100644 --- a/lib/src/dialogs/adaptive_snack_bar/cupertino_snack_bar.dart +++ b/lib/src/dialogs/adaptive_snack_bar/cupertino_snack_bar.dart @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import 'package:flutter/cupertino.dart'; +import 'package:cupertino_ui/cupertino_ui.dart'; /// A widget that displays a Cupertino-style snack bar. /// diff --git a/lib/src/dialogs/image_preview_dialog.dart b/lib/src/dialogs/image_preview_dialog.dart index 279ad11c..b187579d 100644 --- a/lib/src/dialogs/image_preview_dialog.dart +++ b/lib/src/dialogs/image_preview_dialog.dart @@ -24,10 +24,9 @@ class ImagePreviewDialog extends StatelessWidget { child: Center( child: switch (attachment) { (final ImageFileAttachment a) => Image.memory(a.bytes, fit: _fit), - (FileAttachment _) => - throw AssertionError( - 'File attachments not supported in image preview dialog', - ), + (FileAttachment _) => throw AssertionError( + 'File attachments not supported in image preview dialog', + ), (final LinkAttachment a) => Image.network(a.url.toString(), fit: _fit), }, ), diff --git a/lib/src/dialogs/url_input_dialog.dart b/lib/src/dialogs/url_input_dialog.dart index 7e2cd6aa..ef58b443 100644 --- a/lib/src/dialogs/url_input_dialog.dart +++ b/lib/src/dialogs/url_input_dialog.dart @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import 'package:flutter/cupertino.dart'; -import 'package:flutter/material.dart'; +import 'package:cupertino_ui/cupertino_ui.dart'; +import 'package:material_ui/material_ui.dart'; import '../providers/interface/attachments.dart'; @@ -37,76 +37,101 @@ Future showUrlInputDialog(BuildContext context) async { builder: (context, setState) { return Theme.of(context).platform == TargetPlatform.iOS ? CupertinoAlertDialog( - title: const Text('Attach URL'), - content: Column( - mainAxisSize: MainAxisSize.min, - children: [ - const SizedBox(height: 8), - CupertinoTextField( - controller: controller, - placeholder: 'https://flutter.dev', - keyboardType: TextInputType.url, - autofocus: true, - onChanged: (value) { - if (errorText != null) { - setState(() => errorText = null); + title: const Text('Attach URL'), + content: Column( + mainAxisSize: MainAxisSize.min, + children: [ + const SizedBox(height: 8), + CupertinoTextField( + controller: controller, + placeholder: 'https://flutter.dev', + keyboardType: TextInputType.url, + autofocus: true, + onChanged: (value) { + if (errorText != null) { + setState(() => errorText = null); + } + }, + ), + if (errorText != null) + Padding( + padding: const EdgeInsets.only(top: 8), + child: Text( + errorText!, + style: const TextStyle( + color: CupertinoColors.systemRed, + fontSize: 13, + ), + ), + ), + ], + ), + actions: [ + CupertinoDialogAction( + onPressed: () => Navigator.of(context).pop(null), + child: const Text('Cancel'), + ), + CupertinoDialogAction( + isDefaultAction: true, + onPressed: () { + final attachment = _validateAndCreateAttachment( + controller.text, + ); + if (attachment != null) { + Navigator.of(context).pop(attachment); + } else { + setState( + () => errorText = 'Please enter a valid URL', + ); } }, + child: const Text('Add'), ), - if (errorText != null) - Padding( - padding: const EdgeInsets.only(top: 8), - child: Text( - errorText!, - style: const TextStyle( - color: CupertinoColors.systemRed, - fontSize: 13, - ), - ), - ), ], - ), - actions: [ - CupertinoDialogAction( - onPressed: () => Navigator.of(context).pop(null), - child: const Text('Cancel'), - ), - CupertinoDialogAction( - isDefaultAction: true, - onPressed: () { - final attachment = _validateAndCreateAttachment( - controller.text, - ); - if (attachment != null) { - Navigator.of(context).pop(attachment); - } else { - setState(() => errorText = 'Please enter a valid URL'); - } - }, - child: const Text('Add'), - ), - ], - ) + ) : AlertDialog( - title: const Text('Attach URL'), - content: Column( - mainAxisSize: MainAxisSize.min, - children: [ - TextField( - controller: controller, - decoration: InputDecoration( - hintText: 'https://flutter.dev', - errorText: errorText, + title: const Text('Attach URL'), + content: Column( + mainAxisSize: MainAxisSize.min, + children: [ + TextField( + controller: controller, + decoration: InputDecoration( + hintText: 'https://flutter.dev', + errorText: errorText, + ), + keyboardType: TextInputType.url, + autofocus: true, + onChanged: (value) { + if (errorText != null) { + setState(() => errorText = null); + } + }, + onSubmitted: (value) { + final attachment = _validateAndCreateAttachment( + value, + ); + if (attachment != null) { + Navigator.of(context).pop(attachment); + } else { + setState( + () => errorText = 'Please enter a valid URL', + ); + } + }, ), - keyboardType: TextInputType.url, - autofocus: true, - onChanged: (value) { - if (errorText != null) { - setState(() => errorText = null); - } - }, - onSubmitted: (value) { - final attachment = _validateAndCreateAttachment(value); + ], + ), + actions: [ + TextButton( + onPressed: () => Navigator.of(context).pop(null), + child: const Text('Cancel'), + ), + TextButton( + onPressed: () { + final attachment = _validateAndCreateAttachment( + controller.text, + ); if (attachment != null) { Navigator.of(context).pop(attachment); } else { @@ -115,29 +140,10 @@ Future showUrlInputDialog(BuildContext context) async { ); } }, + child: const Text('Add'), ), ], - ), - actions: [ - TextButton( - onPressed: () => Navigator.of(context).pop(null), - child: const Text('Cancel'), - ), - TextButton( - onPressed: () { - final attachment = _validateAndCreateAttachment( - controller.text, - ); - if (attachment != null) { - Navigator.of(context).pop(attachment); - } else { - setState(() => errorText = 'Please enter a valid URL'); - } - }, - child: const Text('Add'), - ), - ], - ); + ); }, ); }, diff --git a/lib/src/providers/implementations/firebase_provider.dart b/lib/src/providers/implementations/firebase_provider.dart index deeeed60..0449f03f 100644 --- a/lib/src/providers/implementations/firebase_provider.dart +++ b/lib/src/providers/implementations/firebase_provider.dart @@ -16,29 +16,25 @@ import '../interface/llm_provider.dart'; class FirebaseProvider extends LlmProvider with ChangeNotifier { /// Creates a new instance of [FirebaseProvider]. /// - /// [model] is an optional [GenerativeModel] instance for text generation. If + /// [_model] is an optional [GenerativeModel] instance for text generation. If /// provided, it will be used for chat-based interactions and text generation. /// /// [history] is an optional list of previous chat messages to initialize the /// chat session with. /// - /// [chatSafetySettings] is an optional list of safety settings to apply to + /// [_chatSafetySettings] is an optional list of safety settings to apply to /// the model's responses. /// - /// [chatGenerationConfig] is an optional configuration for controlling the + /// [_chatGenerationConfig] is an optional configuration for controlling the /// model's generation behavior. FirebaseProvider({ - required GenerativeModel model, + required this._model, void Function(Iterable)? onFunctionCalls, Iterable? history, - List? chatSafetySettings, - GenerationConfig? chatGenerationConfig, - Future?> Function(FunctionCall)? onFunctionCall, - }) : _model = model, - _history = history?.toList() ?? [], - _chatSafetySettings = chatSafetySettings, - _chatGenerationConfig = chatGenerationConfig, - _onFunctionCall = onFunctionCall { + this._chatSafetySettings, + this._chatGenerationConfig, + this._onFunctionCall, + }) : _history = history?.toList() ?? [] { _chat = _startChat(history); } diff --git a/lib/src/providers/interface/attachments.dart b/lib/src/providers/interface/attachments.dart index e2746d11..1dab3a9d 100644 --- a/lib/src/providers/interface/attachments.dart +++ b/lib/src/providers/interface/attachments.dart @@ -59,10 +59,9 @@ final class FileAttachment extends Attachment { required String name, required String mimeType, required Uint8List bytes, - }) => - Attachment._isImage(mimeType) - ? ImageFileAttachment(name: name, mimeType: mimeType, bytes: bytes) - : FileAttachment(name: name, mimeType: mimeType, bytes: bytes); + }) => Attachment._isImage(mimeType) + ? ImageFileAttachment(name: name, mimeType: mimeType, bytes: bytes) + : FileAttachment(name: name, mimeType: mimeType, bytes: bytes); /// The MIME type of the file attachment. final String mimeType; diff --git a/lib/src/providers/interface/llm_provider.dart b/lib/src/providers/interface/llm_provider.dart index 830770b0..10919a57 100644 --- a/lib/src/providers/interface/llm_provider.dart +++ b/lib/src/providers/interface/llm_provider.dart @@ -71,11 +71,10 @@ abstract class LlmProvider implements Listenable { /// A function that generates a stream of text based on a prompt and /// attachments. -typedef LlmStreamGenerator = - Stream Function( - String prompt, { - required Iterable attachments, - }); +typedef LlmStreamGenerator = Stream Function( + String prompt, { + required Iterable attachments, +}); /// A function that converts speech to text. typedef SpeechToTextConverter = Stream Function(XFile file); diff --git a/lib/src/styles/waveform_recorder_style.dart b/lib/src/styles/waveform_recorder_style.dart index df14e0ca..fb4d2d43 100644 --- a/lib/src/styles/waveform_recorder_style.dart +++ b/lib/src/styles/waveform_recorder_style.dart @@ -1,4 +1,4 @@ -import 'package:flutter/material.dart'; +import 'package:material_ui/material_ui.dart'; /// Style for the waveform recorder widget. @immutable diff --git a/lib/src/utility.dart b/lib/src/utility.dart index feecfab4..c362fd14 100644 --- a/lib/src/utility.dart +++ b/lib/src/utility.dart @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import 'package:flutter/cupertino.dart' show BuildContext, CupertinoApp; +import 'package:cupertino_ui/cupertino_ui.dart' show BuildContext, CupertinoApp; import 'package:flutter/services.dart'; import 'package:universal_platform/universal_platform.dart'; @@ -70,12 +70,11 @@ Future copyToClipboard( /// * [color]: The [Color] to be inverted. This parameter must not be null. /// /// Returns: A new [Color] object with the inverted RGB values. -Color? invertColor(Color? color) => - color != null - ? Color.from( - alpha: color.a, - red: 1 - color.r, - green: 1 - color.g, - blue: 1 - color.b, - ) - : null; +Color? invertColor(Color? color) => color != null + ? Color.from( + alpha: color.a, + red: 1 - color.r, + green: 1 - color.g, + blue: 1 - color.b, + ) + : null; diff --git a/lib/src/views/action_button.dart b/lib/src/views/action_button.dart index bb26adf0..c0e66b36 100644 --- a/lib/src/views/action_button.dart +++ b/lib/src/views/action_button.dart @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import 'package:flutter/material.dart' show Tooltip; +import 'package:material_ui/material_ui.dart' show Tooltip; import 'package:flutter/widgets.dart'; import '../styles/action_button_style.dart'; @@ -44,18 +44,13 @@ class ActionButton extends StatelessWidget { height: size, decoration: style.iconDecoration, // tooltips aren't a thing in cupertino, so skip it - child: - isCupertinoApp(context) - ? Icon(style.icon, color: style.iconColor, size: size * 0.6) - : Tooltip( - message: style.text, - textStyle: style.textStyle, - child: Icon( - style.icon, - color: style.iconColor, - size: size * 0.6, - ), - ), + child: isCupertinoApp(context) + ? Icon(style.icon, color: style.iconColor, size: size * 0.6) + : Tooltip( + message: style.text, + textStyle: style.textStyle, + child: Icon(style.icon, color: style.iconColor, size: size * 0.6), + ), ), ); } diff --git a/lib/src/views/adaptive_progress_indicator.dart b/lib/src/views/adaptive_progress_indicator.dart index 8d08f4b3..c463e0c3 100644 --- a/lib/src/views/adaptive_progress_indicator.dart +++ b/lib/src/views/adaptive_progress_indicator.dart @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import 'package:flutter/cupertino.dart' show CupertinoActivityIndicator; -import 'package:flutter/material.dart' show CircularProgressIndicator; +import 'package:cupertino_ui/cupertino_ui.dart' show CupertinoActivityIndicator; +import 'package:material_ui/material_ui.dart' show CircularProgressIndicator; import 'package:flutter/widgets.dart'; import '../utility.dart'; @@ -25,8 +25,7 @@ class AdaptiveCircularProgressIndicator extends StatelessWidget { final Color color; @override - Widget build(BuildContext context) => - isCupertinoApp(context) - ? CupertinoActivityIndicator(color: color) - : CircularProgressIndicator(color: color); + Widget build(BuildContext context) => isCupertinoApp(context) + ? CupertinoActivityIndicator(color: color) + : CircularProgressIndicator(color: color); } diff --git a/lib/src/views/attachment_view/image_attachment_view.dart b/lib/src/views/attachment_view/image_attachment_view.dart index 7c40dd00..22ddabef 100644 --- a/lib/src/views/attachment_view/image_attachment_view.dart +++ b/lib/src/views/attachment_view/image_attachment_view.dart @@ -32,10 +32,9 @@ class ImageAttachmentView extends StatelessWidget { onTap: () => unawaited(_showPreviewDialog(context)), child: switch (attachment) { (final ImageFileAttachment a) => Image.memory(a.bytes), - (FileAttachment _) => - throw AssertionError( - 'File attachments not supported in image attachment view', - ), + (FileAttachment _) => throw AssertionError( + 'File attachments not supported in image attachment view', + ), (final LinkAttachment a) => Image.network(a.url.toString()), }, ), diff --git a/lib/src/views/attachment_view/link_attachment_view.dart b/lib/src/views/attachment_view/link_attachment_view.dart index 8855c5cf..a93fd81b 100644 --- a/lib/src/views/attachment_view/link_attachment_view.dart +++ b/lib/src/views/attachment_view/link_attachment_view.dart @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import 'package:flutter/material.dart'; +import 'package:material_ui/material_ui.dart'; import '../../styles/toolkit_colors.dart'; import '../../styles/toolkit_text_styles.dart'; @@ -84,27 +84,22 @@ class LinkAttachmentView extends StatelessWidget { _getFaviconUrl(attachment.url), width: 16, height: 16, - errorBuilder: - (context, error, stackTrace) => Icon( - Icons.link, - size: 14, - color: isDark ? Colors.grey[400] : Colors.grey[600], - ), - frameBuilder: ( - context, - child, - frame, - wasSynchronouslyLoaded, - ) { - if (frame == null) { - return Icon( - Icons.link, - size: 14, - color: isDark ? Colors.grey[400] : Colors.grey[600], - ); - } - return child; - }, + errorBuilder: (context, error, stackTrace) => Icon( + Icons.link, + size: 14, + color: isDark ? Colors.grey[400] : Colors.grey[600], + ), + frameBuilder: + (context, child, frame, wasSynchronouslyLoaded) { + if (frame == null) { + return Icon( + Icons.link, + size: 14, + color: isDark ? Colors.grey[400] : Colors.grey[600], + ); + } + return child; + }, ), ), Expanded( diff --git a/lib/src/views/chat_history_view.dart b/lib/src/views/chat_history_view.dart index 429aa3c2..a604a029 100644 --- a/lib/src/views/chat_history_view.dart +++ b/lib/src/views/chat_history_view.dart @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import 'package:flutter/material.dart'; +import 'package:material_ui/material_ui.dart'; import 'package:flutter/widgets.dart'; import 'package:flutter_ai_toolkit/flutter_ai_toolkit.dart'; import 'package:flutter_ai_toolkit/src/views/chat_input/chat_suggestion_view.dart'; @@ -92,19 +92,17 @@ class _ChatHistoryViewState extends State { return Padding( padding: EdgeInsets.only(top: messageSpacing), - child: - isUser - ? UserMessageView( - message, - onEdit: - canEdit - ? () => widget.onEditMessage?.call(message) - : null, - ) - : LlmMessageView( - message, - isWelcomeMessage: messageIndex == 0, - ), + child: isUser + ? UserMessageView( + message, + onEdit: canEdit + ? () => widget.onEditMessage?.call(message) + : null, + ) + : LlmMessageView( + message, + isWelcomeMessage: messageIndex == 0, + ), ); }, ), diff --git a/lib/src/views/chat_input/attachments_action_bar.dart b/lib/src/views/chat_input/attachments_action_bar.dart index edd327d6..2e54ae7f 100644 --- a/lib/src/views/chat_input/attachments_action_bar.dart +++ b/lib/src/views/chat_input/attachments_action_bar.dart @@ -5,11 +5,13 @@ import 'dart:async'; import 'package:file_selector/file_selector.dart'; -import 'package:flutter/material.dart' +import 'package:material_ui/material_ui.dart' show Icons, MenuAnchor, MenuItemButton, MenuStyle; import 'package:flutter/widgets.dart'; + import '../../dialogs/url_input_dialog.dart'; import '../../strings/llm_chat_view_strings.dart'; + import 'package:flutter_ai_toolkit/src/utility.dart'; import 'package:image_picker/image_picker.dart'; @@ -114,11 +116,10 @@ class _AttachmentActionBarState extends State { menuItems.length, ), consumeOutsideTap: true, - builder: - (_, controller, _) => ActionButton( - onPressed: controller.isOpen ? controller.close : controller.open, - style: chatStyle.addButtonStyle!, - ), + builder: (_, controller, _) => ActionButton( + onPressed: controller.isOpen ? controller.close : controller.open, + style: chatStyle.addButtonStyle!, + ), menuChildren: menuItems, ); }, diff --git a/lib/src/views/chat_input/attachments_view.dart b/lib/src/views/chat_input/attachments_view.dart index 199964bd..079c835d 100644 --- a/lib/src/views/chat_input/attachments_view.dart +++ b/lib/src/views/chat_input/attachments_view.dart @@ -34,15 +34,14 @@ class AttachmentsView extends StatelessWidget { Widget build(BuildContext context) => Container( height: attachments.isNotEmpty ? 104 : 0, padding: const EdgeInsets.only(top: 12, bottom: 12, left: 12), - child: - attachments.isNotEmpty - ? ListView( - scrollDirection: Axis.horizontal, - children: [ - for (final a in attachments) - RemovableAttachment(attachment: a, onRemove: onRemove), - ], - ) - : const SizedBox(), + child: attachments.isNotEmpty + ? ListView( + scrollDirection: Axis.horizontal, + children: [ + for (final a in attachments) + RemovableAttachment(attachment: a, onRemove: onRemove), + ], + ) + : const SizedBox(), ); } diff --git a/lib/src/views/chat_input/chat_input.dart b/lib/src/views/chat_input/chat_input.dart index d46b8b50..441a4649 100644 --- a/lib/src/views/chat_input/chat_input.dart +++ b/lib/src/views/chat_input/chat_input.dart @@ -168,51 +168,46 @@ class _ChatInputState extends State { if (_attachments.isNotEmpty) const SizedBox(height: 6), ValueListenableBuilder( valueListenable: _textController, - builder: - (context, value, child) => ListenableBuilder( - listenable: _waveController, - builder: - (context, child) => Row( - crossAxisAlignment: CrossAxisAlignment.end, - children: [ - if (_viewModel!.enableAttachments) - Padding( - padding: const EdgeInsets.only(bottom: 14), - child: AttachmentActionBar( - onAttachments: onAttachments, - ), - ), - Expanded( - child: TextOrAudioInput( - inputStyle: _inputStyle!, - waveController: _waveController, - onCancelEdit: widget.onCancelEdit, - onRecordingStopped: onRecordingStopped, - onSubmitPrompt: onSubmitPrompt, - textController: _textController, - focusNode: _focusNode, - autofocus: widget.autofocus, - inputState: _inputState, - cancelButtonStyle: _chatStyle!.cancelButtonStyle!, - voiceNoteRecorderStyle: - _chatStyle!.voiceNoteRecorderStyle!, - chatStrings: _viewModel!.strings, - ), - ), - Padding( - padding: const EdgeInsets.only(bottom: 14), - child: InputButton( - inputState: _inputState, - chatStyle: _chatStyle!, - onSubmitPrompt: onSubmitPrompt, - onCancelPrompt: onCancelPrompt, - onStartRecording: onStartRecording, - onStopRecording: onStopRecording, - ), - ), - ], - ), - ), + builder: (context, value, child) => ListenableBuilder( + listenable: _waveController, + builder: (context, child) => Row( + crossAxisAlignment: CrossAxisAlignment.end, + children: [ + if (_viewModel!.enableAttachments) + Padding( + padding: const EdgeInsets.only(bottom: 14), + child: AttachmentActionBar(onAttachments: onAttachments), + ), + Expanded( + child: TextOrAudioInput( + inputStyle: _inputStyle!, + waveController: _waveController, + onCancelEdit: widget.onCancelEdit, + onRecordingStopped: onRecordingStopped, + onSubmitPrompt: onSubmitPrompt, + textController: _textController, + focusNode: _focusNode, + autofocus: widget.autofocus, + inputState: _inputState, + cancelButtonStyle: _chatStyle!.cancelButtonStyle!, + voiceNoteRecorderStyle: _chatStyle!.voiceNoteRecorderStyle!, + chatStrings: _viewModel!.strings, + ), + ), + Padding( + padding: const EdgeInsets.only(bottom: 14), + child: InputButton( + inputState: _inputState, + chatStyle: _chatStyle!, + onSubmitPrompt: onSubmitPrompt, + onCancelPrompt: onCancelPrompt, + onStartRecording: onStartRecording, + onStopRecording: onStopRecording, + ), + ), + ], + ), + ), ), ], ), diff --git a/lib/src/views/chat_input/removable_attachment.dart b/lib/src/views/chat_input/removable_attachment.dart index 214cc7b6..f87bb152 100644 --- a/lib/src/views/chat_input/removable_attachment.dart +++ b/lib/src/views/chat_input/removable_attachment.dart @@ -40,10 +40,9 @@ class RemovableAttachment extends StatelessWidget { Widget build(BuildContext context) => Stack( children: [ GestureDetector( - onTap: - attachment is ImageFileAttachment - ? () => unawaited(_showPreviewDialog(context)) - : null, + onTap: attachment is ImageFileAttachment + ? () => unawaited(_showPreviewDialog(context)) + : null, child: Container( padding: const EdgeInsets.only(right: 12), height: 80, diff --git a/lib/src/views/chat_input/text_or_audio_input.dart b/lib/src/views/chat_input/text_or_audio_input.dart index 72d74002..a4d90944 100644 --- a/lib/src/views/chat_input/text_or_audio_input.dart +++ b/lib/src/views/chat_input/text_or_audio_input.dart @@ -1,6 +1,8 @@ import 'package:flutter/services.dart'; import 'package:flutter/widgets.dart'; + import '../../strings/llm_chat_view_strings.dart'; + import 'package:waveform_recorder/waveform_recorder.dart'; import '../../styles/styles.dart'; @@ -16,43 +18,32 @@ import 'input_state.dart'; /// recorder when recording audio. class TextOrAudioInput extends StatelessWidget { /// The [TextOrAudioInput] widget requires several parameters: - /// - [inputStyle]: Defines the styling for the input field. - /// - [waveController]: Controls the waveform recorder. - /// - [onCancelEdit]: Callback for when editing is canceled. - /// - [onRecordingStopped]: Callback for when audio recording is stopped. - /// - [onSubmitPrompt]: Callback for when the text input is submitted. - /// - [textController]: Controls the text being edited. - /// - [focusNode]: Manages the focus of the text field. - /// - [autofocus]: Determines if the text field should be focused on build. - /// - [inputState]: Represents the current state of the input. - /// - [cancelButtonStyle]: Defines the styling for the cancel button. - /// - [voiceNoteRecorderStyle]: Defines the styling for the waveform recorder. + /// - [_inputStyle]: Defines the styling for the input field. + /// - [_waveController]: Controls the waveform recorder. + /// - [_onCancelEdit]: Callback for when editing is canceled. + /// - [_onRecordingStopped]: Callback for when audio recording is stopped. + /// - [_onSubmitPrompt]: Callback for when the text input is submitted. + /// - [_textController]: Controls the text being edited. + /// - [_focusNode]: Manages the focus of the text field. + /// - [_autofocus]: Determines if the text field should be focused on build. + /// - [_inputState]: Represents the current state of the input. + /// - [_cancelButtonStyle]: Defines the styling for the cancel button. + /// - [_voiceNoteRecorderStyle]: Defines the styling for the waveform recorder. const TextOrAudioInput({ super.key, - required ChatInputStyle inputStyle, - required WaveformRecorderController waveController, - required void Function()? onCancelEdit, - required void Function() onRecordingStopped, - required void Function() onSubmitPrompt, - required TextEditingController textController, - required FocusNode focusNode, - required bool autofocus, - required InputState inputState, - required ActionButtonStyle cancelButtonStyle, - required VoiceNoteRecorderStyle voiceNoteRecorderStyle, - required LlmChatViewStrings chatStrings, - }) : _cancelButtonStyle = cancelButtonStyle, - _inputState = inputState, - _autofocus = autofocus, - _focusNode = focusNode, - _textController = textController, - _onSubmitPrompt = onSubmitPrompt, - _onRecordingStopped = onRecordingStopped, - _onCancelEdit = onCancelEdit, - _waveController = waveController, - _inputStyle = inputStyle, - _voiceNoteRecorderStyle = voiceNoteRecorderStyle, - _chatStrings = chatStrings; + required this._inputStyle, + required this._waveController, + required this._onCancelEdit, + required this._onRecordingStopped, + required this._onSubmitPrompt, + required this._textController, + required this._focusNode, + required this._autofocus, + required this._inputState, + required this._cancelButtonStyle, + required this._voiceNoteRecorderStyle, + required this._chatStrings, + }); final ChatInputStyle _inputStyle; final WaveformRecorderController _waveController; @@ -86,51 +77,47 @@ class TextOrAudioInput extends StatelessWidget { minHeight: _minInputHeight, maxHeight: _maxInputHeight, ), - child: - _waveController.isRecording - ? WaveformRecorder( - controller: _waveController, - height: _voiceNoteRecorderStyle.height!, - waveColor: _voiceNoteRecorderStyle.waveColor!, - durationTextStyle: - _voiceNoteRecorderStyle.durationTextStyle!, - onRecordingStopped: _onRecordingStopped, - ) - : ChatTextField( - minLines: 1, - maxLines: 1024, - controller: _textController, - autofocus: _autofocus, - focusNode: _focusNode, - textInputAction: - isMobile - ? TextInputAction.newline - : TextInputAction.done, - onSubmitted: - _inputState == InputState.canSubmitPrompt - ? (_) => _onSubmitPrompt() - : (_) => _focusNode.requestFocus(), - style: _inputStyle.textStyle!, - hintText: _inputStyle.hintText!, - hintStyle: _inputStyle.hintStyle!, - hintPadding: const EdgeInsets.symmetric( - horizontal: 12, - vertical: 8, - ), + child: _waveController.isRecording + ? WaveformRecorder( + controller: _waveController, + height: _voiceNoteRecorderStyle.height!, + waveColor: _voiceNoteRecorderStyle.waveColor!, + durationTextStyle: + _voiceNoteRecorderStyle.durationTextStyle!, + onRecordingStopped: _onRecordingStopped, + ) + : ChatTextField( + minLines: 1, + maxLines: 1024, + controller: _textController, + autofocus: _autofocus, + focusNode: _focusNode, + textInputAction: isMobile + ? TextInputAction.newline + : TextInputAction.done, + onSubmitted: _inputState == InputState.canSubmitPrompt + ? (_) => _onSubmitPrompt() + : (_) => _focusNode.requestFocus(), + style: _inputStyle.textStyle!, + hintText: _inputStyle.hintText!, + hintStyle: _inputStyle.hintStyle!, + hintPadding: const EdgeInsets.symmetric( + horizontal: 12, + vertical: 8, ), + ), ), ), ), Align( alignment: Alignment.topRight, - child: - _onCancelEdit != null - ? EditingIndicator( - onCancelEdit: _onCancelEdit, - cancelButtonStyle: _cancelButtonStyle, - editingTitle: _chatStrings.editing, - ) - : const SizedBox(), + child: _onCancelEdit != null + ? EditingIndicator( + onCancelEdit: _onCancelEdit, + cancelButtonStyle: _cancelButtonStyle, + editingTitle: _chatStrings.editing, + ) + : const SizedBox(), ), ], ); diff --git a/lib/src/views/chat_message_view/adaptive_copy_text.dart b/lib/src/views/chat_message_view/adaptive_copy_text.dart index b859bc22..d1d71a8f 100644 --- a/lib/src/views/chat_message_view/adaptive_copy_text.dart +++ b/lib/src/views/chat_message_view/adaptive_copy_text.dart @@ -1,7 +1,8 @@ import 'dart:async'; -import 'package:flutter/cupertino.dart' show DefaultCupertinoLocalizations; -import 'package:flutter/material.dart' +import 'package:cupertino_ui/cupertino_ui.dart' + show DefaultCupertinoLocalizations; +import 'package:material_ui/material_ui.dart' show DefaultMaterialLocalizations, SelectionArea, @@ -63,14 +64,13 @@ class AdaptiveCopyText extends StatelessWidget { MenuItem( label: Text(chatStrings.copy), icon: Icon(chatStyle.copyButtonStyle!.icon), - onSelected: - (_) => unawaited( - copyToClipboard( - context, - clipboardText, - chatStrings.copyToClipboard, - ), - ), + onSelected: (_) => unawaited( + copyToClipboard( + context, + clipboardText, + chatStrings.copyToClipboard, + ), + ), ), ], ); @@ -82,14 +82,14 @@ class AdaptiveCopyText extends StatelessWidget { : isCupertinoApp(context) // Ensure MaterialLocalizations is available for SelectionArea ? Localizations( - locale: Localizations.localeOf(context), - delegates: const [ - DefaultMaterialLocalizations.delegate, - DefaultWidgetsLocalizations.delegate, - DefaultCupertinoLocalizations.delegate, - ], - child: SelectionArea(child: child), - ) + locale: Localizations.localeOf(context), + delegates: const [ + DefaultMaterialLocalizations.delegate, + DefaultWidgetsLocalizations.delegate, + DefaultCupertinoLocalizations.delegate, + ], + child: SelectionArea(child: child), + ) : SelectionArea(child: child); } } diff --git a/lib/src/views/chat_message_view/hovering_buttons.dart b/lib/src/views/chat_message_view/hovering_buttons.dart index cb37b1e0..6c90541a 100644 --- a/lib/src/views/chat_message_view/hovering_buttons.dart +++ b/lib/src/views/chat_message_view/hovering_buttons.dart @@ -56,58 +56,55 @@ class HoveringButtons extends StatelessWidget { return clipboardText == null ? paddedChild : MouseRegion( - onEnter: (_) => _hovering.value = true, - onExit: (_) => _hovering.value = false, - child: Stack( - children: [ - paddedChild, - ListenableBuilder( - listenable: _hovering, - builder: - (context, child) => - _hovering.value - ? Positioned( - bottom: 0, - right: isUserMessage ? 0 : null, - left: isUserMessage ? null : 32, - child: Row( - spacing: 6, - children: [ - if (onEdit != null) - GestureDetector( - onTap: onEdit, - child: Icon( - chatStyle.editButtonStyle!.icon, - size: _iconSize.toDouble(), - color: invertColor( - chatStyle.editButtonStyle!.iconColor, - ), - ), - ), - GestureDetector( - onTap: - () => unawaited( - copyToClipboard( - context, - clipboardText!, - clipboardMessage, - ), - ), - child: Icon( - chatStyle.copyButtonStyle!.icon, - size: 12, - color: invertColor( - chatStyle.copyButtonStyle!.iconColor, - ), + onEnter: (_) => _hovering.value = true, + onExit: (_) => _hovering.value = false, + child: Stack( + children: [ + paddedChild, + ListenableBuilder( + listenable: _hovering, + builder: (context, child) => _hovering.value + ? Positioned( + bottom: 0, + right: isUserMessage ? 0 : null, + left: isUserMessage ? null : 32, + child: Row( + spacing: 6, + children: [ + if (onEdit != null) + GestureDetector( + onTap: onEdit, + child: Icon( + chatStyle.editButtonStyle!.icon, + size: _iconSize.toDouble(), + color: invertColor( + chatStyle.editButtonStyle!.iconColor, ), ), - ], + ), + GestureDetector( + onTap: () => unawaited( + copyToClipboard( + context, + clipboardText!, + clipboardMessage, + ), + ), + child: Icon( + chatStyle.copyButtonStyle!.icon, + size: 12, + color: invertColor( + chatStyle.copyButtonStyle!.iconColor, + ), + ), ), - ) - : const SizedBox(), - ), - ], - ), - ); + ], + ), + ) + : const SizedBox(), + ), + ], + ), + ); } } diff --git a/lib/src/views/chat_message_view/llm_message_view.dart b/lib/src/views/chat_message_view/llm_message_view.dart index 9aedca05..cb601e86 100644 --- a/lib/src/views/chat_message_view/llm_message_view.dart +++ b/lib/src/views/chat_message_view/llm_message_view.dart @@ -77,40 +77,36 @@ class LlmMessageView extends StatelessWidget { decoration: llmStyle.decoration, margin: const EdgeInsets.only(left: 28), padding: llmStyle.padding, - child: - text == null - ? SizedBox( - width: 32, - child: JumpingDotsProgressIndicator( - fontSize: 24, - color: chatStyle.progressIndicatorColor!, - ), - ) - : AdaptiveCopyText( - clipboardText: text, - chatStyle: chatStyle, - chatStrings: chatString, - child: - isWelcomeMessage || - viewModel.responseBuilder == null - ? MarkdownBody( - data: text, - selectable: false, - styleSheet: llmStyle.markdownStyle, - imageBuilder: - llmStyle.imageBuilder ?? - _emptyImageBuilder, - onTapLink: (_, href, _) { - if (href != null) { - launchUrl(Uri.parse(href)); - } - }, - ) - : viewModel.responseBuilder!( - context, - text, - ), + child: text == null + ? SizedBox( + width: 32, + child: JumpingDotsProgressIndicator( + fontSize: 24, + color: chatStyle.progressIndicatorColor!, ), + ) + : AdaptiveCopyText( + clipboardText: text, + chatStyle: chatStyle, + chatStrings: chatString, + child: + isWelcomeMessage || + viewModel.responseBuilder == null + ? MarkdownBody( + data: text, + selectable: false, + styleSheet: llmStyle.markdownStyle, + imageBuilder: + llmStyle.imageBuilder ?? + _emptyImageBuilder, + onTapLink: (_, href, _) { + if (href != null) { + launchUrl(Uri.parse(href)); + } + }, + ) + : viewModel.responseBuilder!(context, text), + ), ), ), ], diff --git a/lib/src/views/chat_text_field.dart b/lib/src/views/chat_text_field.dart index 551bc01e..d0fcd145 100644 --- a/lib/src/views/chat_text_field.dart +++ b/lib/src/views/chat_text_field.dart @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import 'package:flutter/cupertino.dart' show CupertinoTextField; -import 'package:flutter/material.dart' +import 'package:cupertino_ui/cupertino_ui.dart' show CupertinoTextField; +import 'package:material_ui/material_ui.dart' show InputBorder, InputDecoration, TextField, TextInputAction; import 'package:flutter/services.dart'; import 'package:flutter/widgets.dart'; @@ -72,45 +72,44 @@ class ChatTextField extends StatelessWidget { @override Widget build(BuildContext context) => CallbackShortcuts( bindings: { - const SingleActivator(LogicalKeyboardKey.enter): - () => onSubmitted(controller.text), + const SingleActivator(LogicalKeyboardKey.enter): () => + onSubmitted(controller.text), }, - child: - isCupertinoApp(context) - ? CupertinoTextField( - minLines: minLines, - maxLines: maxLines, - controller: controller, - autofocus: autofocus, - focusNode: focusNode, - onSubmitted: onSubmitted, - style: style, - placeholder: hintText, - placeholderStyle: hintStyle, - padding: hintPadding ?? EdgeInsets.zero, - decoration: BoxDecoration( - border: Border.all(width: 0, color: ToolkitColors.transparent), - ), - keyboardType: TextInputType.multiline, - textInputAction: TextInputAction.newline, - ) - : TextField( - minLines: minLines, - maxLines: maxLines, - controller: controller, - autofocus: autofocus, - focusNode: focusNode, - keyboardType: TextInputType.multiline, - textInputAction: TextInputAction.newline, - onSubmitted: onSubmitted, - style: style, - decoration: InputDecoration( - border: InputBorder.none, - hintText: hintText, - hintStyle: hintStyle, - contentPadding: hintPadding, - isDense: false, - ), + child: isCupertinoApp(context) + ? CupertinoTextField( + minLines: minLines, + maxLines: maxLines, + controller: controller, + autofocus: autofocus, + focusNode: focusNode, + onSubmitted: onSubmitted, + style: style, + placeholder: hintText, + placeholderStyle: hintStyle, + padding: hintPadding ?? EdgeInsets.zero, + decoration: BoxDecoration( + border: Border.all(width: 0, color: ToolkitColors.transparent), ), + keyboardType: TextInputType.multiline, + textInputAction: TextInputAction.newline, + ) + : TextField( + minLines: minLines, + maxLines: maxLines, + controller: controller, + autofocus: autofocus, + focusNode: focusNode, + keyboardType: TextInputType.multiline, + textInputAction: TextInputAction.newline, + onSubmitted: onSubmitted, + style: style, + decoration: InputDecoration( + border: InputBorder.none, + hintText: hintText, + hintStyle: hintStyle, + contentPadding: hintPadding, + isDense: false, + ), + ), ); } diff --git a/lib/src/views/llm_chat_view/llm_chat_view.dart b/lib/src/views/llm_chat_view/llm_chat_view.dart index 1b074436..1e89a98d 100644 --- a/lib/src/views/llm_chat_view/llm_chat_view.dart +++ b/lib/src/views/llm_chat_view/llm_chat_view.dart @@ -195,57 +195,57 @@ class _LlmChatViewState extends State final chatStyle = LlmChatViewStyle.resolve(widget.viewModel.style); return ListenableBuilder( listenable: widget.viewModel.provider, - builder: - (context, child) => ChatViewModelProvider( - viewModel: widget.viewModel, - child: GestureDetector( - onTap: () { - // Dismiss keyboard when tapping anywhere in the view - FocusScope.of(context).unfocus(); - }, - child: Container( - color: chatStyle.backgroundColor, - child: Column( - children: [ - Expanded( - child: Stack( - children: [ - ChatHistoryView( - // can only edit if we're not waiting on the LLM or if - // we're not already editing an LLM response - onEditMessage: - _pendingPromptResponse == null && - _associatedResponse == null - ? _onEditMessage - : null, - onSelectSuggestion: _onSelectSuggestion, - ), - ], + builder: (context, child) => ChatViewModelProvider( + viewModel: widget.viewModel, + child: GestureDetector( + onTap: () { + // Dismiss keyboard when tapping anywhere in the view + FocusScope.of(context).unfocus(); + }, + child: Container( + color: chatStyle.backgroundColor, + child: Column( + children: [ + Expanded( + child: Stack( + children: [ + ChatHistoryView( + // can only edit if we're not waiting on the LLM or if + // we're not already editing an LLM response + onEditMessage: + _pendingPromptResponse == null && + _associatedResponse == null + ? _onEditMessage + : null, + onSelectSuggestion: _onSelectSuggestion, ), - ), - SafeArea( - child: ChatInput( - initialMessage: _initialMessage, - autofocus: - widget.autofocus ?? - widget.viewModel.suggestions.isEmpty, - onCancelEdit: - _associatedResponse != null ? _onCancelEdit : null, - onSendMessage: _onSendMessage, - onCancelMessage: - _pendingPromptResponse == null - ? null - : _onCancelMessage, - onTranslateStt: _onTranslateStt, - onCancelStt: - _pendingSttResponse == null ? null : _onCancelStt, - ), - ), - ], + ], + ), + ), + SafeArea( + child: ChatInput( + initialMessage: _initialMessage, + autofocus: + widget.autofocus ?? + widget.viewModel.suggestions.isEmpty, + onCancelEdit: _associatedResponse != null + ? _onCancelEdit + : null, + onSendMessage: _onSendMessage, + onCancelMessage: _pendingPromptResponse == null + ? null + : _onCancelMessage, + onTranslateStt: _onTranslateStt, + onCancelStt: _pendingSttResponse == null + ? null + : _onCancelStt, + ), ), - ), + ], ), ), + ), + ), ); } @@ -316,13 +316,12 @@ class _LlmChatViewState extends State widget.viewModel.speechToText?.call(file) ?? _convertSpeechToText(file), onUpdate: (text) => response.write(text), - onDone: - (error) async => _onSttDone( - error, - response.toString().trim(), - file, - currentAttachments, - ), + onDone: (error) async => _onSttDone( + error, + response.toString().trim(), + file, + currentAttachments, + ), ); setState(() {}); diff --git a/lib/src/views/response_builder.dart b/lib/src/views/response_builder.dart index ac959820..4add43c7 100644 --- a/lib/src/views/response_builder.dart +++ b/lib/src/views/response_builder.dart @@ -14,5 +14,7 @@ import 'package:flutter/widgets.dart'; /// /// The function should return a [Widget] that represents the formatted response /// in the chat interface. -typedef ResponseBuilder = - Widget Function(BuildContext context, String response); +typedef ResponseBuilder = Widget Function( + BuildContext context, + String response, +); diff --git a/pubspec.yaml b/pubspec.yaml index 62f0b7a2..bf614618 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -2,7 +2,7 @@ name: flutter_ai_toolkit description: >- AI chat widget for Flutter apps targeting mobile, desktop, and web supporting text, image, and voice input. -version: 1.1.0 +version: 1.2.0 repository: https://github.com/flutter/ai topics: @@ -11,11 +11,12 @@ topics: - gemini environment: - sdk: ^3.7.0 - flutter: '>=3.27.0' + sdk: ^3.13.0 + flutter: '>=3.47.0' dependencies: cross_file: ^0.3.5+2 + cupertino_ui: ^1.1.7 file_selector: ^1.1.0 firebase_ai: ^3.12.2 flutter: @@ -25,6 +26,7 @@ dependencies: flutter_picture_taker: ^0.2.0 google_fonts: ^8.1.0 image_picker: ^1.2.2 + material_ui: ^1.11.1 mime: ^2.0.0 universal_platform: ^1.1.0 url_launcher: ^6.3.2 diff --git a/test/llm_message_image_test.dart b/test/llm_message_image_test.dart index 484f240d..9f9eeb84 100644 --- a/test/llm_message_image_test.dart +++ b/test/llm_message_image_test.dart @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import 'package:flutter/material.dart'; +import 'package:material_ui/material_ui.dart'; import 'package:flutter_ai_toolkit/flutter_ai_toolkit.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -172,9 +172,8 @@ void main() { enableVoiceNotes: false, style: LlmChatViewStyle( llmMessageStyle: LlmMessageStyle( - imageBuilder: - (uri, title, alt) => - Text('CUSTOM_IMG:${uri.host}:$alt:$title'), + imageBuilder: (uri, title, alt) => + Text('CUSTOM_IMG:${uri.host}:$alt:$title'), ), ), ), diff --git a/test/smoke_test.dart b/test/smoke_test.dart index 9d84483f..0b42a74f 100644 --- a/test/smoke_test.dart +++ b/test/smoke_test.dart @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import 'package:flutter/material.dart'; +import 'package:material_ui/material_ui.dart'; import 'package:flutter_ai_toolkit/flutter_ai_toolkit.dart'; import 'package:flutter_markdown_plus/flutter_markdown_plus.dart'; import 'package:flutter_test/flutter_test.dart'; diff --git a/test/suggestions_test.dart b/test/suggestions_test.dart index c4cb622a..ed136eb3 100644 --- a/test/suggestions_test.dart +++ b/test/suggestions_test.dart @@ -1,4 +1,4 @@ -import 'package:flutter/material.dart'; +import 'package:material_ui/material_ui.dart'; import 'package:flutter_ai_toolkit/flutter_ai_toolkit.dart'; import 'package:flutter_ai_toolkit/src/views/chat_input/chat_suggestion_view.dart'; import 'package:flutter_ai_toolkit/src/views/chat_text_field.dart'; @@ -10,8 +10,7 @@ void main() { home: Scaffold( appBar: AppBar(title: const Text('Title')), body: LlmChatView( - welcomeMessage: - 'Hello! This is the Flutter AI Assistant, how can I help you today?', + welcomeMessage: 'Hello! This is the Flutter AI Assistant, how can I help you today?', suggestions: List.generate( suggestionsCount, (index) => 'Suggestion sample ${index + 1}',