replace bloc with watch_it
This commit is contained in:
+16
-46
@@ -1,63 +1,33 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:immich_mobile/domain/service_locator.dart';
|
||||
import 'package:immich_mobile/presentation/home_page/cubit/home_cubit.dart';
|
||||
import 'package:immich_mobile/i18n/strings.g.dart';
|
||||
import 'package:immich_mobile/immich_app.dart';
|
||||
import 'package:immich_mobile/presentation/theme/states/app_theme.state.dart';
|
||||
import 'package:immich_mobile/presentation/theme/widgets/app_theme_builder.dart';
|
||||
import 'package:immich_mobile/service_locator.dart';
|
||||
import 'package:watch_it/watch_it.dart';
|
||||
|
||||
void main() {
|
||||
// Ensure the bindings are initialized
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
// DI Injection
|
||||
ServiceLocator.configureServices();
|
||||
|
||||
// Init localization
|
||||
LocaleSettings.useDeviceLocale();
|
||||
runApp(const MainWidget());
|
||||
}
|
||||
|
||||
class MainWidget extends StatelessWidget {
|
||||
class MainWidget extends StatelessWidget with WatchItMixin {
|
||||
const MainWidget({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp(
|
||||
title: 'Flutter Demo',
|
||||
theme: ThemeData(
|
||||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
|
||||
useMaterial3: true,
|
||||
),
|
||||
home: MultiBlocProvider(
|
||||
providers: [BlocProvider(create: (context) => HomeCubit())],
|
||||
child: Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text("Immich v2"),
|
||||
),
|
||||
body: BlocConsumer<HomeCubit, HomeState>(
|
||||
listener: (context, state) {
|
||||
print(state);
|
||||
},
|
||||
builder: (context, state) {
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text("Album count: ${state.albumCount}"),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
context.read<HomeCubit>().increaseAlbumCount();
|
||||
},
|
||||
child: const Text("Increase"),
|
||||
),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
context.read<HomeCubit>().decreaseAlbumCount();
|
||||
},
|
||||
child: const Text("Decrease"),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
final appTheme = watchIt<AppThemeState>().value;
|
||||
|
||||
return TranslationProvider(
|
||||
child: AppThemeBuilder(
|
||||
theme: appTheme,
|
||||
builder: (lightTheme, darkTheme) =>
|
||||
ImmichApp(lightTheme: lightTheme, darkTheme: darkTheme),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user