updatify_flutter 1.1.0
updatify_flutter: ^1.1.0 copied to clipboard
A Flutter widget for displaying release notes, product updates, and announcements from the Updatify service.
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:updatify_flutter/updatify_flutter.dart';
void main() {
runApp(const App());
}
class App extends StatefulWidget {
const App({super.key});
@override
State<App> createState() => _AppState();
}
class _AppState extends State<App> {
static const _projectId = '3593f6b9-92de-4b32-941f-e152062745bb';
ThemeMode _themeMode = ThemeMode.light;
Key _triggerKey = UniqueKey();
late final TapGestureRecognizer _resetRecognizer = TapGestureRecognizer()
..onTap = _resetViewed;
@override
void dispose() {
_resetRecognizer.dispose();
super.dispose();
}
void _toggleTheme() {
setState(() {
_themeMode =
_themeMode == ThemeMode.light ? ThemeMode.dark : ThemeMode.light;
});
}
Future<void> _resetViewed() async {
await UpdatifyTrigger.resetLastViewed(_projectId);
setState(() => _triggerKey = UniqueKey());
}
Future<void> _onShowDialog(BuildContext context) => showUpdatifyDialog(
context,
projectId: _projectId,
itemDecoration: UpdatifyPostDecoration(),
borderRadius: BorderRadius.circular(6),
width: _dialogWidth(context),
);
// Half the screen on wide/desktop layouts; null keeps the default full-width
// dialog on narrow/mobile layouts.
double? _dialogWidth(BuildContext context) {
final width = MediaQuery.sizeOf(context).width;
return width >= 600 ? width / 2 : null;
}
@override
Widget build(BuildContext context) {
final isDark = _themeMode == ThemeMode.dark;
return MaterialApp(
theme: ThemeData(brightness: Brightness.light),
darkTheme: ThemeData(brightness: Brightness.dark),
themeMode: _themeMode,
home: Scaffold(
appBar: AppBar(
title: const Text('Updatify'),
actions: [
IconButton(
tooltip: isDark ? 'Switch to light mode' : 'Switch to dark mode',
icon: Icon(isDark ? Icons.light_mode : Icons.dark_mode),
onPressed: _toggleTheme,
),
],
),
body: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
spacing: 16,
children: [
Row(
mainAxisSize: MainAxisSize.min,
spacing: 8,
children: [
Builder(
builder: (context) => UpdatifyTrigger(
key: _triggerKey,
projectId: _projectId,
borderRadius: BorderRadius.circular(6),
width: _dialogWidth(context),
),
),
Text("<- Clickable button to open widget with release notes")
],
),
Row(
mainAxisSize: MainAxisSize.min,
children: [
Text.rich(
TextSpan(
children: [
TextSpan(
text: 'Reset viewed posts',
style: TextStyle(
decoration: TextDecoration.underline,
color: Theme.of(context).colorScheme.primary,
),
recognizer: _resetRecognizer,
),
const TextSpan(text: ' to show ping animation'),
],
),
),
]),
Builder(
builder: (context) => ElevatedButton(
onPressed: () => _onShowDialog(context),
child: const Text('Show release notes'),
),
),
],
),
),
),
);
}
}