-
-
Notifications
You must be signed in to change notification settings - Fork 285
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BREAKING: Moved UI related code outside of Upgrader and into UpgradeA…
…lert and UpgradeCard. Also, renamed the private methods to make them public. Added and improved example code and README.
- Loading branch information
1 parent
23acdaf
commit a978f2d
Showing
17 changed files
with
367 additions
and
160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright (c) 2023 Larry Aasen. All rights reserved. | ||
|
||
import 'package:flutter/material.dart'; | ||
import 'package:upgrader/upgrader.dart'; | ||
|
||
void main() async { | ||
WidgetsFlutterBinding.ensureInitialized(); | ||
|
||
// 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()); | ||
} | ||
|
||
class MyApp extends StatelessWidget { | ||
MyApp({super.key}); | ||
|
||
final dark = ThemeData.dark(useMaterial3: true); | ||
|
||
final light = ThemeData( | ||
dialogTheme: DialogTheme( | ||
titleTextStyle: TextStyle(color: Colors.red, fontSize: 48), | ||
contentTextStyle: TextStyle(color: Colors.green, fontSize: 18), | ||
), | ||
// Change the text buttons. | ||
textButtonTheme: const TextButtonThemeData( | ||
style: ButtonStyle( | ||
// Change the color of the text buttons. | ||
foregroundColor: MaterialStatePropertyAll(Colors.orange), | ||
), | ||
), | ||
); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return MaterialApp( | ||
title: 'Upgrader Example', | ||
home: UpgradeAlert( | ||
child: Scaffold( | ||
appBar: AppBar(title: Text('Upgrader Example')), | ||
body: Center(child: Text('Checking...')), | ||
)), | ||
theme: light, | ||
darkTheme: dark, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
// Copyright (c) 2023 Larry Aasen. All rights reserved. | ||
|
||
import 'package:flutter/material.dart'; | ||
import 'package:upgrader/upgrader.dart'; | ||
|
||
void main() async { | ||
WidgetsFlutterBinding.ensureInitialized(); | ||
|
||
// 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()); | ||
} | ||
|
||
class MyApp extends StatelessWidget { | ||
MyApp({super.key}); | ||
|
||
final upgrader = MyUpgrader(debugLogging: true); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return MaterialApp( | ||
title: 'Upgrader Example', | ||
home: MyUpgradeAlert( | ||
upgrader: upgrader, | ||
child: Scaffold( | ||
appBar: AppBar(title: Text('Upgrader Example')), | ||
body: Center(child: Text('Checking...')), | ||
)), | ||
); | ||
} | ||
} | ||
|
||
class MyUpgrader extends Upgrader { | ||
MyUpgrader({super.debugLogging}); | ||
|
||
@override | ||
bool isTooSoon() { | ||
return super.isTooSoon(); | ||
} | ||
} | ||
|
||
class MyUpgradeAlert extends UpgradeAlert { | ||
MyUpgradeAlert({super.upgrader, super.child}); | ||
|
||
@override | ||
void showTheDialog({ | ||
required BuildContext context, | ||
required String? title, | ||
required String message, | ||
required String? releaseNotes, | ||
required bool canDismissDialog, | ||
required UpgraderMessages messages, | ||
}) { | ||
showDialog( | ||
context: context, | ||
builder: (BuildContext context) { | ||
return AlertDialog( | ||
title: const Text('Update?'), | ||
content: const SingleChildScrollView( | ||
child: ListBody( | ||
children: <Widget>[ | ||
Text('Would you like to update?'), | ||
], | ||
), | ||
), | ||
actions: <Widget>[ | ||
TextButton( | ||
child: const Text('No'), | ||
onPressed: () { | ||
onUserIgnored(context, true); | ||
}, | ||
), | ||
TextButton( | ||
child: const Text('Yes'), | ||
onPressed: () { | ||
onUserUpdated(context, !upgrader.blocked()); | ||
}, | ||
), | ||
], | ||
); | ||
}); | ||
} | ||
} |
Oops, something went wrong.