diff --git a/example/lib/main_card.dart b/example/lib/main_card.dart index 01d28117..a17056fd 100644 --- a/example/lib/main_card.dart +++ b/example/lib/main_card.dart @@ -21,6 +21,7 @@ class MyApp extends StatelessWidget { Widget build(BuildContext context) { return MaterialApp( title: 'Upgrader Card Example', + theme: ThemeData(colorScheme: const ColorScheme.light()), home: Scaffold( appBar: AppBar(title: const Text('Upgrader Card Example')), body: Container( diff --git a/example/lib/main_card_updated.dart b/example/lib/main_card_updated.dart new file mode 100644 index 00000000..a34165a5 --- /dev/null +++ b/example/lib/main_card_updated.dart @@ -0,0 +1,75 @@ +// Copyright (c) 2024 Larry Aasen. All rights reserved. + +import 'dart:async'; + +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 + + runApp(const MyApp()); +} + +class MyApp extends StatefulWidget { + const MyApp({super.key}); + + @override + State createState() => _MyAppState(); +} + +class _MyAppState extends State { + final _upgrader = Upgrader(); + + @override + void initState() { + Future.delayed(const Duration(seconds: 3), _updateMessages); + super.initState(); + } + + @override + Widget build(BuildContext context) { + return MaterialApp( + title: 'Upgrader Card Update Example', + theme: ThemeData(colorScheme: const ColorScheme.light()), + home: Scaffold( + appBar: AppBar(title: const Text('Upgrader Card Update Example')), + body: Container( + margin: const EdgeInsets.only(left: 12.0, right: 12.0), + child: SingleChildScrollView( + child: Column( + children: [ + _simpleCard, + _simpleCard, + UpgradeCard(upgrader: _upgrader), + _simpleCard, + _simpleCard, + ], + ), + ), + ), + ), + ); + } + + Widget get _simpleCard => const Card( + child: SizedBox( + width: 200, + height: 50, + child: Center(child: Text('Card')), + ), + ); + + void _updateMessages() { + _upgrader + .updateState(_upgrader.state.copyWith(messages: MyUpgraderMessages())); + } +} + +class MyUpgraderMessages extends UpgraderMessages { + @override + String get body => 'The message has been updated.'; +}