Skip to content

Commit

Permalink
Created a new Upgrader Card example for updating the messages.
Browse files Browse the repository at this point in the history
  • Loading branch information
larryaasen committed Sep 24, 2024
1 parent bcf10cd commit 7d08b0b
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
1 change: 1 addition & 0 deletions example/lib/main_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
75 changes: 75 additions & 0 deletions example/lib/main_card_updated.dart
Original file line number Diff line number Diff line change
@@ -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<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
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.';
}

0 comments on commit 7d08b0b

Please sign in to comment.