agnext_common_library_flutter 2.0.3 copy "agnext_common_library_flutter: ^2.0.3" to clipboard
agnext_common_library_flutter: ^2.0.3 copied to clipboard

Agnext common library to reuse various widgets and functions

example/lib/main.dart

import 'dart:isolate';

import 'package:example/src/CommonBottomSheet.dart';
import 'package:example/src/CommonColors.dart';
import 'package:example/src/common_text_field.dart';
import 'package:example/src/common_utilities.dart';
import 'package:example/src/custom_button.dart';
import 'package:example/src/dimensions.dart';
import 'package:example/src/outlineButton.dart';
import 'package:example/src/useIsolates.dart';
import 'package:example/src/widgets.dart';
import 'package:flutter/material.dart';

import 'main.dart';
export 'package:flutter_screenutil/flutter_screenutil.dart';
export 'package:get/get.dart' hide FormData, MultipartFile, Response;

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

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

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    //this is required to be add in  main dart file otherevise all dimension are not working and also this package use getx management packages you can modity if required
    return ScreenUtilInit(
        designSize: const Size(360, 690),
        minTextAdapt: true,
        splitScreenMode: true,
        builder: (_, child) {
          return GetMaterialApp(
            theme: new ThemeData(
              appBarTheme:
                  AppBarTheme(iconTheme: IconThemeData(color: Colors.black)),
            ),
            smartManagement: SmartManagement.onlyBuilder,
            debugShowCheckedModeBanner: false,
            locale: const Locale('en', 'US'),
            defaultTransition: Transition.rightToLeft,
            home: MyHomePage(
              title: "Home page",
            ),
          );
        });
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  var userLocations="";
  var isLoadingLocations=false;

  void _incrementCounter() {
    setState(() {
      _counter++;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: CommonWidgets.customAppBar(
          title: "custom app bar",
          actions: <Widget>[
            CommonWidgets.setPadding(
                rightPadding: margin_20,
                widget: Icon(
                  Icons.favorite,
                  color: CommonColors.white,
                )),
          ],
          appBarBGColor: CommonColors.primaryColor,
          appBarTitleColor: CommonColors.white),

      //add padding with just two lines of code
      body: CommonWidgets.setPaddingAll(
        margin: margin_20,
        widget: Column(
          children: [
            //use common text and easily add font size with minimal code
            CommonWidgets.commonText("this is commonWidget",
                fontSize: font_16, color: CommonColors.primaryColor),
            CommonWidgets.sizedBox(height: height_20),

            CommonWidgets.networkImages(
                "https://fastly.picsum.photos/id/230/200/300.jpg?hmac=pyhlpgJN2oBeEzhJbnJYrCsLoJM6MKd_NUQGIQhVx5k",
                height: height_200,
                width: width_170),

            CommonTextField.commonTextField(
              labelText: "username"
            ),

            CustomButton.customButton(
                buttonText: "open bottonSheet",
                onClick: () {
                  CommonBottomSheet.commonBottomSheet(
                      body: CommonWidgets.setPaddingAll(
                    margin: margin_20,
                    widget: Container(
                      width: CommonWidgets.fullWidth(context),
                      child: Column(
                        mainAxisSize: MainAxisSize.min,
                        children: [
                          Align(
                            alignment: Alignment.topLeft,
                            child: IconButton(
                              icon: Icon(Icons.close),
                              onPressed: () {
                                Get.back();
                              },
                            ),
                          ),
                          CommonWidgets.commonText("this is common Bottomsheet",
                              fontSize: font_16,
                              color: CommonColors.primaryColor),
                        ],
                      ),
                    ),
                  ));
                }),
        CommonWidgets.setPaddingAll(
          margin: margin_20,
          widget:
            CommonWidgets.commonText(userLocations,color: CommonColors.primaryColor),),

            CommonWidgets.setPaddingAll(
             margin: margin_20,
              widget:   OutlineCustomButton.outlineButton  (
                  buttonText: "Get location",
                  onClick: ()  async {

                    var isLocationsEnabled=false.obs;
                    var lat=0.0.obs;
                    var long=0.0.obs;
                    var address="".obs;
                    var address2=  await  CommonUtilities.locationsPermission(isLocationsEnabled, lat, long, address);
                    CommonWidgets.logPrint(address2);
                    userLocations=address2;
                    setState(() {

                    });
                  }
              )
            ),
            CommonWidgets.setPaddingAll(
                margin: margin_20,
                widget:   OutlineCustomButton.outlineButton  (
                    buttonText: "Run isolates",
                    onClick: () async {
                      var isLocationsEnabled=false.obs;
                      var lat=0.0.obs;
                      var long=0.0.obs;
                      var address="".obs;
                      //using isolates and getting data from isolates
                      var data=     await IsolatesTask.useIsolate("ranjeet",isolateFun);
                      CommonWidgets.logPrint(data);
                    }
                )
            )
          ],
        ),
      ),
      // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}

//isolates functions with arguments
isolateFun(List<dynamic>args){
  SendPort sendPort=args[0];
  return Isolate.exit(sendPort, args[1]);
}