diff --git a/packages/smooth_app/assets/animations/off b/packages/smooth_app/assets/animations/off deleted file mode 100644 index 969af53419c..00000000000 Binary files a/packages/smooth_app/assets/animations/off and /dev/null differ diff --git a/packages/smooth_app/lib/smooth_category_picker_example.dart b/packages/smooth_app/lib/smooth_category_picker_example.dart deleted file mode 100644 index 86263096ff9..00000000000 --- a/packages/smooth_app/lib/smooth_category_picker_example.dart +++ /dev/null @@ -1,222 +0,0 @@ -// @dart = 2.12 - -import 'package:flutter/material.dart'; -import 'package:flutter/scheduler.dart'; -import 'package:openfoodfacts/openfoodfacts.dart'; -import 'package:smooth_app/generic_lib/dialogs/smooth_alert_dialog.dart'; -import 'package:smooth_app/generic_lib/dialogs/smooth_category_picker.dart'; -import 'package:smooth_app/widgets/smooth_scaffold.dart'; - -void main() { - timeDilation = 1.0; - runApp( - const MaterialApp( - debugShowCheckedModeBanner: false, - home: SafeArea( - child: ExampleApp(), - ), - ), - ); -} - -class Fruit implements Comparable { - const Fruit(this.name); - final String name; - - @override - int compareTo(Fruit other) => name.compareTo(other.name); - - @override - String toString() => name; -} - -class FruitCategory extends SmoothCategory { - FruitCategory(Fruit value, [Iterable? children]) - : children = children?.toSet() ?? {}, - super(value); - - Set children; - - @override - void addChild(FruitCategory newChild) => children.add(newChild); - - @override - Future getChild(Fruit childValue) async { - return await super.getChild(childValue) as FruitCategory?; - } - - @override - String getLabel(OpenFoodFactsLanguage language) => value.name; - - @override - Stream> getChildren() async* { - for (final SmoothCategory child in children) { - yield child; - } - } - - @override - Stream> getParents() async* {} -} - -FruitCategory categories = FruitCategory( - const Fruit('fruit'), - { - FruitCategory( - const Fruit('apple'), - { - FruitCategory( - const Fruit('red'), - [ - FruitCategory(const Fruit('Red Delicious')), - FruitCategory(const Fruit('Fuji')), - FruitCategory(const Fruit('Crispin')), - FruitCategory(const Fruit('Pink Lady')), - ], - ), - FruitCategory( - const Fruit('yellow'), - [ - FruitCategory(const Fruit('Yellow Delicious')), - FruitCategory(const Fruit('Ginger Gold')), - ], - ), - FruitCategory( - const Fruit('green'), - [ - FruitCategory(const Fruit('Granny Smith')), - ], - ), - }, - ), - FruitCategory( - const Fruit('berry'), - { - FruitCategory(const Fruit('blueberry')), - FruitCategory(const Fruit('raspberry')), - }, - ), - }, -); - -Future getCategory(Iterable path) async { - if (path.isEmpty) { - return null; - } - FruitCategory? result = categories.value == path.first ? categories : null; - final List followPath = path.skip(1).toList(); - while (result != null && followPath.isNotEmpty) { - result = await result.getChild(followPath.first); - followPath.removeAt(0); - } - return result; -} - -class ExampleApp extends StatefulWidget { - const ExampleApp(); - - @override - State createState() => _ExampleAppState(); -} - -class _ExampleAppState extends State { - Set currentCategories = { - const Fruit('raspberry'), - const Fruit('Fuji') - }; - List currentCategoryPath = [ - const Fruit('fruit'), - const Fruit('apple'), - ]; - - Widget _addCategoryDialog(BuildContext context, FruitCategory parent) { - final TextEditingController controller = TextEditingController(); - void addCategory(String name) { - Navigator.of(context) - .pop(name.isNotEmpty ? FruitCategory(Fruit(name)) : null); - } - - return SmoothAlertDialog( - body: TextField( - autofocus: true, - controller: controller, - decoration: const InputDecoration( - hintText: 'Enter new category name', - ), - onSubmitted: addCategory, - ), - positiveAction: SmoothActionButton( - text: 'OK', - onPressed: () => addCategory(controller.text), - ), - negativeAction: SmoothActionButton( - text: 'Cancel', - onPressed: () => Navigator.of(context).pop(), - ), - ); - } - - @override - Widget build(BuildContext context) { - return Theme( - data: Theme.of(context).copyWith( - canvasColor: Colors.lightGreenAccent, - scaffoldBackgroundColor: Colors.lightGreenAccent, - floatingActionButtonTheme: const FloatingActionButtonThemeData( - backgroundColor: Colors.green, - foregroundColor: Colors.black, - ), - checkboxTheme: CheckboxTheme.of(context).copyWith( - fillColor: WidgetStateColor.resolveWith((Set states) { - if (states.contains(WidgetState.selected)) { - return Colors.green; - } - return Colors.black38; - }), - ), - chipTheme: - ChipTheme.of(context).copyWith(backgroundColor: Colors.green), - ), - child: SmoothScaffold( - body: SmoothCategoryPicker( - categoryFinder: getCategory, - currentPath: currentCategoryPath, - currentCategories: currentCategories, - onCategoriesChanged: (Set value) { - setState(() { - currentCategories = value; - }); - }, - onPathChanged: (Iterable path) { - setState(() { - currentCategoryPath = path.toList(); - }); - }, - onAddCategory: (Iterable path) { - getCategory(path).then((FruitCategory? currentCategory) { - if (currentCategory != null) { - showDialog( - builder: (BuildContext context) => - _addCategoryDialog(context, currentCategory), - context: context) - .then((FruitCategory? category) { - if (category != null) { - setState(() { - // Remove the parent from the set of assigned categories, - // since it isn't a leaf anymore. - currentCategories.remove(currentCategory.value); - currentCategory.addChild(category); - // If they added a new category, they must mean that the - // category applies. - currentCategories.add(category.value); - }); - } - }); - } - }); - }, - ), - ), - ); - } -}