Skip to content

Commit

Permalink
chore: use const
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Czizikow committed Apr 14, 2020
1 parent df64160 commit 65a3eb1
Show file tree
Hide file tree
Showing 15 changed files with 91 additions and 81 deletions.
8 changes: 4 additions & 4 deletions lib/screens/currencies_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import '../utils/currencies.dart';
class CurrenciesScreen extends StatelessWidget {
final List<Currency> currencies;

CurrenciesScreen(this.currencies);
const CurrenciesScreen(this.currencies, {Key key}) : super(key: key);

Widget _renderItem(BuildContext context, int i) {
final currency = currencies[i];
Expand All @@ -25,7 +25,7 @@ class CurrenciesScreen extends StatelessWidget {
title: Text(currency.name),
onTap: () => Navigator.of(context).pop({'code': currency.code}),
),
Divider(height: 1),
const Divider(height: 1),
],
);
}
Expand All @@ -36,7 +36,7 @@ class CurrenciesScreen extends StatelessWidget {
appBar: PlatformAppBar(
trailingActions: <Widget>[
IconButton(
icon: Icon(Icons.search),
icon: const Icon(Icons.search),
onPressed: () async {
Currency result = await showSearch<Currency>(
context: context,
Expand Down Expand Up @@ -96,7 +96,7 @@ class CurrenciesSearchDelegate extends SearchDelegate<Currency> {
List<Widget> buildActions(BuildContext context) {
return [
IconButton(
icon: Icon(Icons.clear),
icon: const Icon(Icons.clear),
onPressed: () {
query = '';
},
Expand Down
6 changes: 3 additions & 3 deletions lib/screens/edit_email.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
import 'package:provider/provider.dart';
import 'package:flutter/material.dart';
import 'package:flutter_platform_widgets/flutter_platform_widgets.dart';
import 'package:provider/provider.dart';

import '../services/api.dart';
import '../providers/account.dart';
import '../services/api.dart';

class EditEmailScreen extends StatefulWidget {
static const routeName = '/edit-email';
Expand Down
6 changes: 3 additions & 3 deletions lib/screens/edit_name.dart
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class _EditNameState extends State<EditNameScreen> {
Widget build(BuildContext context) {
return PlatformScaffold(
appBar: PlatformAppBar(
title: Text('Edit Name'),
title: const Text('Edit Name'),
trailingActions: <Widget>[
PlatformIconButton(
iosIcon: Icon(CupertinoIcons.check_mark),
Expand All @@ -116,7 +116,7 @@ class _EditNameState extends State<EditNameScreen> {
controller: _firstNameController,
textInputAction: TextInputAction.next,
android: (_) => MaterialTextFieldData(
decoration: InputDecoration(
decoration: const InputDecoration(
labelText: 'First name',
),
),
Expand All @@ -131,7 +131,7 @@ class _EditNameState extends State<EditNameScreen> {
controller: _lastNameController,
focusNode: _lastNameFocusNode,
android: (_) => MaterialTextFieldData(
decoration: InputDecoration(
decoration: const InputDecoration(
labelText: 'Last name',
),
),
Expand Down
14 changes: 5 additions & 9 deletions lib/screens/forgot_password.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class _ForgotPasswordState extends State<ForgotPasswordScreen> {
content: Text(message),
actions: <Widget>[
PlatformDialogAction(
child: Text('OK'),
child: const Text('OK'),
onPressed: () => Navigator.of(context, rootNavigator: true).pop(),
)
],
Expand Down Expand Up @@ -59,7 +59,7 @@ class _ForgotPasswordState extends State<ForgotPasswordScreen> {
Widget build(BuildContext context) {
return PlatformScaffold(
appBar: PlatformAppBar(
title: Text('Reset password'),
title: const Text('Reset password'),
),
body: SafeArea(
child: SingleChildScrollView(
Expand All @@ -70,17 +70,15 @@ class _ForgotPasswordState extends State<ForgotPasswordScreen> {
Text(
'Enter the email address and we’ll send you instructions to reset your password.',
),
SizedBox(
height: 16,
),
const SizedBox(height: 16),
PlatformTextField(
autofocus: true,
autocorrect: false,
controller: _emailController,
keyboardType: TextInputType.emailAddress,
textInputAction: TextInputAction.send,
android: (_) => MaterialTextFieldData(
decoration: InputDecoration(
decoration: const InputDecoration(
labelText: 'Email',
),
),
Expand All @@ -89,9 +87,7 @@ class _ForgotPasswordState extends State<ForgotPasswordScreen> {
),
onEditingComplete: _resetPassword,
),
SizedBox(
height: 16,
),
const SizedBox(height: 16),
PlatformButton(
color: Theme.of(context).primaryColor,
android: (_) => MaterialRaisedButtonData(
Expand Down
49 changes: 25 additions & 24 deletions lib/screens/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,25 @@ class _HomeScreenState extends State<HomeScreen> {
}

class _AndroidHome extends StatelessWidget {
final _tabs = <Widget>[
Tab(
child: Align(
alignment: Alignment.center,
child: const Text('Balance'),
),
),
Tab(
child: Align(
alignment: Alignment.center,
child: const Text('Expenses'),
),
),
];
final _tabsViews = [
BalanceList(),
ExpensesList(),
];

@override
Widget build(BuildContext context) {
final ThemeData theme = Theme.of(context);
Expand Down Expand Up @@ -125,32 +144,14 @@ class _AndroidHome extends StatelessWidget {
indicator: TabBarIndicator(
color: theme.primaryColorLight.withOpacity(0.3),
),
tabs: <Widget>[
Tab(
child: Align(
alignment: Alignment.center,
child: Text('Balance'),
),
),
Tab(
child: Align(
alignment: Alignment.center,
child: Text('Expenses'),
),
),
],
tabs: _tabs,
),
),
body: TabBarView(
children: <Widget>[
BalanceList(),
ExpensesList(),
],
),
drawer: AppDrawer(),
body: TabBarView(children: _tabsViews),
drawer: const AppDrawer(),
floatingActionButton: SpeedDial(
tooltip: 'Add Expense or Payment',
child: Icon(Icons.add),
child: const Icon(Icons.add),
visible: true,
curve: Curves.decelerate,
overlayOpacity: theme.brightness == Brightness.dark ? 0.54 : 0.8,
Expand All @@ -160,15 +161,15 @@ class _AndroidHome extends StatelessWidget {
SpeedDialChild(
child: const Icon(Icons.shopping_basket),
onTap: () {},
labelWidget: SpeedDialLabel(
labelWidget: const SpeedDialLabel(
title: 'New Expense',
subTitle: 'A purchase made for the group',
),
),
SpeedDialChild(
child: const Icon(Icons.account_balance_wallet),
onTap: () => {},
labelWidget: SpeedDialLabel(
labelWidget: const SpeedDialLabel(
title: 'New Payment',
subTitle: 'Record a payment made in the group',
),
Expand Down
10 changes: 5 additions & 5 deletions lib/screens/login.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class _LoginScreenState extends State<LoginScreen> {
Widget build(BuildContext context) {
return PlatformScaffold(
appBar: PlatformAppBar(
title: Text('Login'),
title: const Text('Login'),
),
body: SafeArea(
child: SingleChildScrollView(
Expand All @@ -96,7 +96,7 @@ class _LoginScreenState extends State<LoginScreen> {
keyboardType: TextInputType.emailAddress,
textInputAction: TextInputAction.next,
android: (_) => MaterialTextFieldData(
decoration: InputDecoration(
decoration: const InputDecoration(
labelText: 'Email',
),
),
Expand All @@ -113,7 +113,7 @@ class _LoginScreenState extends State<LoginScreen> {
controller: _passwordController,
textInputAction: TextInputAction.go,
android: (_) => MaterialTextFieldData(
decoration: InputDecoration(
decoration: const InputDecoration(
labelText: 'Password',
),
),
Expand All @@ -123,7 +123,7 @@ class _LoginScreenState extends State<LoginScreen> {
focusNode: _passwordFocusNode,
onSubmitted: (_) => _handleSubmit(),
),
SizedBox(height: 16),
const SizedBox(height: 16),
Selector<Auth, bool>(
selector: (_, auth) => auth.isFetching,
builder: (_, isFetching, __) => PlatformButton(
Expand All @@ -137,7 +137,7 @@ class _LoginScreenState extends State<LoginScreen> {
),
PlatformButton(
androidFlat: (_) => MaterialFlatButtonData(),
child: Text('Forgot password?'),
child: const Text('Forgot password?'),
onPressed: _forgotPassword,
),
],
Expand Down
4 changes: 4 additions & 0 deletions lib/screens/offline.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ class OfflineScreen extends StatelessWidget {
selector: (_, groups) =>
Tuple2(groups.status, groups.fetchGroups),
builder: (_, data, __) => PlatformButton(
color: Theme.of(context).primaryColor,
android: (_) => MaterialRaisedButtonData(
colorBrightness: Brightness.dark,
),
child: Text('Try again'),
onPressed:
data.item1 == Status.PENDING ? null : data.item2,
Expand Down
12 changes: 6 additions & 6 deletions lib/screens/register.dart
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class _RegisterScreenState extends State<RegisterScreen> {
Widget build(BuildContext context) {
return PlatformScaffold(
appBar: PlatformAppBar(
title: Text('Sign up'),
title: const Text('Sign up'),
),
body: SafeArea(
child: SingleChildScrollView(
Expand All @@ -105,7 +105,7 @@ class _RegisterScreenState extends State<RegisterScreen> {
keyboardType: TextInputType.text,
textInputAction: TextInputAction.next,
android: (_) => MaterialTextFieldData(
decoration: InputDecoration(
decoration: const InputDecoration(
labelText: 'First name',
),
),
Expand All @@ -121,7 +121,7 @@ class _RegisterScreenState extends State<RegisterScreen> {
keyboardType: TextInputType.text,
textInputAction: TextInputAction.next,
android: (_) => MaterialTextFieldData(
decoration: InputDecoration(
decoration: const InputDecoration(
labelText: 'Last name',
),
),
Expand All @@ -138,7 +138,7 @@ class _RegisterScreenState extends State<RegisterScreen> {
keyboardType: TextInputType.emailAddress,
textInputAction: TextInputAction.next,
android: (_) => MaterialTextFieldData(
decoration: InputDecoration(
decoration: const InputDecoration(
labelText: 'Email',
),
),
Expand All @@ -155,7 +155,7 @@ class _RegisterScreenState extends State<RegisterScreen> {
focusNode: _passwordFocusNode,
textInputAction: TextInputAction.go,
android: (_) => MaterialTextFieldData(
decoration: InputDecoration(
decoration: const InputDecoration(
labelText: 'Password',
),
),
Expand All @@ -164,7 +164,7 @@ class _RegisterScreenState extends State<RegisterScreen> {
),
onSubmitted: (_) => _handleSubmit(),
),
SizedBox(height: 16),
const SizedBox(height: 16),
Selector<Auth, bool>(
selector: (_, auth) => auth.isFetching,
builder: (_, isFetching, __) => PlatformButton(
Expand Down
15 changes: 3 additions & 12 deletions lib/screens/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import '../providers/auth.dart';
import '../providers/account.dart';
import '../providers/groups.dart';
import '../widgets/avatar.dart';
import '../widgets/loading_dialog.dart';
import '../utils/constants.dart';

enum MoreMenuOptions {
Expand Down Expand Up @@ -224,6 +225,7 @@ class _SettingsScreenState extends State<SettingsScreen> {
PlatformDialogAction(
onPressed: () => Navigator.of(context).pop(true),
child: Text('Delete'),
ios: (_) => CupertinoDialogActionData(isDestructiveAction: true),
),
],
),
Expand All @@ -233,18 +235,7 @@ class _SettingsScreenState extends State<SettingsScreen> {
showPlatformDialog(
androidBarrierDismissible: false,
context: context,
builder: (_) => PlatformAlertDialog(
content: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
PlatformCircularProgressIndicator(),
SizedBox(height: 12),
Text('Loading...'),
],
),
),
builder: (_) => LoadingDialog(),
);
try {
await Provider.of<AccountProvider>(context, listen: false)
Expand Down
7 changes: 5 additions & 2 deletions lib/utils/currencies.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import 'package:flutter/foundation.dart';

@immutable
class Currency {
final String name;
final String symbol;
final String code;
Currency({this.name, this.symbol, this.code});
const Currency({this.name, this.symbol, this.code});

factory Currency.fromMap(Map<String, String> map) => Currency(
name: map['name'],
Expand All @@ -11,7 +14,7 @@ class Currency {
);
}

final Map<String, Map<String, String>> currencies = {
const Map<String, Map<String, String>> currencies = const {
"AED": {"name": "Emirati Dirham", "code": "AED", "symbol": ".د.ب"},
"AFN": {"name": "Afghan Afghani", "code": "AFN", "symbol": "؋"},
"ALL": {"name": "Albanian lek", "code": "ALL", "symbol": "lek"},
Expand Down
2 changes: 2 additions & 0 deletions lib/widgets/app_drawer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import '../screens/group.dart';
import '../screens/settings.dart';

class AppDrawer extends StatefulWidget {
const AppDrawer({Key key}) : super(key: key);

@override
_AppDrawerState createState() => _AppDrawerState();
}
Expand Down
2 changes: 2 additions & 0 deletions lib/widgets/empty_expenses.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class EmptyExpenses extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
CircleAvatar(
Expand All @@ -20,6 +21,7 @@ class EmptyExpenses extends StatelessWidget {
Text(
'No expenses',
style: Theme.of(context).textTheme.body2.copyWith(fontSize: 18),
textAlign: TextAlign.center,
),
const SizedBox(height: 4),
SizedBox(
Expand Down
Loading

0 comments on commit 65a3eb1

Please sign in to comment.