json_localizations 0.6.0 copy "json_localizations: ^0.6.0" to clipboard
json_localizations: ^0.6.0 copied to clipboard

A minimal JSON localization package built on LocalizationsDelegate.

example/lib/main.dart

import 'package:flutter/material.dart';

import 'package:json_localizations/json_localizations.dart';
import 'package:flutter_localizations/flutter_localizations.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      localizationsDelegates: [
        ...GlobalMaterialLocalizations.delegates,
        JsonLocalizationsDelegate(path: 'assets/json_translations'),
      ],
      supportedLocales: const <Locale>[
        Locale('en'),
        Locale('nb'),
      ],
      theme: ThemeData(
        primarySwatch: Colors.blue,
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: const MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key}) : super(key: key);

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('json_localizations'),
      ),
      body: Column(
        mainAxisAlignment: MainAxisAlignment.start,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: <Widget>[
          Text(JsonLocalizations.of(context)?.value('hello')),
          const SizedBox(height: 12),
          Text(JsonLocalizations.of(context)?.value('bye')),
          const Divider(),
          ...JsonLocalizations.of(context)
              ?.value('items')
              .map((text) => Text(text))
              .toList(),
          const Divider(),
          Text(JsonLocalizations.of(context)!.value('count').toString()),
        ],
      ),
    );
  }
}
2
likes
150
pub points
64%
popularity

Publisher

verified publisherapptakk.com

A minimal JSON localization package built on LocalizationsDelegate.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter

More

Packages that depend on json_localizations