geo-smart-app/lib/main.dart

72 lines
1.9 KiB
Dart
Raw Permalink Normal View History

2020-07-28 18:11:47 +00:00
import 'package:alice/alice.dart';
import 'package:dio/dio.dart';
2019-10-27 10:18:28 +00:00
import 'package:flutter/material.dart';
2020-07-28 18:11:47 +00:00
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:geosmart/config.dart';
import 'package:geosmart/page/map_page.dart';
import 'package:geosmart/page/setting_page.dart';
import 'package:geosmart/page/startup_page.dart';
2019-10-27 10:18:28 +00:00
2020-07-28 18:11:47 +00:00
import 'bloc/bloc.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
final Alice alice = Alice(showNotification: Config.showInterceptor);
final Dio dio = Dio();
dio.interceptors.add(alice.getDioInterceptor());
runApp(
MultiBlocProvider(
providers: [
BlocProvider<AuthenticationBloc>(
create: (context) => AuthenticationBloc(
alice: alice,
dio: dio,
)..add(AuthenticationStarted()),
),
BlocProvider<SettingBloc>(
create: (context) => SettingBloc(
authenticationBloc: BlocProvider.of<AuthenticationBloc>(
context,
),
),
),
BlocProvider<PositionBloc>(
create: (context) => PositionBloc(
authenticationBloc: BlocProvider.of<AuthenticationBloc>(
context,
),
),
),
],
child: MyApp(),
),
);
}
2019-10-27 10:18:28 +00:00
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
2019-10-27 10:19:53 +00:00
title: 'Geo Smart App',
2020-07-28 18:11:47 +00:00
navigatorKey: BlocProvider.of<AuthenticationBloc>(
context,
).alice.getNavigatorKey(),
2019-10-27 10:18:28 +00:00
theme: ThemeData(
primarySwatch: Colors.blue,
),
2020-07-28 18:11:47 +00:00
home: BlocBuilder<AuthenticationBloc, AuthenticationState>(
builder: (ctx, state) {
if (state is AuthenticationSuccess) {
return MapPage();
}
if (state is AuthenticationFailed) {
return SettingPage();
}
return StartupPage();
},
),
2019-10-27 10:18:28 +00:00
);
}
}