diff --git a/example/lib/01_simple_text_sample/main.dart b/example/lib/01_simple_text_sample/main.dart index 2bec605..a62da22 100644 --- a/example/lib/01_simple_text_sample/main.dart +++ b/example/lib/01_simple_text_sample/main.dart @@ -1,13 +1,13 @@ -import 'dart:async'; import 'package:app/01_simple_text_sample/simple_text_sample.dart'; import 'package:flutter/material.dart'; void main() { - runApp(MyApp()); + runApp(const MyApp()); } class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); @override Widget build(BuildContext context) { @@ -15,7 +15,7 @@ class MyApp extends StatelessWidget { return MaterialApp( theme: ThemeData(fontFamily: 'IranSans'), debugShowCheckedModeBanner: false, - home: TextSample() + home: const TextSample() ); } } diff --git a/example/lib/01_simple_text_sample/simple_text_sample.dart b/example/lib/01_simple_text_sample/simple_text_sample.dart index 3cb2301..07fc79f 100644 --- a/example/lib/01_simple_text_sample/simple_text_sample.dart +++ b/example/lib/01_simple_text_sample/simple_text_sample.dart @@ -1,8 +1,9 @@ import 'package:flutter/material.dart'; -import 'package:telescope/src/telescope.dart'; +import 'package:telescope/telescope.dart'; class TextSample extends StatefulWidget { + const TextSample({Key? key}) : super(key: key); @override State createState() => TextSampleState(); @@ -16,7 +17,6 @@ class TextSampleState extends State { Widget build(BuildContext context) { var style = const TextStyle(fontSize: 60); - print("build"); return Material( type: MaterialType.transparency, child: SafeArea( diff --git a/example/lib/02_object_apply_sample/main.dart b/example/lib/02_object_apply_sample/main.dart index 1842b44..f35e3db 100644 --- a/example/lib/02_object_apply_sample/main.dart +++ b/example/lib/02_object_apply_sample/main.dart @@ -14,13 +14,17 @@ class Human{ @override int get hashCode => (name.hashCode) * age.hashCode; + + @override + bool operator ==(Object other) => hashCode==other.hashCode; } void main() { - runApp(MyApp()); + runApp(const MyApp()); } class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); @override Widget build(BuildContext context) { @@ -28,7 +32,7 @@ class MyApp extends StatelessWidget { return MaterialApp( theme: ThemeData(fontFamily: 'IranSans'), debugShowCheckedModeBanner: false, - home: ObjectApplySampleLayout() + home: const ObjectApplySampleLayout() ); } } diff --git a/example/lib/02_object_apply_sample/object_apply_sample.dart b/example/lib/02_object_apply_sample/object_apply_sample.dart index 109be9c..3474e54 100644 --- a/example/lib/02_object_apply_sample/object_apply_sample.dart +++ b/example/lib/02_object_apply_sample/object_apply_sample.dart @@ -1,9 +1,10 @@ import 'package:app/02_object_apply_sample/main.dart'; import 'package:flutter/material.dart'; -import 'package:telescope/src/telescope.dart'; +import 'package:telescope/telescope.dart'; class ObjectApplySampleLayout extends StatefulWidget { + const ObjectApplySampleLayout({Key? key}) : super(key: key); @override State createState() => ObjectApplySampleLayoutState(); @@ -15,8 +16,6 @@ class ObjectApplySampleLayoutState extends State { @override Widget build(BuildContext context) { - - print("build"); return Material( type: MaterialType.transparency, child: SafeArea( diff --git a/example/lib/03_depend_observable_sample/depends_on_sample.dart b/example/lib/03_depend_observable_sample/depends_on_sample.dart index c2a3b39..fdb15ee 100644 --- a/example/lib/03_depend_observable_sample/depends_on_sample.dart +++ b/example/lib/03_depend_observable_sample/depends_on_sample.dart @@ -1,8 +1,10 @@ import 'package:flutter/material.dart'; -import 'package:telescope/src/telescope.dart'; +import 'package:telescope/telescope.dart'; class DependObservableSampleLayout extends StatefulWidget { + const DependObservableSampleLayout({Key? key}) : super(key: key); + @override State createState() => DependObservableSampleLayoutState(); } @@ -35,7 +37,6 @@ class DependObservableSampleLayoutState extends State createState() => SaveOnDiskSampleLayoutState(); } @@ -26,7 +28,6 @@ class SaveOnDiskSampleLayoutState extends State { Widget build(BuildContext context) { var style = const TextStyle(fontSize: 40); - print("build"); return Material( type: MaterialType.transparency, child: SafeArea( diff --git a/example/lib/04_2_save_non_built_in_on_disk/main.dart b/example/lib/04_2_save_non_built_in_on_disk/main.dart index aa39e4c..721ce77 100644 --- a/example/lib/04_2_save_non_built_in_on_disk/main.dart +++ b/example/lib/04_2_save_non_built_in_on_disk/main.dart @@ -2,10 +2,11 @@ import 'package:flutter/material.dart'; import './save_non_built_in_on_disk_sample.dart'; void main() { - runApp(MyApp()); + runApp(const MyApp()); } class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); @override Widget build(BuildContext context) { @@ -13,7 +14,7 @@ class MyApp extends StatelessWidget { return MaterialApp( theme: ThemeData(fontFamily: 'IranSans'), debugShowCheckedModeBanner: false, - home: SaveNonBuiltInOnDiskSampleLayout() + home: const SaveNonBuiltInOnDiskSampleLayout() ); } } diff --git a/example/lib/04_2_save_non_built_in_on_disk/save_non_built_in_on_disk_sample.dart b/example/lib/04_2_save_non_built_in_on_disk/save_non_built_in_on_disk_sample.dart index e31faf3..d6dd429 100644 --- a/example/lib/04_2_save_non_built_in_on_disk/save_non_built_in_on_disk_sample.dart +++ b/example/lib/04_2_save_non_built_in_on_disk/save_non_built_in_on_disk_sample.dart @@ -8,6 +8,9 @@ class Human{ @override int get hashCode => height*weight; + + @override + bool operator ==(Object other) => hashCode==other.hashCode; } class HumanOnDiskAbility implements OnDiskSaveAbility{ @override @@ -22,6 +25,8 @@ class HumanOnDiskAbility implements OnDiskSaveAbility{ class SaveNonBuiltInOnDiskSampleLayout extends StatefulWidget { + const SaveNonBuiltInOnDiskSampleLayout({Key? key}) : super(key: key); + @override State createState() => SaveNonBuiltInOnDiskSampleLayoutState(); } @@ -44,7 +49,6 @@ class SaveNonBuiltInOnDiskSampleLayoutState extends State text; - InputLayout(this.text); + final Telescope text; + const InputLayout(this.text, {Key? key}) : super(key: key); @override State createState() => InputLayoutState(); @@ -14,8 +14,6 @@ class InputLayoutState extends State { @override Widget build(BuildContext context) { - - print("input build"); return TextField( controller: TextEditingController(text: ""), onChanged: (content){ diff --git a/example/lib/05_share_telescope_as_param/main.dart b/example/lib/05_share_telescope_as_param/main.dart index 500c32a..d4deee6 100644 --- a/example/lib/05_share_telescope_as_param/main.dart +++ b/example/lib/05_share_telescope_as_param/main.dart @@ -2,10 +2,11 @@ import 'package:app/05_share_telescope_as_param/parent.dart'; import 'package:flutter/material.dart'; void main() { - runApp(MyApp()); + runApp(const MyApp()); } class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); @override Widget build(BuildContext context) { @@ -13,7 +14,7 @@ class MyApp extends StatelessWidget { return MaterialApp( theme: ThemeData(fontFamily: 'IranSans'), debugShowCheckedModeBanner: false, - home: ParentLayout() + home: const ParentLayout() ); } } diff --git a/example/lib/05_share_telescope_as_param/output_child.dart b/example/lib/05_share_telescope_as_param/output_child.dart index bcedafb..7cfe2fc 100644 --- a/example/lib/05_share_telescope_as_param/output_child.dart +++ b/example/lib/05_share_telescope_as_param/output_child.dart @@ -1,10 +1,10 @@ import 'package:flutter/material.dart'; -import 'package:telescope/src/telescope.dart'; +import 'package:telescope/telescope.dart'; class OutputLayout extends StatefulWidget { - Telescope text; - OutputLayout(this.text); + final Telescope text; + const OutputLayout(this.text, {Key? key}) : super(key: key); @override State createState() => OutputLayoutState(); @@ -14,8 +14,6 @@ class OutputLayoutState extends State { @override Widget build(BuildContext context) { - - print("output build"); return Text(widget.text.watch(this)); } } diff --git a/example/lib/05_share_telescope_as_param/parent.dart b/example/lib/05_share_telescope_as_param/parent.dart index e455320..533aa0a 100644 --- a/example/lib/05_share_telescope_as_param/parent.dart +++ b/example/lib/05_share_telescope_as_param/parent.dart @@ -5,6 +5,8 @@ import 'package:telescope/telescope.dart'; class ParentLayout extends StatefulWidget { + const ParentLayout({Key? key}) : super(key: key); + @override State createState() => ParentLayoutState(); } @@ -15,8 +17,6 @@ class ParentLayoutState extends State { @override Widget build(BuildContext context) { - - print("parent build"); return Material( type: MaterialType.transparency, child: SafeArea( diff --git a/example/lib/06_1_list/list_sample.dart b/example/lib/06_1_list/list_sample.dart index 4940d53..f1e9b08 100644 --- a/example/lib/06_1_list/list_sample.dart +++ b/example/lib/06_1_list/list_sample.dart @@ -1,10 +1,11 @@ import 'package:flutter/material.dart'; -import 'package:telescope/src/telescope.dart'; import 'package:telescope/telescope.dart'; import 'dart:math'; class ListSampleLayout extends StatefulWidget { + const ListSampleLayout({Key? key}) : super(key: key); + @override State createState() => ListSampleLayoutState(); } @@ -30,7 +31,6 @@ class ListSampleLayoutState extends State { @override Widget build(BuildContext context) { - print("build"); return Material( type: MaterialType.transparency, child: SafeArea( diff --git a/example/lib/06_1_list/main.dart b/example/lib/06_1_list/main.dart index 84351bb..966cda7 100644 --- a/example/lib/06_1_list/main.dart +++ b/example/lib/06_1_list/main.dart @@ -2,10 +2,12 @@ import './list_sample.dart'; import 'package:flutter/material.dart'; void main() { - runApp(MyApp()); + runApp(const MyApp()); } class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + @override Widget build(BuildContext context) { @@ -13,7 +15,7 @@ class MyApp extends StatelessWidget { return MaterialApp( theme: ThemeData(fontFamily: 'IranSans'), debugShowCheckedModeBanner: false, - home: ListSampleLayout() + home: const ListSampleLayout() ); } } diff --git a/example/lib/06_2_list_on_disk/list_sample_on_disk.dart b/example/lib/06_2_list_on_disk/list_sample_on_disk.dart index 15a33db..e356fb8 100644 --- a/example/lib/06_2_list_on_disk/list_sample_on_disk.dart +++ b/example/lib/06_2_list_on_disk/list_sample_on_disk.dart @@ -1,10 +1,11 @@ import 'package:flutter/material.dart'; -import 'package:telescope/src/telescope.dart'; import 'package:telescope/telescope.dart'; import 'dart:math'; class ListSampleOnDiskLayout extends StatefulWidget { + const ListSampleOnDiskLayout({Key? key}) : super(key: key); + @override State createState() => ListSampleOnDiskLayoutState(); } @@ -29,8 +30,6 @@ class ListSampleOnDiskLayoutState extends State { @override Widget build(BuildContext context) { - - print("build"); return Material( type: MaterialType.transparency, child: SafeArea( diff --git a/example/lib/06_2_list_on_disk/main.dart b/example/lib/06_2_list_on_disk/main.dart index 033a697..1a076d0 100644 --- a/example/lib/06_2_list_on_disk/main.dart +++ b/example/lib/06_2_list_on_disk/main.dart @@ -2,10 +2,12 @@ import './list_sample_on_disk.dart'; import 'package:flutter/material.dart'; void main() { - runApp(MyApp()); + runApp(const MyApp()); } class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + @override Widget build(BuildContext context) { @@ -13,7 +15,7 @@ class MyApp extends StatelessWidget { return MaterialApp( theme: ThemeData(fontFamily: 'IranSans'), debugShowCheckedModeBanner: false, - home: ListSampleOnDiskLayout() + home: const ListSampleOnDiskLayout() ); } } diff --git a/example/lib/06_3_non_built_in_list_on_disk/list_non_built_in_on_disk_sample.dart b/example/lib/06_3_non_built_in_list_on_disk/list_non_built_in_on_disk_sample.dart index f919f5b..0e8f68c 100644 --- a/example/lib/06_3_non_built_in_list_on_disk/list_non_built_in_on_disk_sample.dart +++ b/example/lib/06_3_non_built_in_list_on_disk/list_non_built_in_on_disk_sample.dart @@ -1,5 +1,4 @@ import 'package:flutter/material.dart'; -import 'package:telescope/src/telescope.dart'; import 'package:telescope/telescope.dart'; class Contact{ @@ -9,6 +8,9 @@ class Contact{ @override int get hashCode => name.hashCode * phone.hashCode; + + @override + bool operator ==(Object other)=> hashCode==other.hashCode; } class ContactOnDiskAbility implements OnDiskSaveAbility{ @override @@ -22,6 +24,8 @@ class ContactOnDiskAbility implements OnDiskSaveAbility{ } class ListNonBuiltInOnDiskSample extends StatefulWidget { + const ListNonBuiltInOnDiskSample({Key? key}) : super(key: key); + @override State createState() => ListNonBuiltInOnDiskSampleState(); } @@ -50,8 +54,6 @@ class ListNonBuiltInOnDiskSampleState extends State @override Widget build(BuildContext context) { - - print("build"); return Material( type: MaterialType.transparency, child: SafeArea( diff --git a/example/lib/06_3_non_built_in_list_on_disk/main.dart b/example/lib/06_3_non_built_in_list_on_disk/main.dart index 743c831..64a11c8 100644 --- a/example/lib/06_3_non_built_in_list_on_disk/main.dart +++ b/example/lib/06_3_non_built_in_list_on_disk/main.dart @@ -2,10 +2,12 @@ import './list_non_built_in_on_disk_sample.dart'; import 'package:flutter/material.dart'; void main() { - runApp(MyApp()); + runApp(const MyApp()); } class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + @override Widget build(BuildContext context) { @@ -13,7 +15,7 @@ class MyApp extends StatelessWidget { return MaterialApp( theme: ThemeData(fontFamily: 'IranSans'), debugShowCheckedModeBanner: false, - home: ListNonBuiltInOnDiskSample() + home: const ListNonBuiltInOnDiskSample() ); } } diff --git a/example/lib/07_multi_language_and_theme/i18n.dart b/example/lib/07_multi_language_and_theme/i18n.dart index a31d4ae..f862c59 100644 --- a/example/lib/07_multi_language_and_theme/i18n.dart +++ b/example/lib/07_multi_language_and_theme/i18n.dart @@ -4,15 +4,15 @@ import 'package:telescope/telescope.dart'; // I18 is actually short form of "Internationalization" class I18n{ - static const ENGLISH = "en"; - static const PERSIAN = "pe"; + static const english = "en"; + static const persian = "pe"; - static var language = Telescope.saveOnDiskForBuiltInType(ENGLISH, "app_language"); + static var language = Telescope.saveOnDiskForBuiltInType(english, "app_language"); static toggleLanguage(){ - language.value = language.value==ENGLISH ? PERSIAN : ENGLISH; + language.value = language.value==english ? persian : english; } - static var hello = Telescope.dependsOn([language],()=>language.value==ENGLISH ? "hello" : "سلام"); - static var bye = Telescope.dependsOn([language],()=>language.value==ENGLISH ? "bye" : "خدانگهدار"); + static var hello = Telescope.dependsOn([language],()=>language.value==english ? "hello" : "سلام"); + static var bye = Telescope.dependsOn([language],()=>language.value==english ? "bye" : "خدانگهدار"); } \ No newline at end of file diff --git a/example/lib/07_multi_language_and_theme/main.dart b/example/lib/07_multi_language_and_theme/main.dart index f62ab70..38a9b0c 100644 --- a/example/lib/07_multi_language_and_theme/main.dart +++ b/example/lib/07_multi_language_and_theme/main.dart @@ -2,10 +2,12 @@ import './multi_language_and_theme.dart'; import 'package:flutter/material.dart'; void main() { - runApp(MyApp()); + runApp(const MyApp()); } class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + @override Widget build(BuildContext context) { @@ -13,7 +15,7 @@ class MyApp extends StatelessWidget { return MaterialApp( theme: ThemeData(fontFamily: 'IranSans'), debugShowCheckedModeBanner: false, - home: MultiLanguageAndThemeSample() + home: const MultiLanguageAndThemeSample() ); } } diff --git a/example/lib/07_multi_language_and_theme/multi_language_and_theme.dart b/example/lib/07_multi_language_and_theme/multi_language_and_theme.dart index 630ba1d..c816d11 100644 --- a/example/lib/07_multi_language_and_theme/multi_language_and_theme.dart +++ b/example/lib/07_multi_language_and_theme/multi_language_and_theme.dart @@ -3,6 +3,8 @@ import 'package:app/07_multi_language_and_theme/theme.dart'; import 'package:flutter/material.dart'; class MultiLanguageAndThemeSample extends StatefulWidget { + const MultiLanguageAndThemeSample({Key? key}) : super(key: key); + @override State createState() => MultiLanguageAndThemeSampleState(); } @@ -11,8 +13,6 @@ class MultiLanguageAndThemeSampleState extends State(String onDiskId, T value, OnDiskSaveAbility? onDiskSaveAbility){ - onDiskId += PREFIX; + onDiskId += prefix; SharedPreferences.getInstance().then((pref){ switch(T){ @@ -29,7 +29,7 @@ class SaveAndLoad{ static load(OnDiskSaveAbility? onDiskSaveAbility, String onDiskId, void Function(T loaded) callback){ - onDiskId += PREFIX; + onDiskId += prefix; SharedPreferences.getInstance().then((pref){ // not assign while its not on disk yet (keeps default value) @@ -52,10 +52,10 @@ class SaveAndLoad{ // list save and load - static const String SEP = '~'; + static const String sep = '~'; static saveList(String onDiskId, List items, OnDiskSaveAbility? onDiskSaveAbility){ - onDiskId += PREFIX; + onDiskId += prefix; var stringifies = items.map((i){ var itemString = ""; @@ -64,8 +64,8 @@ class SaveAndLoad{ }else{ itemString = i.toString(); } - return itemString.replaceAll(SEP, "\\$SEP"); - }).join("-$SEP"); + return itemString.replaceAll(sep, "\\$sep"); + }).join("-$sep"); SharedPreferences.getInstance().then((pref){ pref.setString(onDiskId, stringifies).then((value){}); }); @@ -73,13 +73,13 @@ class SaveAndLoad{ static loadList(String onDiskId, OnDiskSaveAbility? onDiskSaveAbility, void Function(List loaded) callback){ - onDiskId += PREFIX; + onDiskId += prefix; SharedPreferences.getInstance().then((pref){ if(!pref.containsKey(onDiskId)){ return; } callback( - pref.getString(onDiskId)!.split("-$SEP").map((i){ - i = i.replaceAll("\\$SEP", SEP); + pref.getString(onDiskId)!.split("-$sep").map((i){ + i = i.replaceAll("\\$sep", sep); switch(T){ case bool: return (i == "true") as T; case int: return (int.parse(i)) as T; diff --git a/lib/src/telescope.dart b/lib/src/telescope.dart index 7fa48d9..8d670f6 100644 --- a/lib/src/telescope.dart +++ b/lib/src/telescope.dart @@ -129,9 +129,7 @@ class Telescope{ try{ // it may crash while widget is not mounted callback((){}); - } catch(e) { - print(e); - } + } catch(e) {/*ignore*/} }else{ callback(); // this will make State call build in next frame render } diff --git a/pubspec.yaml b/pubspec.yaml index b4bc354..d0af841 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -2,6 +2,7 @@ name: telescope description: A simple and easy to use state manager for flutter. version: 1.0.0 repository: https://github.com/ali77gh/Telescope +homepage: https://github.com/ali77gh/Telescope environment: sdk: ">=2.17.0 <3.0.0" @@ -17,46 +18,4 @@ dev_dependencies: sdk: flutter flutter_lints: ^2.0.0 -# For information on the generic Dart part of this file, see the -# following page: https://dart.dev/tools/pub/pubspec - -# The following section is specific to Flutter packages. flutter: - plugin: - platforms: - linux: - windows: - macos: - android: - web: - ios: - # To add assets to your package, add an assets section, like this: - # assets: - # - images/a_dot_burr.jpeg - # - images/a_dot_ham.jpeg - # - # For details regarding assets in packages, see - # https://flutter.dev/assets-and-images/#from-packages - # - # An image asset can refer to one or more resolution-specific "variants", see - # https://flutter.dev/assets-and-images/#resolution-aware - - # To add custom fonts to your package, add a fonts section here, - # in this "flutter" section. Each entry in this list should have a - # "family" key with the font family name, and a "fonts" key with a - # list giving the asset and other descriptors for the font. For - # example: - # fonts: - # - family: Schyler - # fonts: - # - asset: fonts/Schyler-Regular.ttf - # - asset: fonts/Schyler-Italic.ttf - # style: italic - # - family: Trajan Pro - # fonts: - # - asset: fonts/TrajanPro.ttf - # - asset: fonts/TrajanPro_Bold.ttf - # weight: 700 - # - # For details regarding fonts in packages, see - # https://flutter.dev/custom-fonts/#from-packages diff --git a/test/telescope_test.dart b/test/telescope_test.dart index 66ae971..2996b37 100644 --- a/test/telescope_test.dart +++ b/test/telescope_test.dart @@ -1,5 +1,3 @@ -import 'package:flutter/material.dart'; -import 'package:flutter_test/flutter_test.dart'; // void main() { // test('adds one to input values', () {