brave_api 1.0.1 brave_api: ^1.0.1 copied to clipboard
A Package for Flutter that makes it to use the Brave API easy.
Brave Search Flutter #
A highly customizable Flutter package that provides a search interface using the Brave Search API. This package offers a rich set of features and customization options for creating a seamless search experience in your Flutter applications.
Features #
🔍 Core Features
- Full-featured search interface using Brave Search API
- Built-in WebView for Android
- External URL launcher for iOS
- Search result caching
- Error handling
🎨 Customization Options
- Fully customizable search screen
- Custom themes and styling
- Custom loading states
- Custom error handling
- Custom result rendering
- Custom animations and transitions
🛠️ Advanced Features
- Platform-specific behavior handling
- Extensive callback system
- Navigation controls
- Progress indicators
- JavaScript control
- Custom scroll physics
Installation #
Add this to your package's pubspec.yaml
file:
dependencies:
brave_api: ^1.0.1
Then run:
flutter pub get
Setup #
- Initialize the package with your Brave Search API key:
void main() {
BraveSearchConfig.initialize(apiKey: 'YOUR_BRAVE_API_KEY');
runApp(MyApp());
}
- Import the package:
import 'package:brave_api/brave_api.dart';
Basic Usage #
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: BraveSearchScreen(
title: 'Search',
onResultSelected: (result) {
print('Selected: ${result.title}');
},
),
);
}
}
Advanced Customization #
Custom Search Screen Styling #
BraveSearchScreen(
title: 'Custom Search',
titleStyle: TextStyle(
fontSize: 24,
fontWeight: FontWeight.bold,
color: Colors.indigo,
),
searchDecoration: InputDecoration(
hintText: 'What are you looking for?',
prefixIcon: Icon(Icons.search),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(15),
),
),
backgroundColor: Colors.grey[50],
resultsPadding: EdgeInsets.all(16),
)
Custom Loading and Error States #
BraveSearchScreen(
loadingIndicator: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
CircularProgressIndicator(),
SizedBox(height: 16),
Text('Searching...'),
],
),
errorBuilder: (context, error) => Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(Icons.error_outline),
Text('Error: $error'),
ElevatedButton(
onPressed: () => print('Retry'),
child: Text('Retry'),
),
],
),
),
)
Custom Result Rendering #
BraveSearchScreen(
resultBuilder: (context, result) => Card(
margin: EdgeInsets.symmetric(horizontal: 16, vertical: 8),
child: ListTile(
title: Text(
result.title,
style: TextStyle(fontWeight: FontWeight.bold),
),
subtitle: Text(result.description),
trailing: Icon(Icons.arrow_forward),
onTap: () => print('Selected: ${result.title}'),
),
),
)
Custom WebView Configuration #
WebViewScreen(
url: 'https://example.com',
enableJavaScript: true,
enableZoom: true,
loadingIndicator: CircularProgressIndicator(),
navigationActions: [
IconButton(
icon: Icon(Icons.refresh),
onPressed: () => print('Refresh'),
),
],
)
Available Customization Options #
Search Screen Options #
title
: Custom title for the search screentitleStyle
: Custom style for the titlesearchDecoration
: Custom decoration for the search input fieldtheme
: Custom theme for the entire search screenappBar
: Custom app bar widgetloadingIndicator
: Custom loading indicator widgeterrorBuilder
: Custom error widget builderemptyResultsWidget
: Custom empty results widgetresultBuilder
: Custom search result builderbackgroundColor
: Custom background colorresultDivider
: Custom divider between resultsanimationDuration
: Animation duration for loading statesscrollPhysics
: Custom scroll physics for the results listresultsPadding
: Custom padding for search results
WebView Options #
enableJavaScript
: Enable/disable JavaScriptenableZoom
: Enable/disable zoom controlsuserAgent
: Custom user agent stringnavigationDelegate
: Custom navigation handlingprogressIndicatorBuilder
: Custom progress indicatornavigationActions
: Custom navigation controls
Callback Options #
onSearch
: Triggered when a search is performedonResultSelected
: Triggered when a result is selectedonError
: Triggered when an error occurs
Platform Specific Behavior #
The package automatically handles platform-specific behaviors:
- Android: Opens results in an in-app WebView
- iOS: Opens results in the default browser using URL launcher
Contributing #
We welcome contributions! Please feel free to submit a Pull Request.
License #
This project is licensed under the MIT License - see the LICENSE file for details.