Untitled

mail@pastecode.io avatar
unknown
plain_text
3 years ago
5.7 kB
3
Indexable
Never
import 'package:flutter/material.dart';
import 'package:nb_app/controllers/allProductCommon/categoryWiseProductAllController.dart';
import 'package:nb_app/controllers/allProductCommon/specialProductAllController.dart';
import 'package:nb_app/controllers/auth/loginController.dart';
import 'package:nb_app/controllers/auth/registerController.dart';
import 'package:nb_app/controllers/bottomNavController.dart';
import 'package:nb_app/controllers/cart/cartController.dart';
import 'package:nb_app/controllers/favourite/favouriteController.dart';
import 'package:nb_app/controllers/home/homeController.dart';
import 'package:nb_app/controllers/order/orderDetailController.dart';
import 'package:nb_app/controllers/order/orderListController.dart';
import 'package:nb_app/controllers/package/packageDetailController.dart';
import 'package:nb_app/controllers/productDetails/productDetailController.dart';
import 'package:nb_app/controllers/search/searchController.dart';
import 'package:nb_app/controllers/checkout/checkoutController.dart';
import 'package:nb_app/controllers/account/editProfileController.dart';
import 'package:nb_app/controllers/staticPages/staticPagesController.dart';
import 'package:nb_app/localizations/localizations.dart';
import 'package:nb_app/models/jsonModels/userDataModel.dart';
import 'package:nb_app/sharedPreference/sharedPreference.dart';
import 'package:nb_app/utils/colors.dart';
import 'package:nb_app/utils/theme.dart';
import 'package:nb_app/views/onBoardingScreen.dart';
import 'package:provider/provider.dart';
import 'helpers/ProjectResource.dart';
import 'helpers/ProjectResource.dart';
import 'views/auth/authChoice.dart';
import 'views/home.dart';
import 'models/languageModel.dart';

void main() {
  runApp(MultiProvider(
    providers: [
      ChangeNotifierProvider(
        create: (_) => RegisterController(),
      ),
      ChangeNotifierProvider(create: (_) => LoginController()),
      ChangeNotifierProvider(create: (_) => BottomNavigationController()),
      ChangeNotifierProvider(create: (_) => CartController()),
      ChangeNotifierProvider(create: (_) => FavouriteController()),
      ChangeNotifierProvider(create: (_) => SearchController()),
      ChangeNotifierProvider(create: (_) => HomeController()),
      ChangeNotifierProvider(create: (_) => SpecialProductAllController()),
      ChangeNotifierProvider(create: (_) => CategoryWiseProductAllController()),
      ChangeNotifierProvider(create: (_) => StaticPagesController()),
      ChangeNotifierProvider(create: (_) => ProductDetailController()),
      ChangeNotifierProvider(create: (_) => PackageDetailController()),
      ChangeNotifierProvider(create: (_) => CheckoutController()),
      ChangeNotifierProvider(create: (_) => EditProfileController()),
      ChangeNotifierProvider(create: (_) => OrderListController()),
      ChangeNotifierProvider(create: (_) => OrderDetailsController()),
    ],
    child: MyApp(),
  ));
}

class MyApp extends StatefulWidget {
  // This widget is the root of your application.
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  Languages _languages;

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

  checkSettings() {
    SharedPref.contain('settings').then((val) {
      if (val) {
        SharedPref.read('settings').then((val) {
          print(val);
          print(val['showOnBoard']);
          print(val['loggedIn']);
          print(val['language']);

          setState(() {
            ProjectResource.settings = val;
            ProjectResource.showOnBoard = val['showOnBoarding'];
            ProjectResource.loggedIn = val['loggedIn'];
            ProjectResource.selectedLanguage = val['language'] == 'en'
                ? ProjectResource.languages[0]
                : ProjectResource.languages[1];
            _languages = ProjectResource.selectedLanguage;
            if (val['user'] != null) {
              var userDatas = DataUser.fromJson(val['user']['data']);
              ProjectResource.token = val['user']['token'];
              ProjectResource.userDataGlobal = userDatas;

              ///---------user data log-----------//

              print(ProjectResource.userDataGlobal);
              print(ProjectResource.userDataGlobal.customersEmailAddress);
              print(ProjectResource.userDataGlobal.customersFirstname);
              print("ProjectResource.token");
              print(ProjectResource.token);

              WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
                Provider.of<BottomNavigationController>(context, listen: false)
                    .fetchCartData();
              });
            }
          });
          print(ProjectResource.settings);
        });
      } else {
        setState(() {
          _languages = ProjectResource.selectedLanguage;
        });
      }
    });
  }

  @override
  Widget build(BuildContext context) {
    return _languages == null
        ? Container(
            color: AppColors.whiteColor,
            child: Center(
              child: CircularProgressIndicator(),
            ),
          )
        : MaterialApp(
            title: 'NittaBazar',
            debugShowCheckedModeBanner: false,
            localizationsDelegates: [
              AppLocalizationsDelegate(
                locales: Locale(_languages.languageCode),
                //locales: Locale('en'),
              )
            ],
            theme: appTheme,
            home: ProjectResource.loggedIn
                ? Home()
                : ProjectResource.showOnBoard
                    ? AuthChoice()
                    : OnBoardingPage(),
            //home: Home(),
          );
  }
}