backup. before shop update
This commit is contained in:
126
lib/main.dart
126
lib/main.dart
@@ -1,48 +1,106 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:catcher/catcher.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_device_locale/flutter_device_locale.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_localizations/flutter_localizations.dart';
|
||||
import 'package:flutter_redux/flutter_redux.dart';
|
||||
import 'package:flutter_wisetronic/pages/buy_service.dart';
|
||||
import 'package:geolocator/geolocator.dart' as geolocator;
|
||||
import 'package:url_strategy/url_strategy.dart';
|
||||
import 'models/located_address.dart';
|
||||
import 'pages/me.dart';
|
||||
import 'package:pull_to_refresh/pull_to_refresh.dart';
|
||||
import 'package:splashscreen/splashscreen.dart';
|
||||
// import 'package:uni_links/uni_links.dart';
|
||||
|
||||
import 'constants.dart';
|
||||
import 'events/eventbus.dart';
|
||||
import 'events/events.dart';
|
||||
import 'generated/l10n.dart';
|
||||
import 'pages/home.dart';
|
||||
import 'pages/plain_page.dart';
|
||||
import 'pages/renew_minioffice.dart';
|
||||
import 'routes.dart';
|
||||
import 'store/actions.dart';
|
||||
import 'store/store.dart';
|
||||
import 'utils/configure_nonweb.dart' if (dart.library.html) 'utils/configure_web.dart';
|
||||
import 'utils/http_util.dart';
|
||||
import 'utils/util_io.dart' if (dart.library.html) 'utils/util_web.dart';
|
||||
|
||||
void main() async {
|
||||
void main() {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
Locale locale = await DeviceLocale.getCurrentLocale();
|
||||
|
||||
runApp(MyApp(locale));
|
||||
// Enable configureApp will cause route problem.
|
||||
// configureApp();
|
||||
setPathUrlStrategy();
|
||||
runApp(MyApp());
|
||||
}
|
||||
|
||||
class MyApp extends StatelessWidget {
|
||||
final Locale localLocate;
|
||||
String _to = '/';
|
||||
|
||||
MyApp(this.localLocate) {
|
||||
MyApp() {
|
||||
Routes.configure();
|
||||
store.dispatch(UpdateLocale(localLocate));
|
||||
Util().init();
|
||||
// getCurrentPosition();
|
||||
}
|
||||
|
||||
static getCurrentPosition() async {
|
||||
bool serviceEnabled;
|
||||
geolocator.LocationPermission permission;
|
||||
|
||||
serviceEnabled = await geolocator.Geolocator.isLocationServiceEnabled();
|
||||
if (!serviceEnabled) {
|
||||
print('Location services are disabled');
|
||||
return;
|
||||
}
|
||||
|
||||
permission = await geolocator.Geolocator.checkPermission();
|
||||
if (permission == geolocator.LocationPermission.deniedForever) {
|
||||
print(
|
||||
'Location permissions are permantly denied, we cannot request permissions.');
|
||||
return;
|
||||
}
|
||||
|
||||
if (permission == geolocator.LocationPermission.denied) {
|
||||
permission = await geolocator.Geolocator.requestPermission();
|
||||
if (permission != geolocator.LocationPermission.whileInUse &&
|
||||
permission != geolocator.LocationPermission.always) {
|
||||
print(
|
||||
'Location permissions are denied (actual value: $permission).');
|
||||
return;
|
||||
}
|
||||
geolocator.Position geoPosition = await geolocator.Geolocator.getCurrentPosition(
|
||||
desiredAccuracy: geolocator.LocationAccuracy.high);
|
||||
HttpUtil.httpGet('v1/getposition',
|
||||
queryParameters: {
|
||||
'latitude': geoPosition.latitude.toString(),
|
||||
'longitude': geoPosition.longitude.toString(),
|
||||
},
|
||||
).then((value) {
|
||||
print('value: $value');
|
||||
store.dispatch(UpdateLocatedAddress(LocatedAddress.fromJson(value)));
|
||||
}).catchError((error) {
|
||||
print('error get address: $error');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// This widget is the root of your application.
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
||||
Widget _buildBody() {
|
||||
return SplashScreen(
|
||||
seconds: 5,
|
||||
routeName: '/',
|
||||
navigateAfterSeconds: Home(localLocate, title: 'Welcome',),
|
||||
routeName: _to,
|
||||
navigateAfterSeconds: Home(title: Constants.APP_TITLE,),
|
||||
styleTextUnderTheLoader: new TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 20.0,
|
||||
),
|
||||
// imageBackground: (Image.network(Constants.BASE_API_URL + 'gallery/get-wisetronic-slpash')).image,
|
||||
imageBackground: (new Image.network(Constants.BASE_API_URL + 'gallery/get-minimanager-splash/')).image,
|
||||
imageBackground: (Image.network(Constants.BASE_API_URL + 'gallery/get-minimanager-splash/')).image,
|
||||
backgroundColor: Colors.white,
|
||||
onClick: () {
|
||||
|
||||
@@ -63,21 +121,59 @@ class MyApp extends StatelessWidget {
|
||||
],
|
||||
supportedLocales: S.delegate.supportedLocales,
|
||||
localeResolutionCallback: (Locale locale, Iterable<Locale> supportedLocales) {
|
||||
print('Language code: ${localLocate.languageCode}');
|
||||
print('Language code: ${locale.languageCode}, Country code: ${locale.countryCode}');
|
||||
for (final supportedLocale in supportedLocales) {
|
||||
if (supportedLocale.languageCode == localLocate.languageCode) {
|
||||
if (supportedLocale.languageCode == locale.languageCode) {
|
||||
store.dispatch(UpdateLocale(locale));
|
||||
return supportedLocale;
|
||||
}
|
||||
}
|
||||
store.dispatch(UpdateLocale(supportedLocales.first));
|
||||
return supportedLocales.first;
|
||||
},
|
||||
onGenerateRoute: (RouteSettings settings) {
|
||||
final List<String> pathElements = settings.name.split('/');
|
||||
print('path elements: $pathElements');
|
||||
if (pathElements[0] != '') {
|
||||
return null;
|
||||
}
|
||||
if (pathElements[1] == 'me') {
|
||||
return MaterialPageRoute(
|
||||
builder: (BuildContext context) => Me()
|
||||
);
|
||||
}
|
||||
if (pathElements[1] == 'privacy-policy') {
|
||||
return MaterialPageRoute(
|
||||
builder: (BuildContext context) =>
|
||||
PlainPage(
|
||||
'privacy-policy',
|
||||
// businessId: Constants.BUSINESS_ID,
|
||||
businessId: 310,
|
||||
),
|
||||
);
|
||||
}
|
||||
if (pathElements[1] == 'renew-minioffice') {
|
||||
return MaterialPageRoute(builder: (BuildContext context) =>
|
||||
RenewMiniOffice(int.parse(pathElements[2]))
|
||||
);
|
||||
}
|
||||
if (pathElements[1] == 'buy-service') {
|
||||
return MaterialPageRoute(builder: (BuildContext context) =>
|
||||
BuyService(int.parse(pathElements[2]), pathElements[3])
|
||||
);
|
||||
}
|
||||
return MaterialPageRoute(
|
||||
builder: (BuildContext context) =>
|
||||
Home(title: Constants.APP_TITLE,),
|
||||
);
|
||||
},
|
||||
title: 'Wisetronic Inc.',
|
||||
theme: ThemeData(
|
||||
primarySwatch: Colors.blue,
|
||||
),
|
||||
home: StoreProvider(
|
||||
store: store,
|
||||
child: _buildBody(),
|
||||
child: Home(title: Constants.APP_TITLE,),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user