Skip to content

Instantly share code, notes, and snippets.

@mahmudahsan
Created September 11, 2020 12:14
Show Gist options
  • Save mahmudahsan/68735815fb3313deda65e8eb4100c3f6 to your computer and use it in GitHub Desktop.
Save mahmudahsan/68735815fb3313deda65e8eb4100c3f6 to your computer and use it in GitHub Desktop.
import 'package:flutter/material.dart';
import 'package:states_bloc/drawer_menu.dart';
import 'package:states_bloc/bloc/settings/settings_bloc.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
class Settings extends StatelessWidget {
double _value = 0.5;
bool isBold = false;
bool isItalic = false;
@override
Widget build(BuildContext context) {
final SettingsBloc settingsBloc = BlocProvider.of<SettingsBloc>(context);
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.teal,
title: Text('Settings'),
),
drawer: DrawerMenu(),
body: BlocBuilder<SettingsBloc, SettingsState>(
builder: (context, state) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Padding(
padding: EdgeInsets.only(left: 20, top: 20),
child: Text(
'Font Size: ${state.fontSize.toInt()}',
style: TextStyle(
fontSize: Theme.of(context).textTheme.headline.fontSize),
),
),
Slider(
min: 0.5,
value: state.sliderFontSize,
onChanged: (newValue) {
settingsBloc.dispatch(FontSize(newValue));
}),
Container(
margin: EdgeInsets.symmetric(horizontal: 8),
child: Row(
children: <Widget>[
Checkbox(
value: state.isBold,
onChanged: (newVal) {
settingsBloc.dispatch(Bold(newVal));
},
),
Text(
'Bold',
style: getStyle(state.isBold, false),
),
],
),
),
Container(
margin: EdgeInsets.symmetric(horizontal: 8),
child: Row(
children: <Widget>[
Checkbox(
value: state.isItalic,
onChanged: (newVal) {
settingsBloc.dispatch(Italic(newVal));
}),
Text(
'Italic',
style: getStyle(false, state.isItalic),
),
],
),
),
],
);
},
),
);
}
TextStyle getStyle([bool isBold = false, bool isItalic = false]) {
return TextStyle(
fontSize: 18,
fontWeight: isBold ? FontWeight.bold : FontWeight.normal,
fontStyle: isItalic ? FontStyle.italic : FontStyle.normal,
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment