Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion examples/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ include: package:flutter_lints/flutter.yaml
analyzer:
language:
strict-casts: true
# strict-inference: true
strict-inference: true
strict-raw-types: true
errors:
avoid_print: ignore
Expand Down Expand Up @@ -35,6 +35,7 @@ linter:
- prefer_const_declarations
- prefer_const_literals_to_create_immutables
- prefer_final_fields
- prefer_if_elements_to_conditional_expressions
- prefer_relative_imports
- prefer_single_quotes
- simple_directive_paths
Expand All @@ -51,6 +52,7 @@ linter:
- unnecessary_library_directive
- unnecessary_null_aware_operator_on_extension_on_nullable
- unnecessary_parenthesis
- unnecessary_primary_constructor_body
- unnecessary_statements
- unnecessary_unawaited
- unnecessary_underscores
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class ApiClientService {
Future<UserProfile> getUserProfile() async {
// #enddocregion ApiClientService
// Simulate a network GET request
await Future.delayed(const Duration(seconds: 2));
await Future<void>.delayed(const Duration(seconds: 2));
// Return a dummy user profile
return const UserProfile(
name: 'John Doe (from API)',
Expand All @@ -19,7 +19,7 @@ class ApiClientService {
Future<void> putUserProfile(UserProfile userProfile) async {
// #enddocregion ApiClientService
// Simulate a network PUT request
await Future.delayed(const Duration(seconds: 2));
await Future<void>.delayed(const Duration(seconds: 2));
// #docregion ApiClientService
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class DatabaseService {
Future<UserProfile?> fetchUserProfile() async {
// #enddocregion DatabaseService
// Simulate a database select query
await Future.delayed(const Duration(milliseconds: 100));
await Future<void>.delayed(const Duration(milliseconds: 100));
// Return a dummy user profile
return const UserProfile(
name: 'John Doe (from Database)',
Expand All @@ -20,7 +20,7 @@ class DatabaseService {
Future<void> updateUserProfile(UserProfile userProfile) async {
// #enddocregion DatabaseService
// Simulate a database update query
await Future.delayed(const Duration(milliseconds: 100));
await Future<void>.delayed(const Duration(milliseconds: 100));
// #docregion DatabaseService
}
}
Expand Down
4 changes: 2 additions & 2 deletions examples/app-architecture/offline_first/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ dependencies:
dev_dependencies:
flutter_test:
sdk: flutter
build_runner: ^2.15.1
freezed: ^4.0.0
build_runner: ^2.16.1
freezed: ^4.0.1

flutter:
uses-material-design: true
26 changes: 13 additions & 13 deletions examples/app-architecture/optimistic_state/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ class _SubscribeButtonState extends State<SubscribeButton> {
// #docregion listener2
/// Listen to ViewModel changes.
void _onViewModelChange() {
// If the subscription action has failed
// If the subscription action has failed.
if (widget.viewModel.error) {
// Reset the error state
// Reset the error state.
widget.viewModel.error = false;
// Show an error message
// Show an error message.
ScaffoldMessenger.of(context)
.showSnackBar(const SnackBar(content: Text('Failed to subscribe')));
}
Expand All @@ -105,7 +105,7 @@ class SubscribeButtonStyle {
// #enddocregion style

// #docregion ViewModelFull
/// Subscribe button View Model.
/// Subscribe button view model.
/// Handles the subscribe action and exposes the state to the subscription.
// #docregion ViewModelStart
class SubscribeButtonViewModel extends ChangeNotifier {
Expand All @@ -115,34 +115,34 @@ class SubscribeButtonViewModel extends ChangeNotifier {
// #enddocregion ViewModelStart

// #docregion States
// Whether the user is subscribed
/// Whether the user is subscribed.
bool subscribed = false;

// Whether the subscription action has failed
/// Whether the subscription action has failed.
bool error = false;
// #enddocregion States

// #docregion subscribe
// Subscription action
Future<void> subscribe() async {
// Ignore taps when subscribed
// Ignore taps when subscribed.
if (subscribed) {
return;
}

// Optimistic state.
// It will be reverted if the subscription fails.
subscribed = true;
// Notify listeners to update the UI
// Notify listeners to update the UI.
notifyListeners();

try {
await subscriptionRepository.subscribe();
} catch (e) {
print('Failed to subscribe: $e');
// Revert to the previous state
// Revert to the previous state.
subscribed = false;
// Set the error state
// Set the error state.
error = true;
} finally {
notifyListeners();
Expand All @@ -157,9 +157,9 @@ class SubscribeButtonViewModel extends ChangeNotifier {
class SubscriptionRepository {
/// Simulates a network request and then fails.
Future<void> subscribe() async {
// Simulate a network request
await Future.delayed(const Duration(seconds: 1));
// Fail after one second
// Simulate a network request.
await Future<void>.delayed(const Duration(seconds: 1));
// Fail after one second.
throw Exception('Failed to subscribe');
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/app-architecture/result/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class ApiClientService {

class DatabaseService {
Future<Result<UserProfile>> createTemporaryUser() async {
await Future.delayed(const Duration(seconds: 2));
await Future<void>.delayed(const Duration(seconds: 2));
return Result.ok(UserProfile('John Doe', 'john@example.com'));
}
}
2 changes: 1 addition & 1 deletion examples/app-architecture/result/lib/no_result.dart
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class UserProfileViewModelNoTryCatch extends ChangeNotifier {

class DatabaseService {
Future<UserProfile> createTemporaryUser() async {
await Future.delayed(const Duration(seconds: 2));
await Future<void>.delayed(const Duration(seconds: 2));
return UserProfile('John Doe', 'john@example.com');
}
}
6 changes: 3 additions & 3 deletions examples/app-architecture/todo_data_service/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ import 'ui/todo_list/widgets/todo_list_screen.dart';
// #docregion MainTodo
void main() {
// #enddocregion MainTheme
late DatabaseService databaseService;
final DatabaseService databaseService;
if (kIsWeb) {
throw UnsupportedError('Platform not supported');
} else if (Platform.isLinux || Platform.isWindows || Platform.isMacOS) {
// Initialize FFI SQLite
// Initialize the FFI-based SQLite.
sqfliteFfiInit();
databaseService = DatabaseService(databaseFactory: databaseFactoryFfi);
} else {
// Use default native SQLite
// Use the default native SQLite.
databaseService = DatabaseService(databaseFactory: databaseFactory);
}

Expand Down
4 changes: 2 additions & 2 deletions examples/app-architecture/todo_data_service/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ dependencies:
dev_dependencies:
flutter_test:
sdk: flutter
build_runner: ^2.15.1
freezed: ^4.0.0
build_runner: ^2.16.1
freezed: ^4.0.1
json_serializable: ^6.14.1

flutter:
Expand Down
2 changes: 1 addition & 1 deletion examples/cookbook/design/cupertino_sheets/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class CupertinoSheetPage extends StatelessWidget {
child: CupertinoButton.filled(
onPressed: () {
// #docregion ShowCupertinoSheet
showCupertinoSheet(
showCupertinoSheet<void>(
context: context,
scrollableBuilder: (context, scrollController) {
return SingleChildScrollView(
Expand Down
2 changes: 1 addition & 1 deletion examples/cookbook/forms/retrieve_input/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class _MyCustomFormState extends State<MyCustomForm> {
// When the user presses the button, show an alert dialog containing
// the text that the user has entered into the text field.
onPressed: () {
showDialog(
showDialog<void>(
context: context,
builder: (context) {
return AlertDialog(
Expand Down
10 changes: 5 additions & 5 deletions examples/cookbook/forms/retrieve_input/lib/step3.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ class MyCustomForm extends StatefulWidget {
// Define a corresponding State class.
// This class holds the data related to the Form.
class _MyCustomFormState extends State<MyCustomForm> {
// Create a text controller and use it to retrieve the current value
// of the TextField.
// Create a text controller and use it to
// retrieve the current value of the TextField.
final myController = TextEditingController();

@override
Expand All @@ -35,12 +35,12 @@ class _MyCustomFormState extends State<MyCustomForm> {
// When the user presses the button, show an alert dialog containing
// the text that the user has entered into the text field.
onPressed: () {
showDialog(
showDialog<void>(
context: context,
builder: (context) {
return AlertDialog(
// Retrieve the text that the user has entered by using the
// TextEditingController.
// Retrieve the text that the user has entered by
// using the TextEditingController.
content: Text(myController.text),
);
},
Expand Down
4 changes: 2 additions & 2 deletions examples/cookbook/games/firestore_multiplayer/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ dependencies:
sdk: flutter

async: ^2.13.1
cloud_firestore: ^6.8.0
firebase_core: ^4.13.0
cloud_firestore: ^6.9.0
firebase_core: ^4.14.0
logging: ^1.3.0
provider: ^6.1.5+1

Expand Down
2 changes: 1 addition & 1 deletion examples/cookbook/images/cached_images/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ dependencies:
flutter:
sdk: flutter
cupertino_icons: ^1.0.9
cached_network_image: ^3.4.1
cached_network_image: ^4.0.0

dev_dependencies:
flutter_test:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ environment:
dependencies:
flutter:
sdk: flutter
sentry_flutter: ^9.27.0
sentry_flutter: ^9.28.0

dev_dependencies:
flutter_test:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class Photo {
required this.thumbnailUrl,
});

factory Photo.fromJson(Map<String, dynamic> json) {
factory Photo.fromJson(Map<String, Object?> json) {
return Photo(
albumId: json['albumId'] as int,
id: json['id'] as int,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class Photo {
required this.thumbnailUrl,
});

factory Photo.fromJson(Map<String, dynamic> json) {
factory Photo.fromJson(Map<String, Object?> json) {
return Photo(
albumId: json['albumId'] as int,
id: json['id'] as int,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import 'package:path_provider/path_provider.dart';
void main() {
runApp(
MaterialApp(
title: 'Reading and Writing Files',
title: 'Reading and writing files',
home: FlutterDemo(storage: CounterStorage()),
),
);
Expand All @@ -37,12 +37,12 @@ class CounterStorage {
try {
final file = await _localFile;

// Read the file
// Read the contents of the local file.
final contents = await file.readAsString();

return int.parse(contents);
} catch (e) {
// If encountering an error, return 0
} catch (_) {
// If an error was encountered, return 0.
return 0;
}
}
Expand All @@ -52,7 +52,7 @@ class CounterStorage {
Future<File> writeCounter(int counter) async {
final file = await _localFile;

// Write the file
// Write the counter as a string to the file.
return file.writeAsString('$counter');
}
// #enddocregion writeCounter
Expand Down Expand Up @@ -92,7 +92,7 @@ class _FlutterDemoState extends State<FlutterDemo> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Reading and Writing Files')),
appBar: AppBar(title: const Text('Reading and writing files')),
body: Center(
child: Text('Button tapped $_counter time${_counter == 1 ? '' : 's'}.'),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'package:flutter/material.dart';
import 'package:google_mobile_ads/google_mobile_ads.dart';

// #docregion main
void main() async {
void main() {
WidgetsFlutterBinding.ensureInitialized();
unawaited(MobileAds.instance.initialize());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ dependencies:
sdk: flutter

dev_dependencies:
test: ^1.31.0
test: ^1.31.1

flutter:
uses-material-design: true
2 changes: 1 addition & 1 deletion examples/cookbook/testing/unit/counter_app/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ dependencies:
flutter:
sdk: flutter
cupertino_icons: ^1.0.9
test: ^1.31.0
test: ^1.31.1

flutter:
uses-material-design: true
2 changes: 1 addition & 1 deletion examples/cookbook/testing/unit/mocking/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ dev_dependencies:
flutter_test:
sdk: flutter
mockito: ^5.8.1
build_runner: ^2.15.1
build_runner: ^2.16.1

flutter:
uses-material-design: true
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ environment:
dependencies:
flutter:
sdk: flutter
path_provider: ^2.1.5
path_provider: ^2.1.6
path: ^1.9.1
flutter_test:
sdk: flutter
Expand Down
2 changes: 1 addition & 1 deletion examples/data-and-backend/json/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ dependencies:
json_annotation: ^4.12.0

dev_dependencies:
build_runner: ^2.15.1
build_runner: ^2.16.1
json_serializable: ^6.14.1

This file was deleted.

2 changes: 1 addition & 1 deletion examples/get-started/flutter-for/ios_devs/lib/form.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class _MyFormState extends State<MyForm> {
// When the user presses the button, show an alert dialog with the
// text the user has typed into our text field.
onPressed: () {
showDialog(
showDialog<void>(
context: context,
builder: (context) {
return AlertDialog(
Expand Down
Loading
Loading