mirror of
https://github.com/flutter/samples.git
synced 2026-04-03 18:22:45 +00:00
Beta (#1234)
This commit is contained in:
@@ -19,7 +19,7 @@ class LintingTool extends StatefulWidget {
|
||||
static const String homeRoute = routes.homeRoute;
|
||||
|
||||
@override
|
||||
_LintingToolState createState() => _LintingToolState();
|
||||
State<LintingTool> createState() => _LintingToolState();
|
||||
}
|
||||
|
||||
class _LintingToolState extends State<LintingTool> {
|
||||
|
||||
@@ -60,6 +60,7 @@ class ProfilesStore extends ChangeNotifier {
|
||||
}
|
||||
|
||||
Future<void> addToExistingProfile(RulesProfile profile, Rule rule) async {
|
||||
// ignore: todo
|
||||
// TODO(abd99): Consider refactoring to LinkedHashSet/SplayTreeSet to avoid
|
||||
// duplication automatically.
|
||||
// ref: https://github.com/flutter/samples/pull/870#discussion_r685666792
|
||||
|
||||
@@ -32,7 +32,7 @@ class RuleStore extends ChangeNotifier {
|
||||
String? get error => _error;
|
||||
|
||||
List<RulesProfile> get defaultProfiles {
|
||||
List<RulesProfile> _defaultProfiles = [];
|
||||
List<RulesProfile> defaultProfiles = [];
|
||||
|
||||
var rulesWithDefaultSets =
|
||||
rules.where((rule) => rule.sets.isNotEmpty).toList();
|
||||
@@ -40,16 +40,16 @@ class RuleStore extends ChangeNotifier {
|
||||
for (final rule in rulesWithDefaultSets) {
|
||||
for (final setName in rule.sets) {
|
||||
var profileIndex =
|
||||
_defaultProfiles.indexWhere((profile) => profile.name == setName);
|
||||
defaultProfiles.indexWhere((profile) => profile.name == setName);
|
||||
if (profileIndex >= 0) {
|
||||
_defaultProfiles[profileIndex].rules.add(rule);
|
||||
defaultProfiles[profileIndex].rules.add(rule);
|
||||
} else {
|
||||
_defaultProfiles.add(RulesProfile(name: setName, rules: [rule]));
|
||||
defaultProfiles.add(RulesProfile(name: setName, rules: [rule]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return _defaultProfiles;
|
||||
return defaultProfiles;
|
||||
}
|
||||
|
||||
Future<void> fetchRules() async {
|
||||
|
||||
@@ -10,9 +10,14 @@ import 'package:linting_tool/pages/rules_page.dart';
|
||||
import 'package:linting_tool/theme/colors.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class SavedLintsPage extends StatelessWidget {
|
||||
class SavedLintsPage extends StatefulWidget {
|
||||
const SavedLintsPage({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<SavedLintsPage> createState() => _SavedLintsPageState();
|
||||
}
|
||||
|
||||
class _SavedLintsPageState extends State<SavedLintsPage> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Consumer<ProfilesStore>(
|
||||
@@ -90,11 +95,14 @@ class SavedLintsPage extends StatelessWidget {
|
||||
onSelected: (value) async {
|
||||
switch (value) {
|
||||
case 'Export file':
|
||||
// ignore: todo
|
||||
// TODO(abd99): Add option to select formatting style.
|
||||
|
||||
var saved = await profilesStore
|
||||
.exportProfileFile(profile);
|
||||
|
||||
if (!mounted) return;
|
||||
|
||||
if (!saved) {
|
||||
_showSnackBar(
|
||||
context,
|
||||
@@ -112,12 +120,12 @@ class SavedLintsPage extends StatelessWidget {
|
||||
itemBuilder: (context) {
|
||||
return [
|
||||
const PopupMenuItem(
|
||||
child: Text('Export file'),
|
||||
value: 'Export file',
|
||||
child: Text('Export file'),
|
||||
),
|
||||
const PopupMenuItem(
|
||||
child: Text('Delete'),
|
||||
value: 'Delete',
|
||||
child: Text('Delete'),
|
||||
),
|
||||
];
|
||||
},
|
||||
|
||||
@@ -18,14 +18,14 @@ class AdaptiveNav extends StatefulWidget {
|
||||
const AdaptiveNav({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
_AdaptiveNavState createState() => _AdaptiveNavState();
|
||||
State<AdaptiveNav> createState() => _AdaptiveNavState();
|
||||
}
|
||||
|
||||
class _AdaptiveNavState extends State<AdaptiveNav> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final isDesktop = isDisplayLarge(context);
|
||||
const _navigationDestinations = <_Destination>[
|
||||
const navigationDestinations = <_Destination>[
|
||||
_Destination(
|
||||
textLabel: 'Home',
|
||||
icon: Icons.home_outlined,
|
||||
@@ -46,14 +46,14 @@ class _AdaptiveNavState extends State<AdaptiveNav> {
|
||||
),
|
||||
];
|
||||
|
||||
final _trailing = <String, IconData>{
|
||||
final trailing = <String, IconData>{
|
||||
'About': Icons.info_outline,
|
||||
};
|
||||
|
||||
return _NavView(
|
||||
extended: isDesktop,
|
||||
destinations: _navigationDestinations,
|
||||
trailing: _trailing,
|
||||
destinations: navigationDestinations,
|
||||
trailing: trailing,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ class LintExpansionTile extends StatefulWidget {
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
_LintExpansionTileState createState() => _LintExpansionTileState();
|
||||
State<LintExpansionTile> createState() => _LintExpansionTileState();
|
||||
}
|
||||
|
||||
class _LintExpansionTileState extends State<LintExpansionTile> {
|
||||
@@ -142,7 +142,7 @@ class _LintExpansionTileState extends State<LintExpansionTile> {
|
||||
await showDialog<String>(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return _NewProfileDialog(rule: rule);
|
||||
return NewProfileDialog(rule: rule);
|
||||
},
|
||||
);
|
||||
} else if (destinationProfileType ==
|
||||
@@ -150,7 +150,7 @@ class _LintExpansionTileState extends State<LintExpansionTile> {
|
||||
await showDialog<String>(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return _ExistingProfileDialog(rule: rule);
|
||||
return ExistingProfileDialog(rule: rule);
|
||||
},
|
||||
);
|
||||
}
|
||||
@@ -205,22 +205,27 @@ class _ProfileTypeDialog extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
|
||||
class _NewProfileDialog extends StatelessWidget {
|
||||
class NewProfileDialog extends StatefulWidget {
|
||||
final Rule rule;
|
||||
const _NewProfileDialog({
|
||||
const NewProfileDialog({
|
||||
required this.rule,
|
||||
Key? key,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<NewProfileDialog> createState() => _NewProfileDialogState();
|
||||
}
|
||||
|
||||
class _NewProfileDialogState extends State<NewProfileDialog> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
String name = '';
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
final formKey = GlobalKey<FormState>();
|
||||
|
||||
return AlertDialog(
|
||||
title: const Text('Create new lint profile'),
|
||||
content: Form(
|
||||
key: _formKey,
|
||||
key: formKey,
|
||||
autovalidateMode: AutovalidateMode.onUserInteraction,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
@@ -251,13 +256,14 @@ class _NewProfileDialog extends StatelessWidget {
|
||||
),
|
||||
ElevatedButton(
|
||||
onPressed: () async {
|
||||
if (_formKey.currentState!.validate()) {
|
||||
if (formKey.currentState!.validate()) {
|
||||
var newProfile = RulesProfile(
|
||||
name: name,
|
||||
rules: [rule],
|
||||
rules: [widget.rule],
|
||||
);
|
||||
await Provider.of<ProfilesStore>(context, listen: false)
|
||||
.addToNewProfile(newProfile);
|
||||
if (!mounted) return;
|
||||
Navigator.pop(context);
|
||||
}
|
||||
},
|
||||
@@ -268,14 +274,19 @@ class _NewProfileDialog extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
|
||||
class _ExistingProfileDialog extends StatelessWidget {
|
||||
const _ExistingProfileDialog({
|
||||
class ExistingProfileDialog extends StatefulWidget {
|
||||
const ExistingProfileDialog({
|
||||
Key? key,
|
||||
required this.rule,
|
||||
}) : super(key: key);
|
||||
|
||||
final Rule rule;
|
||||
|
||||
@override
|
||||
State<ExistingProfileDialog> createState() => _ExistingProfileDialogState();
|
||||
}
|
||||
|
||||
class _ExistingProfileDialogState extends State<ExistingProfileDialog> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var profilesStore = Provider.of<ProfilesStore>(context);
|
||||
@@ -291,7 +302,8 @@ class _ExistingProfileDialog extends StatelessWidget {
|
||||
title: Text(savedProfiles[index].name),
|
||||
onTap: () async {
|
||||
await profilesStore.addToExistingProfile(
|
||||
savedProfiles[index], rule);
|
||||
savedProfiles[index], widget.rule);
|
||||
if (!mounted) return;
|
||||
Navigator.pop(context);
|
||||
},
|
||||
),
|
||||
|
||||
@@ -18,7 +18,7 @@ class SavedRuleTile extends StatefulWidget {
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
_SavedRuleTileState createState() => _SavedRuleTileState();
|
||||
State<SavedRuleTile> createState() => _SavedRuleTileState();
|
||||
}
|
||||
|
||||
class _SavedRuleTileState extends State<SavedRuleTile> {
|
||||
|
||||
Reference in New Issue
Block a user