Enable prefer_const_constructors

This commit is contained in:
Vishesh Handa
2019-10-20 01:11:01 +01:00
parent 5d69dd9de2
commit ffc0af12a3
21 changed files with 97 additions and 99 deletions

View File

@ -82,8 +82,8 @@ linter:
# - parameter_assignments # we do this commonly
- prefer_adjacent_string_concatenation
- prefer_collection_literals
# - prefer_conditional_assignment # not yet tested
# - prefer_const_constructors
- prefer_conditional_assignment
- prefer_const_constructors
# - prefer_constructors_over_static_methods # not yet tested
- prefer_contains
- prefer_equal_for_default_values
@ -107,7 +107,7 @@ linter:
- unnecessary_brace_in_string_interps
# - unnecessary_const
- unnecessary_getters_setters
# - unnecessary_lambdas # https://github.com/dart-lang/linter/issues/498
- unnecessary_lambdas
- unnecessary_new
- unnecessary_null_aware_assignments
- unnecessary_null_in_if_null_operators

View File

@ -113,7 +113,7 @@ class JournalApp extends StatelessWidget {
}
return MaterialApp(
key: ValueKey("App"),
key: const ValueKey("App"),
title: 'GitJournal',
theme: themeData,
navigatorObservers: <NavigatorObserver>[JournalApp.observer],

View File

@ -15,7 +15,7 @@ class GitApp extends StatelessWidget {
home: Scaffold(
key: _scaffoldKey,
appBar: AppBar(
title: Text('Git Test'),
title: const Text('Git Test'),
),
body: Column(
children: _buildGitButtons(),
@ -48,12 +48,12 @@ class GitApp extends StatelessWidget {
return <Widget>[
RaisedButton(
child: Text("Generate Keys"),
child: const Text("Generate Keys"),
onPressed: () {
generateSSHKeys(comment: "Git Sample App");
}),
RaisedButton(
child: Text("Git Clone"),
child: const Text("Git Clone"),
onPressed: () async {
try {
await GitRepo.clone(basePath, cloneUrl);
@ -65,25 +65,25 @@ class GitApp extends StatelessWidget {
},
),
RaisedButton(
child: Text("Git Pull"),
child: const Text("Git Pull"),
onPressed: () async {
gitRepo.pull();
},
),
RaisedButton(
child: Text("Git Add"),
child: const Text("Git Add"),
onPressed: () async {
gitRepo.add(".");
},
),
RaisedButton(
child: Text("Git Push"),
child: const Text("Git Push"),
onPressed: () async {
gitRepo.push();
},
),
RaisedButton(
child: Text("Git Commit"),
child: const Text("Git Commit"),
onPressed: () async {
gitRepo.commit(
message: "Default message from GitJournal",
@ -92,13 +92,13 @@ class GitApp extends StatelessWidget {
},
),
RaisedButton(
child: Text("Git Reset Last"),
child: const Text("Git Reset Last"),
onPressed: () async {
gitRepo.resetLast();
},
),
RaisedButton(
child: Text("Git Migrate"),
child: const Text("Git Migrate"),
onPressed: () async {
var baseGitPath = await getGitBaseDirectory();
await migrateGitRepo(

View File

@ -72,9 +72,7 @@ class Note implements Comparable<Note> {
}
}
if (_created == null) {
_created = DateTime(0, 0, 0, 0, 0, 0, 0, 0);
}
_created ??= DateTime(0, 0, 0, 0, 0, 0, 0, 0);
}
bool hasValidDate() {

View File

@ -35,17 +35,17 @@ class OAuthAppState extends State<OAuthApp> {
title: 'OAuth App',
home: Scaffold(
appBar: AppBar(
title: Text('OAuth Test'),
title: const Text('OAuth Test'),
),
body: Column(children: <Widget>[
RaisedButton(
child: Text("Open OAuth URL"),
child: const Text("Open OAuth URL"),
onPressed: () {
githost.launchOAuthScreen();
},
),
RaisedButton(
child: Text("List Repos"),
child: const Text("List Repos"),
onPressed: () async {
try {
var repos = await githost.listRepos();
@ -58,7 +58,7 @@ class OAuthAppState extends State<OAuthApp> {
},
),
RaisedButton(
child: Text("Create Repo"),
child: const Text("Create Repo"),
onPressed: () async {
try {
var repo = await githost.createRepo("journal_test2");
@ -69,7 +69,7 @@ class OAuthAppState extends State<OAuthApp> {
},
),
RaisedButton(
child: Text("Add Deploy Key"),
child: const Text("Add Deploy Key"),
onPressed: () async {
try {
await githost.addDeployKey(key, "vhanda/journal_test2");

View File

@ -140,24 +140,24 @@ class GitHostSetupAutoConfigureState extends State<GitHostSetupAutoConfigure> {
'We need permission to perform the following steps:',
style: Theme.of(context).textTheme.title,
),
SizedBox(height: 32.0),
const SizedBox(height: 32.0),
// Step 1
Text(
"1. Create a new private repo called 'journal' or use the existing one",
style: Theme.of(context).textTheme.body2,
),
SizedBox(height: 8.0),
const SizedBox(height: 8.0),
Text(
"2. Generate an SSH Key on this device",
style: Theme.of(context).textTheme.body2,
),
SizedBox(height: 8.0),
const SizedBox(height: 8.0),
Text(
"3. Add the key as a deploy key with write access to the created repo",
style: Theme.of(context).textTheme.body2,
),
SizedBox(height: 32.0),
const SizedBox(height: 32.0),
GitHostSetupButton(
text: "Authorize GitJournal",

View File

@ -83,12 +83,12 @@ class GitCloneUrlPageState extends State<GitCloneUrlPage> {
style: Theme.of(context).textTheme.headline,
),
),
SizedBox(height: 16.0),
const SizedBox(height: 16.0),
Padding(
padding: const EdgeInsets.all(8.0),
child: inputForm,
),
SizedBox(height: 8.0),
const SizedBox(height: 8.0),
GitHostSetupButton(
text: "Next",
onPressed: formSubmitted,
@ -178,28 +178,28 @@ class GitCloneUrlKnownProviderPageState
'Please create a new git repository -',
style: Theme.of(context).textTheme.title,
),
SizedBox(height: 32.0),
const SizedBox(height: 32.0),
// Step 1
Text(
'1. Go to the website, create a repo and copy its git clone URL',
style: Theme.of(context).textTheme.subtitle,
),
SizedBox(height: 8.0),
const SizedBox(height: 8.0),
GitHostSetupButton(
text: "Open Create New Repo Webpage",
onPressed: widget.launchCreateUrlPage,
),
SizedBox(height: 16.0),
const SizedBox(height: 16.0),
// Step 2
Text(
'2. Enter the Git clone URL',
style: Theme.of(context).textTheme.subtitle,
),
SizedBox(height: 8.0),
const SizedBox(height: 8.0),
inputForm,
SizedBox(height: 16.0),
const SizedBox(height: 16.0),
GitHostSetupButton(
text: "Next",
onPressed: formSubmitted,

View File

@ -24,12 +24,12 @@ class GitHostSetupFolderPage extends StatelessWidget {
'Would you like to store your journal entries in an existing folder?',
style: Theme.of(context).textTheme.title,
),
SizedBox(height: 32.0),
const SizedBox(height: 32.0),
FolderListWidget(
folders: folders,
onSelected: subFolderSelected,
),
SizedBox(height: 16.0),
const SizedBox(height: 16.0),
GitHostSetupButton(
text: "Ignore",
onPressed: rootFolderSelected,

View File

@ -15,9 +15,9 @@ class GitHostSetupLoadingPage extends StatelessWidget {
style: Theme.of(context).textTheme.display1,
),
),
SizedBox(height: 8.0),
Padding(
padding: const EdgeInsets.all(8.0),
const SizedBox(height: 8.0),
const Padding(
padding: EdgeInsets.all(8.0),
child: CircularProgressIndicator(
value: null,
),

View File

@ -281,7 +281,7 @@ class GitHostSetupScreenState extends State<GitHostSetupScreen> {
),
],
),
padding: EdgeInsets.all(16.0),
padding: const EdgeInsets.all(16.0),
);
var scaffold = Scaffold(
@ -292,7 +292,7 @@ class GitHostSetupScreenState extends State<GitHostSetupScreen> {
InkWell(
child: Container(
child: Icon(Icons.arrow_back, size: 32.0),
padding: EdgeInsets.all(8.0),
padding: const EdgeInsets.all(8.0),
),
onTap: () => Navigator.of(context).pop(),
),
@ -505,7 +505,7 @@ class GitHostChoicePage extends StatelessWidget {
"Select a Git Hosting Provider -",
style: Theme.of(context).textTheme.headline,
),
SizedBox(height: 16.0),
const SizedBox(height: 16.0),
GitHostSetupButton(
text: "GitHub",
iconUrl: 'assets/icon/github-icon.png',
@ -513,7 +513,7 @@ class GitHostChoicePage extends StatelessWidget {
onKnownGitHost(GitHostType.GitHub);
},
),
SizedBox(height: 8.0),
const SizedBox(height: 8.0),
GitHostSetupButton(
text: "GitLab",
iconUrl: 'assets/icon/gitlab-icon.png',
@ -521,7 +521,7 @@ class GitHostChoicePage extends StatelessWidget {
onKnownGitHost(GitHostType.GitLab);
},
),
SizedBox(height: 8.0),
const SizedBox(height: 8.0),
GitHostSetupButton(
text: "Custom",
onPressed: () async {
@ -555,14 +555,14 @@ class GitHostAutoConfigureChoicePage extends StatelessWidget {
"How do you want to do this?",
style: Theme.of(context).textTheme.headline,
),
SizedBox(height: 16.0),
const SizedBox(height: 16.0),
GitHostSetupButton(
text: "Setup Automatically",
onPressed: () {
onDone(GitHostSetupType.Auto);
},
),
SizedBox(height: 8.0),
const SizedBox(height: 8.0),
GitHostSetupButton(
text: "Let me do it manually",
onPressed: () async {

View File

@ -32,40 +32,40 @@ class GitHostSetupSshKeyKnownProvider extends StatelessWidget {
'In order to access this repository, this public key must be copied as a deploy key',
style: Theme.of(context).textTheme.title,
),
SizedBox(height: 32.0),
const SizedBox(height: 32.0),
// Step 1
Text(
'1. Copy the key',
style: Theme.of(context).textTheme.subtitle,
),
SizedBox(height: 8.0),
const SizedBox(height: 8.0),
PublicKeyWidget(publicKey),
SizedBox(height: 8.0),
const SizedBox(height: 8.0),
GitHostSetupButton(
text: "Copy Key",
onPressed: () => copyKeyFunction(context),
),
SizedBox(height: 16.0),
const SizedBox(height: 16.0),
// Step 2
Text(
'2. Open webpage, and paste the deploy key. Make sure it is given Write Access. ',
style: Theme.of(context).textTheme.subtitle,
),
SizedBox(height: 8.0),
const SizedBox(height: 8.0),
GitHostSetupButton(
text: "Open Deploy Key Webpage",
onPressed: openDeployKeyPage,
),
SizedBox(height: 16.0),
const SizedBox(height: 16.0),
// Step 3
Text(
'3. Try Cloning ..',
style: Theme.of(context).textTheme.subtitle,
),
SizedBox(height: 8.0),
const SizedBox(height: 8.0),
GitHostSetupButton(
text: "Clone Repo",
onPressed: doneFunction,
@ -106,35 +106,35 @@ class GitHostSetupSshKeyUnknownProvider extends StatelessWidget {
'In order to access this repository, this public key must be copied as a deploy key',
style: Theme.of(context).textTheme.title,
),
SizedBox(height: 32.0),
const SizedBox(height: 32.0),
// Step 1
Text(
'1. Copy the key',
style: Theme.of(context).textTheme.subtitle,
),
SizedBox(height: 8.0),
const SizedBox(height: 8.0),
PublicKeyWidget(publicKey),
SizedBox(height: 8.0),
const SizedBox(height: 8.0),
GitHostSetupButton(
text: "Copy Key",
onPressed: () => copyKeyFunction(context),
),
SizedBox(height: 16.0),
const SizedBox(height: 16.0),
// Step 2
Text(
'2. Give this SSH Key access to the git repo. (You need to figure it out yourself)',
style: Theme.of(context).textTheme.subtitle,
),
SizedBox(height: 16.0),
const SizedBox(height: 16.0),
// Step 3
Text(
'3. Try Cloning ..',
style: Theme.of(context).textTheme.subtitle,
),
SizedBox(height: 8.0),
const SizedBox(height: 8.0),
GitHostSetupButton(
text: "Clone Repo",
onPressed: doneFunction,

View File

@ -18,7 +18,7 @@ class HomeScreen extends StatelessWidget {
final appState = container.appState;
var createButton = FloatingActionButton(
key: ValueKey("FAB"),
key: const ValueKey("FAB"),
onPressed: () => _newPost(context),
child: Icon(Icons.add),
);
@ -40,7 +40,7 @@ class HomeScreen extends StatelessWidget {
bool shouldShowBadge =
!appState.remoteGitRepoConfigured && appState.hasJournalEntries;
var appBarMenuButton = BadgeIconButton(
key: ValueKey("DrawerButton"),
key: const ValueKey("DrawerButton"),
icon: const Icon(Icons.menu),
itemCount: shouldShowBadge ? 1 : 0,
onPressed: () {
@ -51,7 +51,7 @@ class HomeScreen extends StatelessWidget {
return Scaffold(
key: _scaffoldKey,
appBar: AppBar(
title: Text('GitJournal'),
title: const Text('GitJournal'),
leading: appBarMenuButton,
actions: <Widget>[
IconButton(

View File

@ -60,7 +60,7 @@ class NoteEditorState extends State<NoteEditor> {
appBar: AppBar(
title: Text(title),
leading: IconButton(
key: ValueKey("NewEntry"),
key: const ValueKey("NewEntry"),
icon: Icon(Icons.check),
onPressed: () {
_saveNote(context);
@ -102,7 +102,7 @@ class NoteEditorState extends State<NoteEditor> {
),
PopupMenuItem<NoteEditorDropDownChoices>(
value: NoteEditorDropDownChoices.SwitchEditor,
child: rawEditor ? Text('Rich Editor') : Text('Raw Editor'),
child: rawEditor ? const Text('Rich Editor') : const Text('Raw Editor'),
),
],
),

View File

@ -49,7 +49,7 @@ class NoteBrowsingScreenState extends State<NoteBrowsingScreen> {
return Scaffold(
appBar: AppBar(
title: Text('TIMELINE'),
title: const Text('TIMELINE'),
actions: <Widget>[
IconButton(
icon: Icon(Icons.delete),
@ -106,14 +106,14 @@ class NoteBrowsingScreenState extends State<NoteBrowsingScreen> {
actions: <Widget>[
FlatButton(
onPressed: () => Navigator.pop(context),
child: Text('Cancel'),
child: const Text('Cancel'),
),
FlatButton(
onPressed: () {
Navigator.pop(context); // Alert box
_deleteNote(context);
},
child: Text('Delete'),
child: const Text('Delete'),
),
],
);
@ -142,7 +142,7 @@ class NoteViewer extends StatelessWidget {
data: note.body,
styleSheet: MarkdownStyleSheet.fromTheme(theme),
),
SizedBox(height: 64.0),
const SizedBox(height: 64.0),
// _buildFooter(context),
],
crossAxisAlignment: CrossAxisAlignment.start,

View File

@ -42,7 +42,7 @@ class OnBoardingScreenState extends State<OnBoardingScreen> {
var row = Row(
children: <Widget>[
OnBoardingBottomButton(
key: ValueKey("Skip"),
key: const ValueKey("Skip"),
text: "Skip",
onPressed: _finish,
),
@ -61,7 +61,7 @@ class OnBoardingScreenState extends State<OnBoardingScreen> {
),
),
OnBoardingBottomButton(
key: ValueKey("Next"),
key: const ValueKey("Next"),
text: "Next",
onPressed: _nextPage,
),
@ -81,7 +81,7 @@ class OnBoardingScreenState extends State<OnBoardingScreen> {
width: double.infinity,
height: _bottomBarHeight,
child: RaisedButton(
key: ValueKey("GetStarted"),
key: const ValueKey("GetStarted"),
child: Text(
"Get Started",
textAlign: TextAlign.center,
@ -98,7 +98,7 @@ class OnBoardingScreenState extends State<OnBoardingScreen> {
width: double.infinity,
height: double.infinity,
child: pageView,
padding: EdgeInsets.all(16.0),
padding: const EdgeInsets.all(16.0),
),
bottomNavigationBar: AnimatedSwitcher(
duration: Duration(milliseconds: 300),
@ -161,7 +161,7 @@ class OnBoardingPage1 extends StatelessWidget {
height: 200,
fit: BoxFit.fill,
),
SizedBox(height: 16.0),
const SizedBox(height: 16.0),
Text(
"GitJournal",
style: headerTextStyle,
@ -173,7 +173,7 @@ class OnBoardingPage1 extends StatelessWidget {
child: Column(
children: <Widget>[
Center(child: header),
SizedBox(height: 64.0),
const SizedBox(height: 64.0),
AutoSizeText(
"A Journaling App focused on\nOpenness and Data Privacy",
style: textTheme.headline,
@ -201,7 +201,7 @@ class OnBoardingPage2 extends StatelessWidget {
//height: 200,
fit: BoxFit.fill,
),
SizedBox(height: 16.0),
const SizedBox(height: 16.0),
],
);
@ -209,7 +209,7 @@ class OnBoardingPage2 extends StatelessWidget {
child: Column(
children: <Widget>[
Center(child: header),
SizedBox(height: 64.0),
const SizedBox(height: 64.0),
AutoSizeText(
"Your Journal Entries are stored in a\nstandard Markdown + YAML\nHeader format",
style: textTheme.headline,
@ -237,7 +237,7 @@ class OnBoardingPage3 extends StatelessWidget {
//height: 200,
fit: BoxFit.fill,
),
SizedBox(height: 16.0),
const SizedBox(height: 16.0),
],
);
@ -245,7 +245,7 @@ class OnBoardingPage3 extends StatelessWidget {
child: Column(
children: <Widget>[
Center(child: header),
SizedBox(height: 64.0),
const SizedBox(height: 64.0),
AutoSizeText(
"Sync your Local Git Repo\nwith any provider",
style: textTheme.headline,

View File

@ -9,7 +9,7 @@ class SettingsScreen extends StatelessWidget {
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Settings'),
title: const Text('Settings'),
leading: IconButton(
icon: Icon(Icons.arrow_back),
onPressed: () {
@ -124,7 +124,7 @@ class SettingsListState extends State<SettingsList> {
},
),
ListTile(
title: Text("Font Size"),
title: const Text("Font Size"),
subtitle: Text(settings.noteFontSize.toPublicString()),
onTap: () async {
var fontSize = await showDialog<NoteFontSize>(
@ -142,7 +142,7 @@ class SettingsListState extends State<SettingsList> {
SettingsHeader("Git Author Settings"),
ListTile(title: gitAuthorForm),
ListTile(title: gitAuthorEmailForm),
SizedBox(height: 16.0),
const SizedBox(height: 16.0),
SettingsHeader("Storage"),
ListPreference(
title: "File Name",
@ -156,7 +156,7 @@ class SettingsListState extends State<SettingsList> {
setState(() {});
},
),
SizedBox(height: 16.0),
const SizedBox(height: 16.0),
SettingsHeader("Analytics"),
BoolPreference(
title: "Collect Anonymous Usage Statistics",
@ -188,7 +188,7 @@ class SettingsHeader extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Padding(
padding: EdgeInsets.only(left: 16.0, bottom: 0.0, top: 20.0),
padding: const EdgeInsets.only(left: 16.0, bottom: 0.0, top: 20.0),
child: Text(
text,
style: TextStyle(
@ -256,10 +256,10 @@ class FontSizeSettingsDialog extends StatelessWidget {
children: sizes,
),
),
contentPadding: EdgeInsets.all(0.0),
contentPadding: const EdgeInsets.all(0.0),
actions: <Widget>[
FlatButton(
child: Text('CANCEL'),
child: const Text('CANCEL'),
onPressed: () {
Navigator.of(context).pop();
},
@ -326,10 +326,10 @@ class ListPreference extends StatelessWidget {
children: children,
),
),
contentPadding: EdgeInsets.all(0.0),
contentPadding: const EdgeInsets.all(0.0),
actions: <Widget>[
FlatButton(
child: Text('CANCEL'),
child: const Text('CANCEL'),
onPressed: () {
Navigator.of(context).pop();
},

View File

@ -3,15 +3,15 @@ import 'package:flutter/material.dart';
class Themes {
static final light = ThemeData(
brightness: Brightness.light,
primaryColor: Color(0xFF66bb6a),
primaryColorLight: Color(0xFF98ee99),
primaryColorDark: Color(0xFF338a3e),
accentColor: Color(0xff6d4c41),
primaryColor: const Color(0xFF66bb6a),
primaryColorLight: const Color(0xFF98ee99),
primaryColorDark: const Color(0xFF338a3e),
accentColor: const Color(0xff6d4c41),
);
static final dark = ThemeData(
brightness: Brightness.dark,
primaryColor: Color(0xff212121),
accentColor: Color(0xff689f38),
primaryColor: const Color(0xff212121),
accentColor: const Color(0xff689f38),
);
}

View File

@ -50,7 +50,7 @@ class AppDrawer extends StatelessWidget {
child: DecoratedBox(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/icon/icon.png'),
image: const AssetImage('assets/icon/icon.png'),
),
),
),

View File

@ -19,7 +19,7 @@ class IconDismissable extends Dismissible {
color: backgroundColor,
alignment: AlignmentDirectional.centerStart,
child: Padding(
padding: EdgeInsets.fromLTRB(16.0, 0.0, 0.0, 0.0),
padding: const EdgeInsets.fromLTRB(16.0, 0.0, 0.0, 0.0),
child: Icon(
Icons.delete,
color: Colors.white,
@ -30,7 +30,7 @@ class IconDismissable extends Dismissible {
color: backgroundColor,
alignment: AlignmentDirectional.centerEnd,
child: Padding(
padding: EdgeInsets.fromLTRB(0.0, 0.0, 16.0, 0.0),
padding: const EdgeInsets.fromLTRB(0.0, 0.0, 16.0, 0.0),
child: Icon(
Icons.delete,
color: Colors.white,

View File

@ -86,13 +86,13 @@ class JournalList extends StatelessWidget {
var children = <Widget>[];
if (time.isNotEmpty) {
children.addAll(<Widget>[
SizedBox(height: 4.0),
const SizedBox(height: 4.0),
Text(time, style: textTheme.body1),
]);
}
children.addAll(<Widget>[
SizedBox(height: 4.0),
const SizedBox(height: 4.0),
Text(
body,
maxLines: 3,
@ -115,7 +115,7 @@ class JournalList extends StatelessWidget {
);
return Padding(
padding: EdgeInsets.only(top: 8.0, bottom: 8.0),
padding: const EdgeInsets.only(top: 8.0, bottom: 8.0),
child: tile,
);
}

View File

@ -30,7 +30,7 @@ class NoteHeader extends StatelessWidget {
var w = Row(
children: <Widget>[
bigNum,
SizedBox(width: 8.0),
const SizedBox(width: 8.0),
Column(
children: <Widget>[
dateText,
@ -43,7 +43,7 @@ class NoteHeader extends StatelessWidget {
);
return Padding(
padding: EdgeInsets.only(top: 8.0, bottom: 18.0),
padding: const EdgeInsets.only(top: 8.0, bottom: 18.0),
child: w,
);
}