Improve repo structure (#22)
* app updated * readme updated * rename base folder * update chatty's readme * move apps to packages dir * update repo overview Co-authored-by: diegoveloper <[email protected]>
This commit is contained in:
co-authored by
diegoveloper
parent
bd6bb66279
commit
030c3eb428
@@ -0,0 +1,19 @@
|
||||
import 'package:stream_chatter/domain/usecases/logout_usecase.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
|
||||
class SettingsSwitchCubit extends Cubit<bool> {
|
||||
SettingsSwitchCubit(bool state) : super(state);
|
||||
|
||||
void onChangeDarkMode(bool isDark) => emit(isDark);
|
||||
}
|
||||
|
||||
class SettingsLogoutCubit extends Cubit<void> {
|
||||
SettingsLogoutCubit(this._logoutUseCase) : super(null);
|
||||
|
||||
final LogoutUseCase _logoutUseCase;
|
||||
|
||||
void logOut() async {
|
||||
await _logoutUseCase.logout();
|
||||
emit(null);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
import 'package:stream_chatter/navigator_utils.dart';
|
||||
import 'package:stream_chatter/ui/app_theme_cubit.dart';
|
||||
import 'package:stream_chatter/ui/common/avatar_image_view.dart';
|
||||
import 'package:stream_chatter/ui/home/settings/settings_cubit.dart';
|
||||
import 'package:stream_chatter/ui/sign_in/sign_in_view.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:stream_chat_flutter/stream_chat_flutter.dart';
|
||||
|
||||
class SettingsView extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final user = StreamChat.of(context).client.state.user;
|
||||
final image = user?.extraData['image'];
|
||||
final textColor = Theme.of(context).appBarTheme.color;
|
||||
return MultiBlocProvider(
|
||||
providers: [
|
||||
BlocProvider(
|
||||
create: (_) => SettingsSwitchCubit(context.read<AppThemeCubit>().isDark),
|
||||
),
|
||||
BlocProvider(
|
||||
create: (_) => SettingsLogoutCubit(context.read()),
|
||||
),
|
||||
],
|
||||
child: Scaffold(
|
||||
backgroundColor: Theme.of(context).canvasColor,
|
||||
appBar: AppBar(
|
||||
title: Text(
|
||||
'Settings',
|
||||
style: TextStyle(
|
||||
fontSize: 24,
|
||||
color: textColor,
|
||||
fontWeight: FontWeight.w800,
|
||||
),
|
||||
),
|
||||
centerTitle: false,
|
||||
elevation: 0,
|
||||
backgroundColor: Theme.of(context).canvasColor,
|
||||
),
|
||||
body: Center(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(15.0),
|
||||
child: Column(
|
||||
children: [
|
||||
AvatarImageView(
|
||||
//TODO: implement change avatar
|
||||
onTap: () => null,
|
||||
child: image != null
|
||||
? Image.network(
|
||||
image,
|
||||
fit: BoxFit.cover,
|
||||
)
|
||||
: Icon(
|
||||
Icons.person_outline,
|
||||
size: 100,
|
||||
color: Colors.grey[400],
|
||||
),
|
||||
),
|
||||
Text(
|
||||
user.name,
|
||||
style: TextStyle(
|
||||
fontSize: 24,
|
||||
color: textColor,
|
||||
fontWeight: FontWeight.w800,
|
||||
),
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
Icon(Icons.nights_stay_outlined),
|
||||
const SizedBox(width: 10),
|
||||
Text(
|
||||
'Dark Mode',
|
||||
style: TextStyle(
|
||||
color: textColor,
|
||||
),
|
||||
),
|
||||
Spacer(),
|
||||
BlocBuilder<SettingsSwitchCubit, bool>(builder: (context, snapshot) {
|
||||
return Switch(
|
||||
value: snapshot,
|
||||
onChanged: (val) {
|
||||
context.read<SettingsSwitchCubit>().onChangeDarkMode(val);
|
||||
context.read<AppThemeCubit>().updateTheme(val);
|
||||
},
|
||||
);
|
||||
}),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 15),
|
||||
Builder(builder: (context) {
|
||||
return GestureDetector(
|
||||
onTap: context.read<SettingsLogoutCubit>().logOut,
|
||||
child: BlocListener<SettingsLogoutCubit, void>(
|
||||
listener: (context, snapshot) {
|
||||
popAllAndPush(context, SignInView());
|
||||
},
|
||||
child: Row(children: [
|
||||
Icon(Icons.logout),
|
||||
const SizedBox(width: 10),
|
||||
Text(
|
||||
'Logout',
|
||||
style: TextStyle(
|
||||
color: textColor,
|
||||
),
|
||||
),
|
||||
Spacer(),
|
||||
Icon(Icons.arrow_right),
|
||||
]),
|
||||
),
|
||||
);
|
||||
}),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user