Skip to content

Commit

Permalink
Improve code documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
TechAurelian committed Oct 29, 2024
1 parent d3330a2 commit 503763c
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 11 deletions.
2 changes: 2 additions & 0 deletions lib/common/app_settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@

import 'package:shared_preferences/shared_preferences.dart';

/// Persistent app settings.
class AppSettings {
bool _counterTapMode = false;

/// The setting for whether counters are incremented by tapping the screen.
bool get counterTapMode => _counterTapMode;

set counterTapMode(bool value) {
Expand Down
7 changes: 5 additions & 2 deletions lib/common/urls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
// Url constants used throughout the app.
library;

const String feedbackURL = 'https://hellogramming.com/weekdaycounters/feedback/';

/// The app's home page URL.
const String aboutURL = 'https://hellogramming.com/weekdaycounters/';

/// The URL to the source code repository of the app.
const String viewSourceURL = 'https://github.com/Hellogramming/weekday_counters';

/// The URL for sending feedback.
const String feedbackURL = 'https://hellogramming.com/weekdaycounters/feedback/';
8 changes: 4 additions & 4 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import 'common/strings.dart' as strings;
import 'screens/home_screen.dart';

void main() {
runApp(const CountersApp());
runApp(const WeekdayCountersApp());
}

/// The app widget.
class CountersApp extends StatelessWidget {
const CountersApp({super.key});
/// The main app widget for the Weekday Counters app.
class WeekdayCountersApp extends StatelessWidget {
const WeekdayCountersApp({super.key});

@override
Widget build(BuildContext context) {
Expand Down
5 changes: 4 additions & 1 deletion lib/screens/settings_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ import 'package:flutter/material.dart';
import '../common/app_settings.dart';
import '../common/strings.dart' as strings;

/// The app settings screen.
class SettingsScreen extends StatefulWidget {
const SettingsScreen({
super.key,
required this.appSettings,
});

/// The app settings that can be changed in this screen.
final AppSettings appSettings;

@override
Expand All @@ -28,7 +30,8 @@ class _SettingsScreenState extends State<SettingsScreen> {
title: const Text(strings.settingsTitle),
),
body: ListView(
children: [
children: <Widget>[
// Add the counter tap mode switch list tile
SwitchListTile(
activeColor: Colors.black,
value: widget.appSettings.counterTapMode,
Expand Down
7 changes: 5 additions & 2 deletions lib/utils/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ Future<void> launchUrlExternal(String url) async {
/// Utility Color extension methods.
extension ColorX on Color {
/// Returns the contrast color for this color.
Color contrastOf() =>
ThemeData.estimateBrightnessForColor(this) == Brightness.light ? Colors.black : Colors.white;
Color contrastOf() {
return ThemeData.estimateBrightnessForColor(this) == Brightness.light
? Colors.black
: Colors.white;
}
}
8 changes: 7 additions & 1 deletion lib/widgets/counters_drawer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ class CountersDrawer extends StatelessWidget {
/// Called when the user taps a drawer list tile.
final void Function(DrawerExtraActions value)? onExtraSelected;

/// Handles the tap event on an extra action.
void _onExtraActionTap(BuildContext context, DrawerExtraActions action) {
Navigator.pop(context);
Navigator.pop(context); // Close the drawer
onExtraSelected?.call(action);
}

Expand All @@ -45,7 +46,10 @@ class CountersDrawer extends StatelessWidget {
child: ListView(
children: <Widget>[
_buildDrawerHeader(context, counters.current.color),

// Add a list tile for each counter type
...CounterType.values.map((type) => _buildCounterListTile(context, type)),

const Divider(),
ListTile(
leading: const Icon(Icons.settings),
Expand Down Expand Up @@ -74,6 +78,7 @@ class CountersDrawer extends StatelessWidget {
);
}

/// Builds the drawer header.
Widget _buildDrawerHeader(BuildContext context, Color color) {
return DrawerHeader(
child: Center(
Expand All @@ -85,6 +90,7 @@ class CountersDrawer extends StatelessWidget {
);
}

/// Builds a list tile for the counter of the specified type.
Widget _buildCounterListTile(BuildContext context, CounterType counterType) {
return ColorListTile(
color: Counter.colorOf(counterType),
Expand Down
2 changes: 1 addition & 1 deletion test/widget_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import 'package:weekday_counters/main.dart';
void main() {
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
// Build our app and trigger a frame.
await tester.pumpWidget(const CountersApp());
await tester.pumpWidget(const WeekdayCountersApp());

// Verify that our counter starts at 0.
expect(find.text('0'), findsOneWidget);
Expand Down

0 comments on commit 503763c

Please sign in to comment.