universally 5.0.1 copy "universally: ^5.0.1" to clipboard
universally: ^5.0.1 copied to clipboard

It depends on universally plug and can update the latest available version in time

example/lib/main.dart

import 'package:app/page/basic_list_page.dart';
import 'package:app/page/component_page.dart';
import 'package:app/page/gif_page.dart';
import 'package:app/page/hive_preferences.dart';
import 'package:app/page/text_field_page.dart';
import 'package:flutter/material.dart';
import 'package:universally/universally.dart';

Future<void> main() async {
  isBeta = true;

  await GlobalConfig().setDefaultConfig(ProjectConfig(
      mainColor: Colors.purple.shade900,
      textColor: TextColor(
          largeColor: const Color(0xFF292929),
          veryLargeColor: const Color(0xFF292929),
          defaultColor: const Color(0xFF292929),
          styleColor: const Color(0xFF292929),
          smallColor: const Color(0x804D4D4D)),
      loadingBuilder: (BasicLoading loading) => Container(
          width: loading.size * 2,
          height: loading.size * 2,
          decoration: BoxDecoration(
              color: UCS.black, borderRadius: BorderRadius.circular(10)),
          child: const BasicLoading(
              color: Colors.white, style: SpinKitStyle.fadingCircle)),
      betaApi: '这是设置测试Api',
      releaseApi: '这里设置发布版Api',
      toastOptions: const ToastOptions(ignoring: false)));

  runApp(BasicApp(
      title: 'Universally',
      providers: [ChangeNotifierProvider(create: (_) => AppState())],
      home: const HomePage(),
      theme: ThemeData.light(useMaterial3: true),
      darkTheme: ThemeData.dark(useMaterial3: true),
      initState: (context) async {
        BasicConnectivity().addListener((status, result) async {
          switch (result) {
            case ConnectivityResult.wifi:
              showToast('use wifi');
              break;
            case ConnectivityResult.ethernet:
              showToast('use ethernet');
              break;
            case ConnectivityResult.mobile:
              showToast('use Cellular networks');
              break;
            case ConnectivityResult.none:
              showToast('none networks');
              break;
            case ConnectivityResult.bluetooth:
              showToast('use bluetooth');
              break;
            case ConnectivityResult.vpn:
              showToast('use vpn');
              break;
            case ConnectivityResult.other:
              showToast('use other');
              break;
          }
          return true;
        });
        BasicConnectivity().subscription(
            alertUnavailableNetwork: (status, result) =>
                alertOnlyMessage('Network Unavailable'));
      }));
}

class HomePage extends StatelessWidget {
  const HomePage({super.key});

  @override
  Widget build(BuildContext context) {
    return BasicScaffold(
        padding: EdgeInsets.fromLTRB(15, context.statusBarHeight + 15, 15,
            context.bottomNavigationBarHeight + 15),
        isScroll: true,
        isRootPage: true,
        child: Wrap(alignment: WrapAlignment.center, children: [
          Button(onTap: () => push(const ComponentPage()), text: 'Component'),
          Button(
              onTap: () {
                UrlLauncher().openUrl('tel:10086');
              },
              text: 'Call Phone'),
          Button(onTap: () => push(const GifPage()), text: 'Gif'),
          Button(child: const SwitchApiButton(color: Colors.white)),
          Button(onTap: () => push(const TextFieldPage()), text: 'TextField'),
          Button(onTap: () => push(const BasicListPage()), text: 'BasicList'),
          Button(
              onTap: () => push(const HivePreferencesPage()),
              text: 'BHP(BasicHivePreferences)'),
          Button(
              onTap: () {
                showDoubleChooseAlert(
                    title: 'title', left: 'left', right: 'right');
              },
              text: 'showDoubleChooseAlert'),
          Button(onTap: showLoading, text: 'showLoading'),
        ]));
  }
}

class Button extends Universal {
  Button({
    super.key,
    Widget? child,
    String? text,
    super.onTap,
  }) : super(
            padding: const EdgeInsets.symmetric(vertical: 10, horizontal: 12),
            margin: const EdgeInsets.all(5),
            heroTag: text,
            child: child ??
                BText(text ?? '', style: const TStyle(color: UCS.white)),
            decoration: BoxDecoration(
                border: Border.all(color: GlobalConfig().currentColor),
                color: GlobalConfig().currentColor,
                borderRadius: BorderRadius.circular(8)));
}

class AppState with ChangeNotifier {}