Skip to content

Commit

Permalink
First pass at moving the code that downloads version details from the…
Browse files Browse the repository at this point in the history
… app stores and Appcast to store controllers.
  • Loading branch information
larryaasen committed Jan 19, 2024
1 parent 66f3766 commit 8e626e5
Show file tree
Hide file tree
Showing 28 changed files with 620 additions and 424 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Tapping the UPDATE NOW button takes the user to the App Store (iOS) or Google Pl
Just wrap your home widget in the `UpgradeAlert` widget, and it will handle the rest.
```dart
class MyApp extends StatelessWidget {
const MyApp({Key key}) : super(key: key);
const MyApp({super.key});
@override
Widget build(BuildContext context) {
Expand Down
49 changes: 4 additions & 45 deletions example/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,47 +1,6 @@
include: package:flutter_lints/flutter.yaml

linter:
rules:
- always_declare_return_types
- always_require_non_null_named_parameters
- annotate_overrides
- avoid_empty_else
- avoid_init_to_null
- avoid_null_checks_in_equality_operators
- avoid_relative_lib_imports
- avoid_return_types_on_setters
- avoid_shadowing_type_parameters
- avoid_types_as_parameter_names
- camel_case_extensions
- curly_braces_in_flow_control_structures
- empty_catches
- empty_constructor_bodies
- library_names
- library_prefixes
- no_duplicate_case_values
- null_closures
- omit_local_variable_types
- prefer_adjacent_string_concatenation
- prefer_collection_literals
- prefer_conditional_assignment
- prefer_contains
- prefer_equal_for_default_values
- prefer_final_fields
- prefer_for_elements_to_map_fromIterable
- prefer_generic_function_type_aliases
- prefer_if_null_operators
- prefer_is_empty
- prefer_is_not_empty
- prefer_iterable_whereType
- prefer_single_quotes
- prefer_spread_collections
- recursive_getters
- slash_for_doc_comments
- type_init_formals
- unawaited_futures
- unnecessary_const
- unnecessary_new
- unnecessary_null_in_if_null_operators
- unnecessary_this
- unrelated_type_equality_checks
- use_function_type_syntax_for_parameters
- use_rethrow_when_possible
- valid_regexps
avoid_function_literals_in_foreach_calls: false
avoid_print: false
9 changes: 5 additions & 4 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ void main() async {
// On iOS, the default behavior will be to use the App Store version of
// the app, so update the Bundle Identifier in example/ios/Runner with a
// valid identifier already in the App Store.
runApp(MyApp());
runApp(const MyApp());
}

class MyApp extends StatelessWidget {
Expand All @@ -27,10 +27,11 @@ class MyApp extends StatelessWidget {
return MaterialApp(
title: 'Upgrader Example',
home: UpgradeAlert(
upgrader: Upgrader(debugLogging: true),
child: Scaffold(
appBar: AppBar(title: Text('Upgrader Example')),
body: Center(child: Text('Checking...')),
)),
appBar: AppBar(title: const Text('Upgrader Example')),
body: const Center(child: Text('Checking...')),
)),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class MyApp extends StatelessWidget {
final dark = ThemeData.dark(useMaterial3: true);

final light = ThemeData(
dialogTheme: DialogTheme(
dialogTheme: const DialogTheme(
titleTextStyle: TextStyle(color: Colors.red, fontSize: 48),
contentTextStyle: TextStyle(color: Colors.green, fontSize: 18),
),
Expand All @@ -42,8 +42,8 @@ class MyApp extends StatelessWidget {
title: 'Upgrader Example',
home: UpgradeAlert(
child: Scaffold(
appBar: AppBar(title: Text('Upgrader Alert Theme Example')),
body: Center(child: Text('Checking...')),
appBar: AppBar(title: const Text('Upgrader Alert Theme Example')),
body: const Center(child: Text('Checking...')),
)),
theme: light,
darkTheme: dark,
Expand Down
12 changes: 7 additions & 5 deletions example/lib/main-appcast.dart → example/lib/main_appcast.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,25 @@ void main() async {
}

class MyApp extends StatelessWidget {
MyApp({Key? key}) : super(key: key);
MyApp({super.key});

static const appcastURL =
'https://raw.githubusercontent.com/larryaasen/upgrader/master/test/testappcast.xml';
final upgrader = Upgrader(
appcastConfig:
AppcastConfiguration(url: appcastURL, supportedOS: ['android']));
storeController: UpgraderStoreController(
onAndroid: () => UpgraderAppcastStore(appcastURL: appcastURL),
),
);

@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Upgrader Example',
home: Scaffold(
appBar: AppBar(title: Text('Upgrader Appcast Example')),
appBar: AppBar(title: const Text('Upgrader Appcast Example')),
body: UpgradeAlert(
upgrader: upgrader,
child: Center(child: Text('Checking...')),
child: const Center(child: Text('Checking...')),
)),
);
}
Expand Down
13 changes: 4 additions & 9 deletions example/lib/main-card.dart → example/lib/main_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,7 @@ void main() async {
// Only call clearSavedSettings() during testing to reset internal values.
await Upgrader.clearSavedSettings(); // REMOVE this for release builds

// On Android, the default behavior will be to use the Google Play Store
// version of the app.
// On iOS, the default behavior will be to use the App Store version of
// the app, so update the Bundle Identifier in example/ios/Runner with a
// valid identifier already in the App Store.
runApp(MyApp());
runApp(const MyApp());
}

class MyApp extends StatelessWidget {
Expand All @@ -27,9 +22,9 @@ class MyApp extends StatelessWidget {
return MaterialApp(
title: 'Upgrader Card Example',
home: Scaffold(
appBar: AppBar(title: Text('Upgrader Card Example')),
appBar: AppBar(title: const Text('Upgrader Card Example')),
body: Container(
margin: EdgeInsets.only(left: 12.0, right: 12.0),
margin: const EdgeInsets.only(left: 12.0, right: 12.0),
child: SingleChildScrollView(
child: Column(
children: [
Expand All @@ -46,7 +41,7 @@ class MyApp extends StatelessWidget {
);
}

Widget get _simpleCard => Card(
Widget get _simpleCard => const Card(
child: SizedBox(
width: 200,
height: 50,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ void main() async {
// Only call clearSavedSettings() during testing to reset internal values.
await Upgrader.clearSavedSettings(); // REMOVE this for release builds

// On Android, the default behavior will be to use the Google Play Store
// version of the app.
// On iOS, the default behavior will be to use the App Store version of
// the app, so update the Bundle Identifier in example/ios/Runner with a
// valid identifier already in the App Store.
runApp(MyApp());
}

Expand All @@ -23,7 +18,7 @@ class MyApp extends StatelessWidget {
final dark = ThemeData.dark(useMaterial3: true);

final light = ThemeData(
cardTheme: CardTheme(color: Colors.greenAccent),
cardTheme: const CardTheme(color: Colors.greenAccent),
// Change the text buttons.
textButtonTheme: const TextButtonThemeData(
style: ButtonStyle(
Expand All @@ -38,9 +33,9 @@ class MyApp extends StatelessWidget {
return MaterialApp(
title: 'Upgrader Card Example',
home: Scaffold(
appBar: AppBar(title: Text('Upgrader Card Theme Example')),
appBar: AppBar(title: const Text('Upgrader Card Theme Example')),
body: Container(
margin: EdgeInsets.only(left: 12.0, right: 12.0),
margin: const EdgeInsets.only(left: 12.0, right: 12.0),
child: SingleChildScrollView(
child: Column(
children: [
Expand All @@ -59,7 +54,7 @@ class MyApp extends StatelessWidget {
);
}

Widget get _simpleCard => Card(
Widget get _simpleCard => const Card(
child: SizedBox(
width: 200,
height: 50,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,21 @@ void main() async {
// Only call clearSavedSettings() during testing to reset internal values.
await Upgrader.clearSavedSettings(); // REMOVE this for release builds

// On Android, setup the Appcast.
// On iOS, the default behavior will be to use the App Store version of
// the app, so update the Bundle Identifier in example/ios/Runner with a
// valid identifier already in the App Store.
runApp(MyApp());
runApp(const MyApp());
}

class MyApp extends StatelessWidget {
MyApp({Key? key}) : super(key: key);
const MyApp({super.key});

@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Upgrader Example',
home: Scaffold(
appBar: AppBar(title: Text('Upgrader Cupertino Example')),
appBar: AppBar(title: const Text('Upgrader Cupertino Example')),
body: UpgradeAlert(
dialogStyle: UpgradeDialogStyle.cupertino,
child: Center(child: Text('Checking...')),
child: const Center(child: Text('Checking...')),
),
),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ void main() async {
// Only call clearSavedSettings() during testing to reset internal values.
await Upgrader.clearSavedSettings(); // REMOVE this for release builds

// On Android, the default behavior will be to use the Google Play Store
// version of the app.
// On iOS, the default behavior will be to use the App Store version of
// the app, so update the Bundle Identifier in example/ios/Runner with a
// valid identifier already in the App Store.
runApp(MyApp());
}

Expand All @@ -29,8 +24,8 @@ class MyApp extends StatelessWidget {
home: MyUpgradeAlert(
upgrader: upgrader,
child: Scaffold(
appBar: AppBar(title: Text('Upgrader Custom Alert Example')),
body: Center(child: Text('Checking...')),
appBar: AppBar(title: const Text('Upgrader Custom Alert Example')),
body: const Center(child: Text('Checking...')),
)),
);
}
Expand All @@ -39,23 +34,18 @@ class MyApp extends StatelessWidget {
class MyUpgrader extends Upgrader {
MyUpgrader({super.debugLogging});

@override
bool isTooSoon() {
return super.isTooSoon();
}

@override
bool isUpdateAvailable() {
final appStoreVersion = currentAppStoreVersion;
final storeVersion = currentAppStoreVersion;
final installedVersion = currentInstalledVersion;
print('appStoreVersion=$appStoreVersion');
print('storeVersion=$storeVersion');
print('installedVersion=$installedVersion');
return super.isUpdateAvailable();
}
}

class MyUpgradeAlert extends UpgradeAlert {
MyUpgradeAlert({super.upgrader, super.child});
MyUpgradeAlert({super.key, super.upgrader, super.child});

/// Override the [createState] method to provide a custom class
/// with overridden methods.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,7 @@ void main() async {
// Only call clearSavedSettings() during testing to reset internal values.
await Upgrader.clearSavedSettings(); // REMOVE this for release builds

// On Android, the default behavior will be to use the Google Play Store
// version of the app.
// On iOS, the default behavior will be to use the App Store version of
// the app, so update the Bundle Identifier in example/ios/Runner with a
// valid identifier already in the App Store.
runApp(MyApp());
runApp(const MyApp());
}

class MyApp extends StatelessWidget {
Expand All @@ -25,9 +20,9 @@ class MyApp extends StatelessWidget {
return MaterialApp(
title: 'Upgrader Example',
home: Scaffold(
appBar: AppBar(title: Text('Upgrader Custom Card Example')),
appBar: AppBar(title: const Text('Upgrader Custom Card Example')),
body: Container(
margin: EdgeInsets.only(left: 12.0, right: 12.0),
margin: const EdgeInsets.only(left: 12.0, right: 12.0),
child: SingleChildScrollView(
child: Column(
children: [
Expand All @@ -44,7 +39,7 @@ class MyApp extends StatelessWidget {
);
}

Widget get _simpleCard => Card(
Widget get _simpleCard => const Card(
child: SizedBox(
width: 200,
height: 50,
Expand All @@ -54,7 +49,7 @@ class MyApp extends StatelessWidget {
}

class MyUpgradeCard extends UpgradeCard {
MyUpgradeCard({super.upgrader});
MyUpgradeCard({super.key, super.upgrader});

/// Override the [createState] method to provide a custom class
/// with overridden methods.
Expand All @@ -80,7 +75,7 @@ class MyUpgradeCardState extends UpgradeCardState {
},
),
],
content: Text(''),
content: const Text(''),
title: Text(title ?? ''),
),
);
Expand Down
15 changes: 7 additions & 8 deletions example/lib/main_dialog_key.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,12 @@ void main() async {
// Only call clearSavedSettings() during testing to reset internal values.
await Upgrader.clearSavedSettings(); // REMOVE this for release builds

final log =
() => print('$dialogKey mounted=${dialogKey.currentContext?.mounted}');
unawaited(Future.delayed(Duration(seconds: 0)).then((value) => log()));
unawaited(Future.delayed(Duration(seconds: 3)).then((value) => log()));
unawaited(Future.delayed(Duration(seconds: 4)).then((value) => log()));
log() => print('$dialogKey mounted=${dialogKey.currentContext?.mounted}');
unawaited(Future.delayed(const Duration(seconds: 0)).then((value) => log()));
unawaited(Future.delayed(const Duration(seconds: 3)).then((value) => log()));
unawaited(Future.delayed(const Duration(seconds: 4)).then((value) => log()));

runApp(MyApp());
runApp(const MyApp());
}

class MyApp extends StatelessWidget {
Expand All @@ -32,8 +31,8 @@ class MyApp extends StatelessWidget {
home: UpgradeAlert(
dialogKey: dialogKey,
child: Scaffold(
appBar: AppBar(title: Text('Upgrader Example')),
body: Center(child: Text('Checking...')),
appBar: AppBar(title: const Text('Upgrader Example')),
body: const Center(child: Text('Checking...')),
)),
);
}
Expand Down
Loading

0 comments on commit 8e626e5

Please sign in to comment.