update_center 1.0.0-beta.1 copy "update_center: ^1.0.0-beta.1" to clipboard
update_center: ^1.0.0-beta.1 copied to clipboard

A package that allows you to implement your own update system for your application.

example/lib/main.dart

import 'package:dynamic_color/dynamic_color.dart';
import 'package:flutter/material.dart';
import 'package:update_center/update_center.dart';

void main() {
  runApp(
    // You don't have to do this to test Material dialogs
    DynamicColorBuilder(
        builder: (ColorScheme? lightDynamic, ColorScheme? darkDynamic) {
      return MaterialApp(
          debugShowCheckedModeBanner: false,
          theme: ThemeData(
            colorScheme: darkDynamic,
          ),
          home: const MyApp());
    }),
  );
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  late UpdateCenter updateCenter;

  @override
  void initState() {
    initializeUpdateCenter();
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Update Center v1.0.0-alpha.6'),
      ),
      body: Center(
          child: OutlinedButton(
        onPressed: () =>
            checkUpdate(), // You can check for updates using the button
        child: const Text('Check update'),
      )),
    );
  }

  void initializeUpdateCenter() {
    // Main plugin settings
    updateCenter = UpdateCenter(
        context: context,
        urlJson:
            'https://example.com/UpdateCenter/update_center.json', // URL to get JSON data for updates (replace with yours)

        // Plugin configuration (You can embed your own translation configuration so that the plugin looks harmonious with your application.)
        config: UpdateCenterConfig(
            globalConfig: GlobalConfig(
              isCheckStart:
                  true, // Whether to check for updates when the app starts
              isNoUpdateAvailableToast:
                  true, // Whether to show a toast message if no updates are available
              isSourceUrl:
                  false, // You can enable clicking a link instead of downloading a file
              isVerifiedSha256Android:
                  true, // Responsible for enabling sha256 checks after the file is downloaded
              isVerifiedSha256Windows:
                  true, // Responsible for enabling sha256 checks after the file is downloaded
              isRequestForNotifications:
                  true, // Allows you to request notifications or not
              isOpenFile:
                  false, // Determines whether to open an already downloaded file instead of downloading it again (This can be useful if you don't want users to download the file again)
              isEnabledLog:
                  true, // If you want logs to be shown or not, you basically need to if you are releasing a release and don’t want anyone to see the logs
            ),
            uiConfig: UIConfig(
              updateButtonText: 'Install', // Text for the update button
              skipButtonText: 'Later', // Text for the skip button
              updateAvailableText:
                  'Update available', // Text indicating an update is available
              changelogText: 'Changelog', // Text for the changelog section
              titleDownloadBottomSheets:
                  'Downloading...', // Title text for the downloading bottom sheet
              titleVerifiedSha256BottomSheets:
                  'Verified sha256...', // Header text for hash check bottom sheet 256
              toastNoUpdateFoundText: 'No update found',

              // Custom text style (Uncomment to apply them)
              alertChangeLogTextStyle:
                  const TextStyle(fontSize: 23, fontWeight: FontWeight.bold),
              alertVersionNameStyle:
                  const TextStyle(fontSize: 26, fontWeight: FontWeight.bold),
              bottomSheetChangeLogTextStyle:
                  const TextStyle(fontSize: 22, fontWeight: FontWeight.bold),
              bottomSheetVersionNameTextStyle:
                  const TextStyle(fontSize: 16, fontWeight: FontWeight.normal),

              customIconTitle: const Icon(
                Icons.downloading_outlined,
                size: 26,
              ), // Icon for the bottom sheet
              dialogType: DialogType
                  .bottomSheet, // Type of dialog to show for updates (alert dialog or bottom sheet)
            ),
            notificationConfig: NotificationConfig(
              defaultIcon:
                  '@drawable/ic_update_center', // Icon for the notification (Replace the path with another icon)
              downloadProgressNotificationTextTitle:
                  'Downloading...', // Title header in notification
              downloadProgressNotificationTextBody:
                  '', // Body text for the download progress notification
              downloadFailedNotificationTitleText:
                  'Download failed', // Title for the failed download notification
              downloadFailedNotificationBodyText:
                  'An error occurred while downloading update. Check your internet connections and try again', // Body text for the failed download notification
              verifiedSha256NotificationTitleText: 'Verified sha256...',
              verifiedSha256NotificationBodyText: '',

              showProgress:
                  true, // Whether to show download progress in the notification
              channelShowBadge:
                  true, // Whether to show a badge on the notification channel
            )));
  }

  //Check for updates
  checkUpdate() async {
    await updateCenter.check();
  }
}