mirror of
https://github.com/flutter/samples.git
synced 2025-11-10 14:58:34 +00:00
Upgrading samples to flutter_lints, part 1 of n (#804)
This commit is contained in:
@@ -28,10 +28,8 @@ class FirebaseEntryApi implements EntryApi {
|
||||
|
||||
@override
|
||||
Stream<List<Entry>> subscribe(String categoryId) {
|
||||
var snapshots = _categoriesRef
|
||||
.document('$categoryId')
|
||||
.collection('entries')
|
||||
.snapshots();
|
||||
var snapshots =
|
||||
_categoriesRef.document(categoryId).collection('entries').snapshots();
|
||||
var result = snapshots.map((querySnapshot) {
|
||||
return querySnapshot.documents.map((snapshot) {
|
||||
return Entry.fromJson(snapshot.data)..id = snapshot.documentID;
|
||||
@@ -54,7 +52,7 @@ class FirebaseEntryApi implements EntryApi {
|
||||
@override
|
||||
Future<Entry> insert(String categoryId, Entry entry) async {
|
||||
var document = await _categoriesRef
|
||||
.document('$categoryId')
|
||||
.document(categoryId)
|
||||
.collection('entries')
|
||||
.add(entry.toJson());
|
||||
return await get(categoryId, document.documentID);
|
||||
@@ -62,8 +60,7 @@ class FirebaseEntryApi implements EntryApi {
|
||||
|
||||
@override
|
||||
Future<List<Entry>> list(String categoryId) async {
|
||||
var entriesRef =
|
||||
_categoriesRef.document('$categoryId').collection('entries');
|
||||
var entriesRef = _categoriesRef.document(categoryId).collection('entries');
|
||||
var querySnapshot = await entriesRef.getDocuments();
|
||||
var entries = querySnapshot.documents
|
||||
.map((doc) => Entry.fromJson(doc.data)..id = doc.documentID)
|
||||
@@ -110,7 +107,7 @@ class FirebaseCategoryApi implements CategoryApi {
|
||||
|
||||
@override
|
||||
Future<Category> delete(String id) async {
|
||||
var document = _categoriesRef.document('$id');
|
||||
var document = _categoriesRef.document(id);
|
||||
var categories = await get(document.documentID);
|
||||
|
||||
await document.delete();
|
||||
@@ -120,7 +117,7 @@ class FirebaseCategoryApi implements CategoryApi {
|
||||
|
||||
@override
|
||||
Future<Category> get(String id) async {
|
||||
var document = _categoriesRef.document('$id');
|
||||
var document = _categoriesRef.document(id);
|
||||
var snapshot = await document.get();
|
||||
return Category.fromJson(snapshot.data)..id = snapshot.documentID;
|
||||
}
|
||||
@@ -143,7 +140,7 @@ class FirebaseCategoryApi implements CategoryApi {
|
||||
|
||||
@override
|
||||
Future<Category> update(Category category, String id) async {
|
||||
var document = _categoriesRef.document('$id');
|
||||
var document = _categoriesRef.document(id);
|
||||
await document.setData(category.toJson());
|
||||
var snapshot = await document.get();
|
||||
return Category.fromJson(snapshot.data)..id = snapshot.documentID;
|
||||
|
||||
@@ -20,11 +20,11 @@ class MockDashboardApi implements DashboardApi {
|
||||
|
||||
/// Creates a [MockDashboardApi] filled with mock data for the last 30 days.
|
||||
Future<void> fillWithMockData() async {
|
||||
await Future<void>.delayed(Duration(seconds: 1));
|
||||
await Future<void>.delayed(const Duration(seconds: 1));
|
||||
var category1 = await categories.insert(Category('Coffee (oz)'));
|
||||
var category2 = await categories.insert(Category('Running (miles)'));
|
||||
var category3 = await categories.insert(Category('Git Commits'));
|
||||
var monthAgo = DateTime.now().subtract(Duration(days: 30));
|
||||
var monthAgo = DateTime.now().subtract(const Duration(days: 30));
|
||||
|
||||
for (var category in [category1, category2, category3]) {
|
||||
for (var i = 0; i < 30; i++) {
|
||||
@@ -37,8 +37,8 @@ class MockDashboardApi implements DashboardApi {
|
||||
}
|
||||
|
||||
class MockCategoryApi implements CategoryApi {
|
||||
Map<String, Category> _storage = {};
|
||||
StreamController<List<Category>> _streamController =
|
||||
final Map<String, Category> _storage = {};
|
||||
final StreamController<List<Category>> _streamController =
|
||||
StreamController<List<Category>>.broadcast();
|
||||
|
||||
@override
|
||||
@@ -74,6 +74,7 @@ class MockCategoryApi implements CategoryApi {
|
||||
return category..id = id;
|
||||
}
|
||||
|
||||
@override
|
||||
Stream<List<Category>> subscribe() => _streamController.stream;
|
||||
|
||||
void _emit() {
|
||||
@@ -82,8 +83,8 @@ class MockCategoryApi implements CategoryApi {
|
||||
}
|
||||
|
||||
class MockEntryApi implements EntryApi {
|
||||
Map<String, Entry> _storage = {};
|
||||
StreamController<_EntriesEvent> _streamController =
|
||||
final Map<String, Entry> _storage = {};
|
||||
final StreamController<_EntriesEvent> _streamController =
|
||||
StreamController.broadcast();
|
||||
|
||||
@override
|
||||
|
||||
@@ -26,14 +26,14 @@ class AppState {
|
||||
/// Creates a [DashboardApi] for the given user. This allows users of this
|
||||
/// widget to specify whether [MockDashboardApi] or [ApiBuilder] should be
|
||||
/// created when the user logs in.
|
||||
typedef DashboardApi ApiBuilder(User user);
|
||||
typedef ApiBuilder = DashboardApi Function(User user);
|
||||
|
||||
/// An app that displays a personalized dashboard.
|
||||
class DashboardApp extends StatefulWidget {
|
||||
static ApiBuilder _mockApiBuilder =
|
||||
(user) => MockDashboardApi()..fillWithMockData();
|
||||
static ApiBuilder _apiBuilder =
|
||||
(user) => FirebaseDashboardApi(Firestore.instance, user.uid);
|
||||
static DashboardApi _mockApiBuilder(User user) =>
|
||||
MockDashboardApi()..fillWithMockData();
|
||||
static DashboardApi _apiBuilder(User user) =>
|
||||
FirebaseDashboardApi(Firestore.instance, user.uid);
|
||||
|
||||
final Auth auth;
|
||||
final ApiBuilder apiBuilder;
|
||||
@@ -55,6 +55,7 @@ class DashboardApp extends StatefulWidget {
|
||||
class _DashboardAppState extends State<DashboardApp> {
|
||||
AppState _appState;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_appState = AppState(widget.auth);
|
||||
@@ -80,7 +81,7 @@ class SignInSwitcher extends StatefulWidget {
|
||||
final AppState appState;
|
||||
final ApiBuilder apiBuilder;
|
||||
|
||||
SignInSwitcher({
|
||||
const SignInSwitcher({
|
||||
this.appState,
|
||||
this.apiBuilder,
|
||||
});
|
||||
@@ -97,7 +98,7 @@ class _SignInSwitcherState extends State<SignInSwitcher> {
|
||||
return AnimatedSwitcher(
|
||||
switchInCurve: Curves.easeOut,
|
||||
switchOutCurve: Curves.easeOut,
|
||||
duration: Duration(milliseconds: 200),
|
||||
duration: const Duration(milliseconds: 200),
|
||||
child: _isSignedIn
|
||||
? HomePage(
|
||||
onSignOut: _handleSignOut,
|
||||
|
||||
@@ -12,8 +12,10 @@ class FirebaseAuthService implements Auth {
|
||||
final GoogleSignIn _googleSignIn = GoogleSignIn();
|
||||
final FirebaseAuth _auth = FirebaseAuth.instance;
|
||||
|
||||
@override
|
||||
Future<bool> get isSignedIn => _googleSignIn.isSignedIn();
|
||||
|
||||
@override
|
||||
Future<User> signIn() async {
|
||||
try {
|
||||
return await _signIn();
|
||||
@@ -41,6 +43,7 @@ class FirebaseAuthService implements Auth {
|
||||
return _FirebaseUser(authResult.user.uid);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> signOut() async {
|
||||
await Future.wait([
|
||||
_auth.signOut(),
|
||||
@@ -50,6 +53,7 @@ class FirebaseAuthService implements Auth {
|
||||
}
|
||||
|
||||
class _FirebaseUser implements User {
|
||||
@override
|
||||
final String uid;
|
||||
|
||||
_FirebaseUser(this.uid);
|
||||
|
||||
@@ -7,6 +7,7 @@ import 'dart:math';
|
||||
import 'auth.dart';
|
||||
|
||||
class MockAuthService implements Auth {
|
||||
@override
|
||||
Future<bool> get isSignedIn async => false;
|
||||
|
||||
@override
|
||||
@@ -26,5 +27,6 @@ class MockAuthService implements Auth {
|
||||
}
|
||||
|
||||
class MockUser implements User {
|
||||
@override
|
||||
String get uid => "123";
|
||||
}
|
||||
|
||||
@@ -10,13 +10,14 @@ import '../app.dart';
|
||||
import '../widgets/category_chart.dart';
|
||||
|
||||
class DashboardPage extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var appState = Provider.of<AppState>(context);
|
||||
return FutureBuilder<List<Category>>(
|
||||
future: appState.api.categories.list(),
|
||||
builder: (context, futureSnapshot) {
|
||||
if (!futureSnapshot.hasData) {
|
||||
return Center(
|
||||
return const Center(
|
||||
child: CircularProgressIndicator(),
|
||||
);
|
||||
}
|
||||
@@ -25,7 +26,7 @@ class DashboardPage extends StatelessWidget {
|
||||
stream: appState.api.categories.subscribe(),
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.data == null) {
|
||||
return Center(
|
||||
return const Center(
|
||||
child: CircularProgressIndicator(),
|
||||
);
|
||||
}
|
||||
@@ -40,14 +41,14 @@ class DashboardPage extends StatelessWidget {
|
||||
class Dashboard extends StatelessWidget {
|
||||
final List<Category> categories;
|
||||
|
||||
Dashboard(this.categories);
|
||||
const Dashboard(this.categories);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var api = Provider.of<AppState>(context).api;
|
||||
return Scrollbar(
|
||||
child: GridView(
|
||||
gridDelegate: SliverGridDelegateWithMaxCrossAxisExtent(
|
||||
gridDelegate: const SliverGridDelegateWithMaxCrossAxisExtent(
|
||||
childAspectRatio: 2,
|
||||
maxCrossAxisExtent: 500,
|
||||
),
|
||||
|
||||
@@ -29,7 +29,7 @@ class _EntriesPageState extends State<EntriesPage> {
|
||||
onSelected: (category) => setState(() => _selected = category)),
|
||||
Expanded(
|
||||
child: _selected == null
|
||||
? Center(child: CircularProgressIndicator())
|
||||
? const Center(child: CircularProgressIndicator())
|
||||
: EntriesList(
|
||||
category: _selected,
|
||||
api: appState.api.entries,
|
||||
@@ -89,7 +89,7 @@ class _EntriesListState extends State<EntriesList> {
|
||||
}
|
||||
|
||||
Widget _buildLoadingIndicator() {
|
||||
return Center(child: CircularProgressIndicator());
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ class EntryTile extends StatelessWidget {
|
||||
final Category category;
|
||||
final Entry entry;
|
||||
|
||||
EntryTile({
|
||||
const EntryTile({
|
||||
this.category,
|
||||
this.entry,
|
||||
});
|
||||
@@ -111,7 +111,7 @@ class EntryTile extends StatelessWidget {
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
TextButton(
|
||||
child: Text('Edit'),
|
||||
child: const Text('Edit'),
|
||||
onPressed: () {
|
||||
showDialog<void>(
|
||||
context: context,
|
||||
@@ -122,19 +122,19 @@ class EntryTile extends StatelessWidget {
|
||||
},
|
||||
),
|
||||
TextButton(
|
||||
child: Text('Delete'),
|
||||
child: const Text('Delete'),
|
||||
onPressed: () async {
|
||||
var shouldDelete = await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: Text('Delete entry?'),
|
||||
title: const Text('Delete entry?'),
|
||||
actions: [
|
||||
TextButton(
|
||||
child: Text('Cancel'),
|
||||
child: const Text('Cancel'),
|
||||
onPressed: () => Navigator.of(context).pop(false),
|
||||
),
|
||||
TextButton(
|
||||
child: Text('Delete'),
|
||||
child: const Text('Delete'),
|
||||
onPressed: () => Navigator.of(context).pop(true),
|
||||
),
|
||||
],
|
||||
@@ -147,7 +147,7 @@ class EntryTile extends StatelessWidget {
|
||||
.delete(category.id, entry.id);
|
||||
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
const SnackBar(
|
||||
content: Text('Entry deleted'),
|
||||
),
|
||||
);
|
||||
|
||||
@@ -12,7 +12,7 @@ import 'entries.dart';
|
||||
class HomePage extends StatefulWidget {
|
||||
final VoidCallback onSignOut;
|
||||
|
||||
HomePage({
|
||||
const HomePage({
|
||||
@required this.onSignOut,
|
||||
});
|
||||
|
||||
@@ -26,19 +26,19 @@ class _HomePageState extends State<HomePage> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AdaptiveScaffold(
|
||||
title: Text('Dashboard App'),
|
||||
title: const Text('Dashboard App'),
|
||||
actions: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: TextButton(
|
||||
style: TextButton.styleFrom(primary: Colors.white),
|
||||
onPressed: () => _handleSignOut(),
|
||||
child: Text('Sign Out'),
|
||||
child: const Text('Sign Out'),
|
||||
),
|
||||
)
|
||||
],
|
||||
currentIndex: _pageIndex,
|
||||
destinations: [
|
||||
destinations: const [
|
||||
AdaptiveScaffoldDestination(title: 'Home', icon: Icons.home),
|
||||
AdaptiveScaffoldDestination(title: 'Entries', icon: Icons.list),
|
||||
AdaptiveScaffoldDestination(title: 'Settings', icon: Icons.settings),
|
||||
@@ -61,7 +61,7 @@ class _HomePageState extends State<HomePage> {
|
||||
|
||||
FloatingActionButton _buildFab(BuildContext context) {
|
||||
return FloatingActionButton(
|
||||
child: Icon(Icons.add),
|
||||
child: const Icon(Icons.add),
|
||||
onPressed: () => _handleFabPressed(),
|
||||
);
|
||||
}
|
||||
@@ -88,16 +88,16 @@ class _HomePageState extends State<HomePage> {
|
||||
var shouldSignOut = await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: Text('Are you sure you want to sign out?'),
|
||||
title: const Text('Are you sure you want to sign out?'),
|
||||
actions: [
|
||||
TextButton(
|
||||
child: Text('No'),
|
||||
child: const Text('No'),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop(false);
|
||||
},
|
||||
),
|
||||
TextButton(
|
||||
child: Text('Yes'),
|
||||
child: const Text('Yes'),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop(true);
|
||||
},
|
||||
@@ -122,6 +122,6 @@ class _HomePageState extends State<HomePage> {
|
||||
return EntriesPage();
|
||||
}
|
||||
|
||||
return Center(child: Text('Settings page'));
|
||||
return const Center(child: Text('Settings page'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ class SignInPage extends StatelessWidget {
|
||||
final Auth auth;
|
||||
final ValueChanged<User> onSuccess;
|
||||
|
||||
SignInPage({
|
||||
const SignInPage({
|
||||
@required this.auth,
|
||||
@required this.onSuccess,
|
||||
});
|
||||
@@ -29,7 +29,7 @@ class SignInButton extends StatefulWidget {
|
||||
final Auth auth;
|
||||
final ValueChanged<User> onSuccess;
|
||||
|
||||
SignInButton({
|
||||
const SignInButton({
|
||||
@required this.auth,
|
||||
@required this.onSuccess,
|
||||
});
|
||||
@@ -78,7 +78,7 @@ class _SignInButtonState extends State<SignInButton> {
|
||||
var alreadySignedIn = snapshot.data;
|
||||
if (snapshot.connectionState != ConnectionState.done ||
|
||||
alreadySignedIn == true) {
|
||||
return CircularProgressIndicator();
|
||||
return const CircularProgressIndicator();
|
||||
}
|
||||
|
||||
// If sign in failed, show toast and the login button
|
||||
@@ -87,7 +87,7 @@ class _SignInButtonState extends State<SignInButton> {
|
||||
}
|
||||
|
||||
return ElevatedButton(
|
||||
child: Text('Sign In with Google'),
|
||||
child: const Text('Sign In with Google'),
|
||||
onPressed: () => _signIn(),
|
||||
);
|
||||
},
|
||||
@@ -96,7 +96,7 @@ class _SignInButtonState extends State<SignInButton> {
|
||||
|
||||
void _showError() {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
const SnackBar(
|
||||
content: Text('Unable to sign in.'),
|
||||
),
|
||||
);
|
||||
|
||||
@@ -60,6 +60,6 @@ Iterable<List<Entry>> _entriesInRangeImpl(
|
||||
}
|
||||
|
||||
yield es;
|
||||
d = d.add(Duration(days: 1));
|
||||
d = d.add(const Duration(days: 1));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,6 @@ extension DayUtils on DateTime {
|
||||
|
||||
/// Checks that the two [DateTime]s share the same date.
|
||||
bool isSameDay(DateTime d2) {
|
||||
return this.year == d2.year && this.month == d2.month && this.day == d2.day;
|
||||
return year == d2.year && month == d2.month && day == d2.day;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ class CategoryDropdown extends StatefulWidget {
|
||||
final CategoryApi api;
|
||||
final ValueChanged<Category> onSelected;
|
||||
|
||||
CategoryDropdown({
|
||||
const CategoryDropdown({
|
||||
@required this.api,
|
||||
@required this.onSelected,
|
||||
});
|
||||
@@ -27,6 +27,7 @@ class _CategoryDropdownState extends State<CategoryDropdown> {
|
||||
Future<List<Category>> _future;
|
||||
Stream<List<Category>> _stream;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
@@ -69,7 +70,7 @@ class _CategoryDropdownState extends State<CategoryDropdown> {
|
||||
builder: (context, futureSnapshot) {
|
||||
// Show an empty dropdown while the data is loading.
|
||||
if (!futureSnapshot.hasData) {
|
||||
return DropdownButton<Category>(items: [], onChanged: null);
|
||||
return DropdownButton<Category>(items: const [], onChanged: null);
|
||||
}
|
||||
|
||||
return StreamBuilder<List<Category>>(
|
||||
|
||||
@@ -18,11 +18,12 @@ class CategoryChart extends StatelessWidget {
|
||||
final Category category;
|
||||
final DashboardApi api;
|
||||
|
||||
CategoryChart({
|
||||
const CategoryChart({
|
||||
@required this.category,
|
||||
@required this.api,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Column(
|
||||
children: [
|
||||
@@ -33,7 +34,7 @@ class CategoryChart extends StatelessWidget {
|
||||
children: [
|
||||
Text(category.name),
|
||||
IconButton(
|
||||
icon: Icon(Icons.settings),
|
||||
icon: const Icon(Icons.settings),
|
||||
onPressed: () {
|
||||
showDialog<EditCategoryDialog>(
|
||||
context: context,
|
||||
@@ -73,14 +74,14 @@ class CategoryChart extends StatelessWidget {
|
||||
}
|
||||
|
||||
Widget _buildLoadingIndicator() {
|
||||
return Center(child: CircularProgressIndicator());
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
}
|
||||
}
|
||||
|
||||
class _BarChart extends StatelessWidget {
|
||||
final List<Entry> entries;
|
||||
|
||||
_BarChart({this.entries});
|
||||
const _BarChart({this.entries});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
||||
@@ -13,7 +13,7 @@ class NewCategoryForm extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _NewCategoryFormState extends State<NewCategoryForm> {
|
||||
Category _category = Category('');
|
||||
final Category _category = Category('');
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -34,7 +34,7 @@ class EditCategoryForm extends StatefulWidget {
|
||||
final Category category;
|
||||
final ValueChanged<bool> onDone;
|
||||
|
||||
EditCategoryForm({
|
||||
const EditCategoryForm({
|
||||
@required this.category,
|
||||
@required this.onDone,
|
||||
});
|
||||
@@ -57,7 +57,7 @@ class _EditCategoryFormState extends State<EditCategoryForm> {
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: TextFormField(
|
||||
initialValue: widget.category.name,
|
||||
decoration: InputDecoration(
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Name',
|
||||
),
|
||||
onChanged: (newValue) {
|
||||
@@ -77,7 +77,7 @@ class _EditCategoryFormState extends State<EditCategoryForm> {
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(left: 8.0, right: 8.0),
|
||||
child: ElevatedButton(
|
||||
child: Text('Cancel'),
|
||||
child: const Text('Cancel'),
|
||||
onPressed: () {
|
||||
widget.onDone(false);
|
||||
},
|
||||
@@ -86,7 +86,7 @@ class _EditCategoryFormState extends State<EditCategoryForm> {
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(left: 8.0, right: 8.0),
|
||||
child: ElevatedButton(
|
||||
child: Text('OK'),
|
||||
child: const Text('OK'),
|
||||
onPressed: () {
|
||||
if (_formKey.currentState.validate()) {
|
||||
widget.onDone(true);
|
||||
|
||||
@@ -14,7 +14,7 @@ class NewCategoryDialog extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SimpleDialog(
|
||||
title: Text('New Category'),
|
||||
title: const Text('New Category'),
|
||||
children: <Widget>[
|
||||
NewCategoryForm(),
|
||||
],
|
||||
@@ -25,7 +25,7 @@ class NewCategoryDialog extends StatelessWidget {
|
||||
class EditCategoryDialog extends StatelessWidget {
|
||||
final Category category;
|
||||
|
||||
EditCategoryDialog({
|
||||
const EditCategoryDialog({
|
||||
@required this.category,
|
||||
});
|
||||
|
||||
@@ -34,7 +34,7 @@ class EditCategoryDialog extends StatelessWidget {
|
||||
var api = Provider.of<AppState>(context).api;
|
||||
|
||||
return SimpleDialog(
|
||||
title: Text('Edit Category'),
|
||||
title: const Text('Edit Category'),
|
||||
children: [
|
||||
EditCategoryForm(
|
||||
category: category,
|
||||
@@ -59,7 +59,7 @@ class _NewEntryDialogState extends State<NewEntryDialog> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SimpleDialog(
|
||||
title: Text('New Entry'),
|
||||
title: const Text('New Entry'),
|
||||
children: [
|
||||
NewEntryForm(),
|
||||
],
|
||||
@@ -71,7 +71,7 @@ class EditEntryDialog extends StatelessWidget {
|
||||
final Category category;
|
||||
final Entry entry;
|
||||
|
||||
EditEntryDialog({
|
||||
const EditEntryDialog({
|
||||
this.category,
|
||||
this.entry,
|
||||
});
|
||||
@@ -81,7 +81,7 @@ class EditEntryDialog extends StatelessWidget {
|
||||
var api = Provider.of<AppState>(context).api;
|
||||
|
||||
return SimpleDialog(
|
||||
title: Text('Edit Entry'),
|
||||
title: const Text('Edit Entry'),
|
||||
children: [
|
||||
EditEntryForm(
|
||||
entry: entry,
|
||||
|
||||
@@ -17,7 +17,7 @@ class NewEntryForm extends StatefulWidget {
|
||||
|
||||
class _NewEntryFormState extends State<NewEntryForm> {
|
||||
Category _selected;
|
||||
Entry _entry = Entry(0, DateTime.now());
|
||||
final Entry _entry = Entry(0, DateTime.now());
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -55,7 +55,7 @@ class EditEntryForm extends StatefulWidget {
|
||||
final Entry entry;
|
||||
final ValueChanged<bool> onDone;
|
||||
|
||||
EditEntryForm({
|
||||
const EditEntryForm({
|
||||
@required this.entry,
|
||||
@required this.onDone,
|
||||
});
|
||||
@@ -75,10 +75,10 @@ class _EditEntryFormState extends State<EditEntryForm> {
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Padding(
|
||||
padding: EdgeInsets.all(8),
|
||||
padding: const EdgeInsets.all(8),
|
||||
child: TextFormField(
|
||||
initialValue: widget.entry.value.toString(),
|
||||
decoration: InputDecoration(labelText: 'Value'),
|
||||
decoration: const InputDecoration(labelText: 'Value'),
|
||||
keyboardType: TextInputType.number,
|
||||
validator: (value) {
|
||||
try {
|
||||
@@ -98,18 +98,19 @@ class _EditEntryFormState extends State<EditEntryForm> {
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: EdgeInsets.all(8),
|
||||
padding: const EdgeInsets.all(8),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(intl.DateFormat('MM/dd/yyyy').format(widget.entry.time)),
|
||||
ElevatedButton(
|
||||
child: Text('Edit'),
|
||||
child: const Text('Edit'),
|
||||
onPressed: () async {
|
||||
var result = await showDatePicker(
|
||||
context: context,
|
||||
initialDate: widget.entry.time,
|
||||
firstDate: DateTime.now().subtract(Duration(days: 365)),
|
||||
firstDate:
|
||||
DateTime.now().subtract(const Duration(days: 365)),
|
||||
lastDate: DateTime.now());
|
||||
if (result == null) {
|
||||
return;
|
||||
@@ -128,7 +129,7 @@ class _EditEntryFormState extends State<EditEntryForm> {
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(left: 8.0, right: 8.0),
|
||||
child: ElevatedButton(
|
||||
child: Text('Cancel'),
|
||||
child: const Text('Cancel'),
|
||||
onPressed: () {
|
||||
widget.onDone(false);
|
||||
},
|
||||
@@ -137,7 +138,7 @@ class _EditEntryFormState extends State<EditEntryForm> {
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(left: 8.0, right: 8.0),
|
||||
child: ElevatedButton(
|
||||
child: Text('OK'),
|
||||
child: const Text('OK'),
|
||||
onPressed: () {
|
||||
if (_formKey.currentState.validate()) {
|
||||
widget.onDone(true);
|
||||
|
||||
@@ -35,7 +35,7 @@ class AdaptiveScaffold extends StatefulWidget {
|
||||
final ValueChanged<int> onNavigationIndexChange;
|
||||
final FloatingActionButton floatingActionButton;
|
||||
|
||||
AdaptiveScaffold({
|
||||
const AdaptiveScaffold({
|
||||
this.title,
|
||||
this.body,
|
||||
this.actions = const [],
|
||||
|
||||
Reference in New Issue
Block a user