flutter_easy_utils 1.0.5 copy "flutter_easy_utils: ^1.0.5" to clipboard
flutter_easy_utils: ^1.0.5 copied to clipboard

A Flutter package to handle dialogs , snakbars , loading , shareprefranse , api requests and more.

example/example.md

Documentation #

First ### !Important #

you have to create a folder named languages in your assets directory with the defined languages in it. An example structure could be :

assets
└── languages
    ├── en.json
    └── ar.json

Here's an example of en.json :

{
  "hello": "Hello !"
}

and an example of ar.json :

{
  "hello": "مرحبا بك"
}

Basic #


void main() {
  WidgetsFlutterBinding.ensureInitialized();
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return EasyApp(
      builder: (context) => Home(),
      primary: Colors.pink,
      accent: Colors.yellow,
    );
  }
}

choose primary color of your app and accent color

use some basic functions #

translate text #

Text(tran(context, "text"));

response dimensions #

SizeConfig.height(10);

change languages #

changeLang(context, "ar");

change Theme to dark/light #

toggleTheme(context);

Alerts #

success #

successAlert(context);

error #

errorAlert(context , "error message");

full Home class #


class Home extends StatefulWidget {
  @override
  _HomeState createState() => _HomeState();
}

class _HomeState extends State<Home> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(),
      body: ListView(
        shrinkWrap: true,
        children: [
          SizedBox(
            height: SizeConfig.height(10),
          ),
          Center(
            child: Text(tran(context, "text")),
          ),
          SizedBox(
            height: SizeConfig.height(3),
          ),
          TextButton(
            child: Text(tran(context, "change_lang_ar")),
            onPressed: () {
              changeLang(context, "ar");
            },
          ),
          TextButton(
            child: Text(tran(context, "change_lang_en")),
            onPressed: () {
              changeLang(context, "en");
            },
          ),
          TextButton(
            child: Text(tran(context, "change_theme")),
            onPressed: () {
              toggleTheme(context);
            },
          ),
          TextButton(
            child: Text(tran(context, "alert_error")),
            onPressed: () {
              errorAlert(context , "error");
            },
          ),
          TextButton(
            child: Text(tran(context, "alert_success")),
            onPressed: () {
              successAlert(context);
            },
          ),
          TextButton(
            child: Text(tran(context, "snack")),
            onPressed: () {
              snackBar(context , "message" , type: AlertType.error);
            },
          ),
          TextButton(
            child: Text(tran(context, "review app")),
            onPressed: () {
              reviewApp();
            },
          ),
          TextButton(
            child: Text(tran(context, "share app")),
            onPressed: () {
              shareApp(context);
            },
          ),
        ],
      ),
    );
  }
}