Skip to content

Commit

Permalink
Update shop app example
Browse files Browse the repository at this point in the history
  • Loading branch information
Frezyx committed Jan 27, 2024
1 parent 295ecac commit 9f94fe3
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class _ProductsScreenState extends State<ProductsScreen> {
),
actions: [
_OpenLogsButton(
onPressed: () => _openTalekrScreen(context),
onPressed: () => _openTalkerScreen(context),
),
],
),
Expand Down Expand Up @@ -99,7 +99,7 @@ class _ProductsScreenState extends State<ProductsScreen> {
);
}

void _openTalekrScreen(BuildContext context) =>
void _openTalkerScreen(BuildContext context) =>
Navigator.pushNamed(context, Routes.talker);

void _openProductScreen(BuildContext context, List<Product> products, int i) {
Expand Down
87 changes: 41 additions & 46 deletions examples/shop_app_example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,52 @@ void main() {
runZonedGuarded(() async {
WidgetsFlutterBinding.ensureInitialized();
await _initFirebase();
_initTalker();
_registerRepositories();
Bloc.observer = TalkerBlocObserver(
talker: DI<Talker>(),
settings: const TalkerBlocLoggerSettings(
printCreations: true,
printClosings: true,
),
);
_initDependencies();
runApp(const MyApp());
}, (Object error, StackTrace stack) {
DI<Talker>().handle(error, stack, 'Uncaught app exception');
});
}

void _initDependencies() {
final talker = TalkerFlutter.init(
settings: TalkerSettings(
colors: {
TalkerLogType.verbose: AnsiPen()..yellow(),
},
),
);
DI.registerSingleton<Talker>(talker);
talker.verbose('Talker initialization completed');

final talkerDioLogger = TalkerDioLogger(
talker: talker,
settings: const TalkerDioLoggerSettings(
printRequestHeaders: true,
printResponseHeaders: false,
printRequestData: true,
printResponseData: false,
),
);

final dio = Dio();
dio.interceptors.add(talkerDioLogger);

DI.registerSingleton<AbstractProductsRepository>(
ProductsRepository(dio: dio),
);
talker.info('Repositories initialization completed');

Bloc.observer = TalkerBlocObserver(
talker: talker,
settings: const TalkerBlocLoggerSettings(
printCreations: false,
printClosings: false,
printStateFullData: false,
),
);
}

Future<void> _initFirebase() async {
if (kIsWeb) {
await Firebase.initializeApp(
Expand All @@ -46,7 +77,7 @@ Future<void> _initFirebase() async {
}

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

@override
Widget build(BuildContext context) {
Expand All @@ -71,39 +102,3 @@ class MyApp extends StatelessWidget {
);
}
}

void _initTalker() {
final talker = TalkerFlutter.init();
DI.registerSingleton<Talker>(talker);
talker.verbose('Talker initialization completed');

/// This logic is just for example here
if (!DI.isRegistered<Talker>()) {
DI.registerSingleton<Talker>(talker);
} else {
talker.warning('Trying to re-register an object in GetIt');
}

/// Dio logger initialization
final talkerDioLogger = TalkerDioLogger(
talker: DI<Talker>(),
settings: const TalkerDioLoggerSettings(
printRequestHeaders: true,
printResponseHeaders: true,
printRequestData: true,
printResponseData: true,
),
);

DI.registerSingleton(talkerDioLogger);
}

void _registerRepositories() {
final dio = Dio();
dio.interceptors.add(DI<TalkerDioLogger>());

DI.registerSingleton<AbstractProductsRepository>(
ProductsRepository(dio: dio),
);
DI<Talker>().info('Repositories initialization completed');
}
2 changes: 1 addition & 1 deletion examples/shop_app_example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ packages:
source: hosted
version: "1.2.0"
talker:
dependency: "direct main"
dependency: "direct overridden"
description:
path: "../../packages/talker"
relative: true
Expand Down
8 changes: 4 additions & 4 deletions examples/shop_app_example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ dependencies:
flutter:
sdk: flutter

talker: ^3.2.0
talker_flutter: ^3.6.0
talker_dio_logger: ^2.4.0
talker_bloc_logger: ^2.4.0
talker_flutter: ^4.0.0
talker_dio_logger: ^4.0.0
talker_bloc_logger: ^4.0.0

get_it: ^7.6.7
flutter_bloc: ^8.1.3
equatable: ^2.0.5
Expand Down

0 comments on commit 9f94fe3

Please sign in to comment.