world_countries 1.6.0 copy "world_countries: ^1.6.0" to clipboard
world_countries: ^1.6.0 copied to clipboard

Sealed world data in form of Flutter widgets (country, phone, currency pickers, etc.).

example/lib/main.dart

import "package:flutter/material.dart";
import "package:flutter_localizations/flutter_localizations.dart";
import "package:world_countries/world_countries.dart";

import "app_navigator.dart";
import "model/world_data.dart";
import "routing/delegate.dart";
import "routing/parser.dart";
import "routing/route_state.dart";
import "theme/color_schemes.g.dart";

void main() => runApp(const Main());

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

  @override
  State<Main> createState() => _MainState();
}

class _MainState extends State<Main> {
  /// Also [CurrencyTileThemeData], [LanguageTileThemeData],
  /// [CountryTileThemeData].
  static const pickerThemes = <ThemeExtension>[
    PickersThemeData(primary: true), // Applies to all types of pickers.
    /// Specify the flag decoration in the default country/phone-code picker.
    FlagThemeData(
      decoration:
          BoxDecoration(borderRadius: BorderRadius.all(Radius.circular(4))),
    ),
  ];
  final _navigatorKey = GlobalKey<NavigatorState>();
  final _routeParser = TemplateRouteParser(allowedPaths: WorldData.paths);
  late final _routeState = RouteState(_routeParser);
  late final _routerDelegate = SimpleRouterDelegate(
    routeState: _routeState,
    builder: (_) => AppNavigator(_navigatorKey),
    navigatorKey: _navigatorKey,
  );

  @override
  void dispose() {
    _routerDelegate.dispose();
    _routeState.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) => RouteStateScope(
        notifier: _routeState,
        child: MaterialApp.router(
          routeInformationParser: _routeParser,
          routerDelegate: _routerDelegate,
          theme: ThemeData(
            extensions: pickerThemes,
            useMaterial3: true,
            colorScheme: lightColorScheme,
          ),
          darkTheme: ThemeData(
            extensions: pickerThemes,
            useMaterial3: true,
            colorScheme: darkColorScheme,
          ),
          localizationsDelegates: const [
            GlobalMaterialLocalizations.delegate,
            GlobalCupertinoLocalizations.delegate,
            TypedLocaleDelegate(), // <- Add for automatic pickers translations.
          ],
          supportedLocales: [
            const Locale.fromSubtags(languageCode: "bs", scriptCode: "Cyrl"),
            const Locale.fromSubtags(languageCode: "bs", scriptCode: "Latn"),
            // Classic, string only based locale, or:
            const TypedLocale(LangPor(), country: "PT"), // Loose typed.
            const IsoLocale(LangPor(), country: CountryBra()), // Strict typed.
            for (final locale in kMaterialSupportedLanguages) Locale(locale),
          ],
        ),
      );
}
17
likes
140
pub points
80%
popularity
screenshot

Publisher

verified publishertsin.is

Sealed world data in form of Flutter widgets (country, phone, currency pickers, etc.).

Repository (GitHub)
View/report issues

Topics

#picker #sealed #country-picker #country-selector #currency-picker

Documentation

API reference

License

MIT (license)

Dependencies

flutter, world_flags

More

Packages that depend on world_countries