mirror of
https://github.com/immich-app/immich.git
synced 2025-07-07 10:14:08 -04:00
example
This commit is contained in:
parent
1d3493e00b
commit
4a7137c50c
@ -1,5 +1,7 @@
|
||||
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';
|
||||
|
||||
void main() {
|
||||
// Ensure the bindings are initialized
|
||||
@ -22,7 +24,41 @@ class MainWidget extends StatelessWidget {
|
||||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
|
||||
useMaterial3: true,
|
||||
),
|
||||
home: const Text('Flutter Demo Home Page'),
|
||||
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"),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
15
mobile-v2/lib/presentation/home_page/cubit/home_cubit.dart
Normal file
15
mobile-v2/lib/presentation/home_page/cubit/home_cubit.dart
Normal file
@ -0,0 +1,15 @@
|
||||
import 'package:bloc/bloc.dart';
|
||||
|
||||
part 'home_state.dart';
|
||||
|
||||
class HomeCubit extends Cubit<HomeState> {
|
||||
HomeCubit() : super(HomeState(albumCount: 0));
|
||||
|
||||
void increaseAlbumCount() {
|
||||
emit(state.copyWith(albumCount: state.albumCount + 1));
|
||||
}
|
||||
|
||||
void decreaseAlbumCount() {
|
||||
emit(state.copyWith(albumCount: state.albumCount - 1));
|
||||
}
|
||||
}
|
41
mobile-v2/lib/presentation/home_page/cubit/home_state.dart
Normal file
41
mobile-v2/lib/presentation/home_page/cubit/home_state.dart
Normal file
@ -0,0 +1,41 @@
|
||||
part of 'home_cubit.dart';
|
||||
|
||||
class HomeState {
|
||||
final int albumCount;
|
||||
HomeState({
|
||||
required this.albumCount,
|
||||
});
|
||||
|
||||
HomeState copyWith({
|
||||
int? albumCount,
|
||||
}) {
|
||||
return HomeState(
|
||||
albumCount: albumCount ?? this.albumCount,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toMap() {
|
||||
return {
|
||||
'albumCount': albumCount,
|
||||
};
|
||||
}
|
||||
|
||||
factory HomeState.fromMap(Map<String, dynamic> map) {
|
||||
return HomeState(
|
||||
albumCount: map['albumCount']?.toInt() ?? 0,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() => 'HomeState(albumCount: $albumCount)';
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
if (identical(this, other)) return true;
|
||||
|
||||
return other is HomeState && other.albumCount == albumCount;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => albumCount.hashCode;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user