bui_component 0.0.70+19 copy "bui_component: ^0.0.70+19" to clipboard
bui_component: ^0.0.70+19 copied to clipboard

Flutter base component. Which is include all the basic screen and the details. If the user import the package they will use all the basic needs.

example/lib/main.dart

import 'dart:async';
import 'dart:convert';

import 'package:bui_component/Utils/BuiFormatterComponent.dart';
import 'package:example/Constants/AppColors.dart';
import 'package:example/Constants/AppStrings.dart';
import 'package:example/Constants/server_url.dart';
import 'package:example/Firebase/sign_in.dart';
import 'package:example/Models/base_bean.dart';
import 'package:example/Models/bui_format_details_bean.dart';
import 'package:example/Models/user_view_bean.dart';
import 'package:example/Screens/ModuleSelectionScreen.dart';
import 'package:example/Screens/SignUpScreen.dart';
import 'package:example/Screens/platform.dart';
import 'package:example/network/api_service.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:package_info/package_info.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:url_strategy/url_strategy.dart';

import './Constants/AppStrings.dart';
import 'Screens/SplashScreen.dart';

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp();
  setPathUrlStrategy();
  runZoned<Future<void>>(() async {
    runApp(new _MyAppState());
  });
}

const flashOn = 'FLASH ON';
const flashOff = 'FLASH OFF';
const frontCamera = 'FRONT CAMERA';
const backCamera = 'BACK CAMERA';

class _MyAppState extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
      statusBarColor: Colors.black, //top bar color
      statusBarIconBrightness: Brightness.dark, //top bar icons
      systemNavigationBarColor: Colors.black, //bottom bar color
      systemNavigationBarIconBrightness: Brightness.dark, //bottom bar icons
    ));

    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: new SplashScreen(
        seconds: 3,
        navigateAfterSeconds: new RestartWidget(
          child: MyAppState(),
        ),
      ),
    );
  }
}

class MyAppState extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return new MyApp();
  }
}

class MyApp extends State<MyAppState> {
  /* static const platform =
  const MethodChannel('com.aagnia.bui/playerChannel');*/
  static String user_token = "";

  static String user_name;
  static String user_email;
  static String user_phoneNumber;
  static bool user_emailVerified;
  static bool IS_PRE_LOGIN = false;
  static String user_imageUrl;
  static String user_uid;
  static String AUTH_TOKEN_VALUE;
  static String userId;
  static SharedPreferences sharedPreferences;
  UserViewBean userViewBean;
  List<UserListBean> userListBean;
  static String appName = '';
  static String packageName = '';
  static String version = '';
  static String buildNumber = '';
  static String email = '';
  static String name = '';
  static BuiFormatter buiFormatter = BuiFormatter();

  static Color primaryColor = AppColors.primaryColor;
  static Color secondaryColor = AppColors.primaryColor;

  static TextTheme textTheme;
  static CardTheme cardTheme;

  static Future getPrefs() async {
    userId = sharedPreferences.getString(AppStrings.USER_ID);
    AUTH_TOKEN_VALUE = sharedPreferences.getString(AppStrings.TOKEN);
  }

  Future<String> isLoggedIn() async {
    sharedPreferences = await SharedPreferences.getInstance();
    AUTH_TOKEN_VALUE = sharedPreferences.getString(AppStrings.TOKEN);

    if (AUTH_TOKEN_VALUE != null) {
      await getPrefs();
    }
  }

  final routes = <String, WidgetBuilder>{
    SignUpScreen.tag: (BuildContext context) => SignUpScreen(),
    MyBaseScreen.tag: (BuildContext context) => MyBaseScreen(),
  };

  @override
  void initState() {
    getPackageInfo();
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    textTheme = Theme.of(context).textTheme;
    cardTheme = Theme.of(context).cardTheme;

    return new FutureBuilder(
        future: isLoggedIn(),
        builder: (BuildContext context, AsyncSnapshot<String> snapshot) {
          switch (snapshot.connectionState) {
            case ConnectionState.waiting:
              return Center(child: new Container());
            default:
              if (snapshot.hasError)
                return new Text('Error: ${snapshot.error}');
              else {
                return MaterialApp(
                  debugShowCheckedModeBanner: false,
                  /*  theme: ThemeData.light().copyWith(
                      primaryColor: AppColors.APP_COLOR_PRIMARY,
                      primaryColorDark: AppColors.APP_COLOR_PRIMARY,
                      textTheme: Theme.of(context)
                          .textTheme
                          .apply(fontFamily: FontFamily.Gilroy)),*/
                  theme: ThemeData(
                    // Define the default brightness and colors.
                    brightness: Brightness.light,
                    pageTransitionsTheme: PageTransitionsTheme(builders: {
                      TargetPlatform.iOS: ZoomPageTransitionsBuilder(),
                      TargetPlatform.android: CupertinoPageTransitionsBuilder(),
                    }),
                    backgroundColor: AppColors.primaryColor,

                    primaryColor: AppColors.primaryColor,
                    accentColor: AppColors.primaryColor,

                    cardTheme: CardTheme(
                        shape: RoundedRectangleBorder(
                      borderRadius: BorderRadius.circular(5.0),
                    )),

                    buttonTheme: ButtonThemeData(
                      shape: RoundedRectangleBorder(
                          borderRadius: BorderRadius.circular(5)),
                      textTheme: ButtonTextTheme.accent,
                    ),

                    /// Font size and Font Family
                    textTheme: TextTheme(
                      headline1: TextStyle(
                          fontSize: 18.0, fontWeight: FontWeight.bold),
                      headline6: TextStyle(
                          fontSize: 14.0,
                          fontStyle: FontStyle.italic,
                          color: AppColors.APP_COLOR_BLACK),
                      //bodyText1: TextStyle(letterSpacing: 2,color: AppColors.APP_COLOR_WHITE,fontSize: 50,wordSpacing: 1.0,fontFamily: FontFamily.Gilroy, fontStyle: FontStyle.italic,),
                      bodyText1: GoogleFonts.inter(
                          letterSpacing: 1,
                          color: AppColors.APP_COLOR_BLACK,
                          fontSize: 14),
                      bodyText2: GoogleFonts.inter(
                          letterSpacing: 1,
                          color: AppColors.APP_COLOR_BLACK,
                          fontSize: 12),
                    ),
                  ),
                  home: getHomeWidget(),
                  routes: routes,
                );
              }
          }
        });
  }

  Widget getHomeWidget() {
    if (AUTH_TOKEN_VALUE == null) {
      IS_PRE_LOGIN = true;
      return new SignUpScreen();
    } else {
      IS_PRE_LOGIN = false;
      return new MyBaseScreen();
    }
  }

  static void noInternetDialog(BuildContext mContext, String mTitle,
      String mMessage, Function() okayFunct) {
    showDialog(
        context: mContext,
        builder: (BuildContext context) {
          return AlertDialog(
            title: new Text(mTitle),
            content: new Text(mMessage),
            actions: <Widget>[
              new TextButton(
                child: new Text(AppStrings.CANCEL),
                onPressed: () {
                  Navigator.of(context).pop();
                },
              ),
              new TextButton(
                  child: new Text(AppStrings.OKAY),
                  onPressed: () {
                    okayFunct();
                    Navigator.of(context).pop();
                  }),
            ],
          );
        });
  }

  Future<void> getPackageInfo() async {
    PackageInfo packageInfo = await PackageInfo.fromPlatform();
    appName = packageInfo.appName;
    packageName = packageInfo.packageName;
    version = packageInfo.version;
    buildNumber = packageInfo.buildNumber;
  }

  static Future<void> updateAuthToken(String authToken) async {
    SharedPreferences sharedPreferences = await SharedPreferences.getInstance();
    sharedPreferences.setString(AppStrings.TOKEN, authToken);
    MyApp.AUTH_TOKEN_VALUE = authToken;
  }

  static Future<void> callLoginAPI(BuildContext context) async {
    SharedPreferences prefs = await SharedPreferences.getInstance();

    signInWithGoogle().then((result) {
      if (result != null) {
        print("Login Success====");
        user_email = email;
        user_name = name;
        user_emailVerified = emailVerified;
        user_imageUrl = imageUrl;
        user_token = "Bearer " + bearToken.toString();
        user_uid = uid;
        MyApp.user_token = user_token;
        MyApp.user_uid = user_uid;
        MyApp.user_phoneNumber = user_phoneNumber;

        SignUpScreenState.user_token = user_token;

        prefs.setString(AppStrings.EMAIL, email);
        prefs.setString(AppStrings.TOKEN, user_token);
        prefs.setString(AppStrings.USER_ID, user_uid);
        MyPlatformState.isLoader = false;

        if (authResultData.additionalUserInfo.isNewUser) {
          callCreateAPI(context);
        } else {
          callUserAPI(context);
        }
        //Utils.showSnackBar(context, "Login Success" + name);
      } else {
        //Utils.showSnackBar(context, "Login Failed");
      }
    }).catchError((onError) async {
      print("Login Faile====" + onError.toString());
      await FirebaseAuth.instance.signOut();
      await signOutGoogle(context);
      // Utils.showSnackBar(
      //     context, "Unable to reach your account please try again...");
      MyApp.user_token = "";
    });
  }

  static Future<void> callCreateAPI(BuildContext context) async {
    String urlController = ServerUrl.crmUserCreate;
    var objToSend = {
      "\"uid\"": "\"${user_uid.toString()}\"",
      "\"name\"": "\"${user_name.toString()}\"",
      "\"phone\"": "\"${user_phoneNumber.toString() ?? ""}\"",
      "\"email\"": "\"${user_email.toString()}\"",
      "\"photourl\"": "\"${user_imageUrl.toString()}\"",
      "\"roleid\"": "\"${2}\"",
      "\"${UrlParams.AID}\"": "\"${UrlParams.AID_VALUE}\"",
      "\"${UrlParams.AKEY}\"": "\"${UrlParams.AKEY_VALUE}\"",
      "\"${UrlParams.AV}\"": "\"${UrlParams.AV_VALUE}\"",
    };

    String jsonStr = objToSend.toString();

    String res = await APIClient.getInstance().callAPI(
        context, urlController, HTTPMethod.POST,
        isHeader: true, requestBody: jsonStr);
    Map map = jsonDecode(res);

    BaseResponse response = BaseResponse.fromJson(map);

    if (response.status) {
      callUserAPI(context);
    }
  }

  static Future<void> callUserAPI(BuildContext context) async {
    String urlController = ServerUrl.crmUserView;
    var objToSend = {
      "\"condition\"": [
        {"\"uid\"": "\"${user_uid.toString()}\""}
      ],
      "\"${UrlParams.AID}\"": "\"${UrlParams.AID_VALUE}\"",
      "\"${UrlParams.AKEY}\"": "\"${UrlParams.AKEY_VALUE}\"",
      "\"${UrlParams.AV}\"": "\"${UrlParams.AV_VALUE}\"",
    };

    String jsonStr = objToSend.toString();

    String res = await APIClient.getInstance().callAPI(
        context, urlController, HTTPMethod.POST,
        isHeader: true, requestBody: jsonStr);
    Map map = jsonDecode(res);

    UserViewBean userViewBeanResponse = UserViewBean.fromJson(map);

    if (userViewBeanResponse.status) {
      sharedPreferences.setString(
          AppStrings.OWNER_ID, userViewBeanResponse.data[0].id.toString());

      callBUIFormatAPI(context);
    }
  }

  static Future<void> callBUIFormatAPI(BuildContext context) async {
    String urlController = ServerUrl.crmProductView;
    var objToSend = {
      "\"condition\"": [],
      "\"${UrlParams.AID}\"": "\"${UrlParams.AID_VALUE}\"",
      "\"${UrlParams.AKEY}\"": "\"${UrlParams.AKEY_VALUE}\"",
      "\"${UrlParams.AV}\"": "\"${UrlParams.AV_VALUE}\"",
    };

    String jsonStr = objToSend.toString();

    String res = await APIClient.getInstance().callAPI(
        context, urlController, HTTPMethod.POST,
        isHeader: true, requestBody: jsonStr);
    Map map = jsonDecode(res);

    BUIFormatDetailsBean buiFormatDetailsBean =
        BUIFormatDetailsBean.fromJson(map);

    if (buiFormatDetailsBean.status) {
      for (int i = 0; i < buiFormatDetailsBean.data.length; i++) {
        if (buiFormatDetailsBean.data[i].primary == "date") {
          sharedPreferences.setString(
              AppStrings.date, buiFormatDetailsBean.data[i].value.toString());
        }
        if (buiFormatDetailsBean.data[i].primary == "time") {
          sharedPreferences.setString(
              AppStrings.time, buiFormatDetailsBean.data[i].value.toString());
        }
        if (buiFormatDetailsBean.data[i].primary == "Currency" &&
            buiFormatDetailsBean.data[i].status == "active") {
          sharedPreferences.setString(AppStrings.currency,
              buiFormatDetailsBean.data[i].secondary.toString());
        }
      }

      Navigator.of(context).push(
        MaterialPageRoute(
          builder: (context) {
            return ModuleSelectionScreen();
          },
        ),
      );
    } else {}
  }
}

class RestartWidget extends StatefulWidget {
  final Widget child;

  RestartWidget({this.child});

  static restartApp(BuildContext context) {
    final _RestartWidgetState state =
        context.findAncestorStateOfType<_RestartWidgetState>();
    state.restartApp();
  }

  @override
  _RestartWidgetState createState() => new _RestartWidgetState();
}

class _RestartWidgetState extends State<RestartWidget> {
  Key key = new UniqueKey();

  void restartApp() {
    this.setState(() {
      key = new UniqueKey();
    });
  }

  @override
  Widget build(BuildContext context) {
    return new Container(
      key: key,
      child: widget.child,
    );
  }
}
1
likes
20
pub points
0%
popularity

Publisher

verified publisheraagnia.com

Flutter base component. Which is include all the basic screen and the details. If the user import the package they will use all the basic needs.

Repository (GitLab)
View/report issues

License

unknown (LICENSE)

Dependencies

country_code_picker, cyclop, file_picker, flutter, flutter_rating_bar, flutter_svg, google_fonts, intl, meta, shared_preferences

More

Packages that depend on bui_component