Skip to content

Commit

Permalink
chore(cleanup): some context adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
Kounex committed Dec 15, 2023
1 parent b414ebf commit 1551186
Show file tree
Hide file tree
Showing 41 changed files with 190 additions and 105 deletions.
25 changes: 23 additions & 2 deletions lib/shared/general/base/adaptive_text_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,27 @@ class BaseAdaptiveTextFieldState extends State<BaseAdaptiveTextField> {
super.dispose();
}

List<TextInputFormatter>? _textInputFormatter() {
if (this.widget.inputFormatters != null) {
return this.widget.inputFormatters;
}

if (this.widget.keyboardType == TextInputType.number) {
return [
FilteringTextInputFormatter.digitsOnly,
];
}

if (this.widget.keyboardType ==
const TextInputType.numberWithOptions(decimal: true)) {
return [
FilteringTextInputFormatter.deny(',', replacementString: '.'),
FilteringTextInputFormatter.allow(RegExp(r'^-?\d*\.?\d*')),
];
}
return null;
}

@override
Widget build(BuildContext context) {
return Column(
Expand All @@ -148,7 +169,7 @@ class BaseAdaptiveTextFieldState extends State<BaseAdaptiveTextField> {
cursorColor: Theme.of(context).textSelectionTheme.cursorColor,
placeholder: this.widget.placeholder,
keyboardType: this.widget.keyboardType,
inputFormatters: this.widget.inputFormatters ?? [],
inputFormatters: _textInputFormatter(),
minLines: this.widget.minLines,
maxLines: this.widget.maxLines ?? this.widget.minLines,
autocorrect: this.widget.autocorrect,
Expand Down Expand Up @@ -192,7 +213,7 @@ class BaseAdaptiveTextFieldState extends State<BaseAdaptiveTextField> {
: null,
),
keyboardType: this.widget.keyboardType,
inputFormatters: this.widget.inputFormatters ?? [],
inputFormatters: _textInputFormatter(),
minLines: this.widget.minLines,
maxLines: this.widget.maxLines ?? this.widget.minLines,
autocorrect: this.widget.autocorrect,
Expand Down
2 changes: 1 addition & 1 deletion lib/shared/general/cupertino_dropdown.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class CupertinoDropdown<T> extends StatelessWidget {
right: 2.0,
),
child: DropdownButton<T>(
underline: Container(),
underline: const SizedBox(),
isExpanded: true,
isDense: true,
value: this.value,
Expand Down
2 changes: 1 addition & 1 deletion lib/shared/general/custom_expansion_tile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ class _CustomExpansionTileState extends State<CustomExpansionTile>
),
),
),
collapsed: Container(),
collapsed: const SizedBox(),
expanded: this.widget.expandedBody,
),
);
Expand Down
14 changes: 9 additions & 5 deletions lib/stores/views/dashboard.dart
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ abstract class _DashboardStore with Store {
!defaultFilter.filterSettings.containsKey(key)));
}

Filter _filterWithDefaults(Filter filter) {
Filter _populateFiltersWithDefaults(Filter filter) {
try {
final defaultFilterSettings = _defaultFilters
.firstWhere(
Expand Down Expand Up @@ -1642,11 +1642,13 @@ abstract class _DashboardStore with Store {
/// default FilterSettings of these.
List<Filter> filters = [...sceneItem.filters];

/// If this is the first time we fetch the current [Filter]s, we
/// can just add them since there are no default ones.
/// If this is the first time we fetch the current [Filter]s or we
/// have new ones or some were deleted, we can just add them since
/// there are no default ones.
if (filters.length != responseFilters.length) {
filters = [];
filters.addAll(responseFilters.map(_filterWithDefaults));
filters
.addAll(responseFilters.map(_populateFiltersWithDefaults));
} else {
/// We handle this case if this is a subsequent fetch and our
/// [Filter]s are already populated. Here we need to make sure
Expand Down Expand Up @@ -1746,7 +1748,9 @@ abstract class _DashboardStore with Store {
this.currentSceneItems = ObservableList.of(
this.currentSceneItems.map(
(sceneItem) => sceneItem.copyWith(
filters: sceneItem.filters.map(_filterWithDefaults).toList(),
filters: sceneItem.filters
.map(_populateFiltersWithDefaults)
.toList(),
),
),
);
Expand Down
2 changes: 1 addition & 1 deletion lib/stores/views/statistics.dart
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ abstract class _StatisticsStore with Store {
this.excludeUnnamedStats = false;
this.statType = StatType.All;
this.durationFilter = null;
this.durationFilterAmount;
this.durationFilterAmount = null;
this.durationFilterTimeUnit = TimeUnit.Minutes;

/// Used as a toggle (only listen for change, not value) to exactly determine
Expand Down
4 changes: 2 additions & 2 deletions lib/tab_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class _TabBaseState extends State<TabBase> {
TabsStore tabsStore = GetIt.instance<TabsStore>();

return Scaffold(
body: Observer(builder: (_) {
body: Observer(builder: (context) {
return WillPopScope(
onWillPop: () {
if (tabsStore.navigatorKeys[tabsStore.activeTab]!.currentState!
Expand Down Expand Up @@ -131,7 +131,7 @@ class _TabBaseState extends State<TabBase> {
}),
extendBody: true,
bottomNavigationBar: Observer(
builder: (_) => CupertinoTabBar(
builder: (context) => CupertinoTabBar(
backgroundColor: !StylingHelper.isApple(context)
? CupertinoTheme.of(context).barBackgroundColor.withOpacity(1.0)
: null,
Expand Down
2 changes: 1 addition & 1 deletion lib/views/dashboard/dashboard.dart
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ class _DashboardViewState extends State<DashboardView> {
@override
Widget build(BuildContext context) {
return ThemedCupertinoScaffold(
body: Observer(builder: (_) {
body: Observer(builder: (context) {
return Stack(
alignment: Alignment.topCenter,
children: [
Expand Down
2 changes: 1 addition & 1 deletion lib/views/dashboard/widgets/obs_widgets/stats/stats.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class _StatsState extends State<Stats> {
),
),
Expanded(
child: Observer(builder: (_) {
child: Observer(builder: (context) {
return PageView(
controller: _pageController,
children: <Widget>[
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import 'package:flutter/material.dart';
import 'package:obs_blade/shared/general/base/card.dart';
import 'package:obs_blade/shared/general/base/divider.dart';
import 'package:obs_blade/shared/general/custom_expansion_tile.dart';
import 'package:obs_blade/shared/general/described_box.dart';
import 'package:obs_blade/views/dashboard/widgets/scenes/exposed_controls/hotkeys_control/hotkeys_control.dart';
import 'package:obs_blade/views/dashboard/widgets/scenes/exposed_controls/replay_buffer_controls.dart';
Expand Down Expand Up @@ -90,8 +92,23 @@ class ExposedControls extends StatelessWidget {
return exposedControls.isNotEmpty
? BaseCard(
bottomPadding: 0.0,
child: Column(
children: exposedControls,
paddingChild: const EdgeInsets.symmetric(vertical: 18.0),
child: CustomExpansionTile(
headerText: 'Exposed Controls',
headerPadding: const EdgeInsets.symmetric(horizontal: 18.0),
expandedBody: Column(
children: [
const SizedBox(height: 18.0),
const BaseDivider(),
const SizedBox(height: 24.0),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 18.0),
child: Column(
children: exposedControls,
),
)
],
),
),
)
: const SizedBox();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class SceneButton extends StatelessWidget {
hiveKey: HiveKeys.Settings,
rebuildKeys: const [SettingsKeys.ExposeStudioControls],
builder: (context, settingsBox, child) => Observer(
builder: (_) =>
builder: (context) =>
// GestureDetector(
// onTap: () {
// if (dashboardStore.editSceneVisibility) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ class SceneButtons extends StatelessWidget {

return HiveBuilder<HiddenScene>(
hiveKey: HiveKeys.HiddenScene,
builder: (context, hiddenScenesBox, child) => Observer(builder: (_) {
builder: (context, hiddenScenesBox, child) =>
Observer(builder: (context) {
Iterable<Scene>? visibleScenes = dashboardStore.scenes;
List<HiddenScene> hiddenScenes = [];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class _AudioInputsState extends State<AudioInputs>
DashboardStore dashboardStore = GetIt.instance<DashboardStore>();

return Observer(
builder: (_) => NestedScrollManager(
builder: (context) => NestedScrollManager(
parentScrollController:
ModalRoute.of(context)!.settings.arguments as ScrollController,
child: Scrollbar(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:obs_blade/shared/general/base/adaptive_switch.dart';
import 'package:obs_blade/shared/general/base/adaptive_text_field.dart';
import 'package:obs_blade/shared/general/keyboard_number_header.dart';

enum InputType {
Int,
Expand Down Expand Up @@ -75,22 +76,28 @@ class _DynamicInputState extends State<DynamicInput> {
width: 102.0,
alignment: Alignment.centerRight,
child: switch (_type) {
InputType.Int => BaseAdaptiveTextField(
InputType.Int => KeyboardNumberHeader(
focusNode: _focusNode,
controller: _controller,
keyboardType: TextInputType.number,
onChanged: (value) => int.tryParse(value) != null
? this.widget.onUpdate?.call(int.parse(value))
: null,
child: BaseAdaptiveTextField(
focusNode: _focusNode,
controller: _controller,
keyboardType: TextInputType.number,
onChanged: (value) => int.tryParse(value) != null
? this.widget.onUpdate?.call(int.parse(value))
: null,
),
),
InputType.Double => BaseAdaptiveTextField(
InputType.Double => KeyboardNumberHeader(
focusNode: _focusNode,
controller: _controller,
keyboardType:
const TextInputType.numberWithOptions(decimal: true),
onChanged: (value) => double.tryParse(value) != null
? this.widget.onUpdate?.call(double.parse(value))
: null,
child: BaseAdaptiveTextField(
focusNode: _focusNode,
controller: _controller,
keyboardType:
const TextInputType.numberWithOptions(decimal: true),
onChanged: (value) => double.tryParse(value) != null
? this.widget.onUpdate?.call(double.parse(value))
: null,
),
),
InputType.Bool => BaseAdaptiveSwitch(
value: this.widget.value,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class _FilterListState extends State<FilterList> {
child: Scrollbar(
child: ListView(
padding: EdgeInsets.only(
bottom: MediaQuery.paddingOf(context).bottom + 12.0,
bottom: MediaQuery.paddingOf(context).bottom + 24.0,
),
children: sceneItem.filters
.map(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class _SceneItemsState extends State<SceneItems>
super.build(context);
DashboardStore dashboardStore = GetIt.instance<DashboardStore>();

return Observer(builder: (_) {
return Observer(builder: (context) {
return NestedScrollManager(
parentScrollController:
ModalRoute.of(context)!.settings.arguments as ScrollController,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class VisibilityEditToggle extends StatelessWidget {
};

Widget editButton = Observer(
builder: (_) => ThemedCupertinoButton(
builder: (context) => ThemedCupertinoButton(
text: (this.sceneItemType == SceneItemType.Source
? dashboardStore.editSceneItemVisibility
: dashboardStore.editAudioVisibility)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class _VisibilitySlideWrapperState extends State<VisibilitySlideWrapper> {
}

return Observer(
builder: (_) => Offstage(
builder: (context) => Offstage(
offstage: _isItemHidden(
dashboardStore, hiddenSceneItemsBox, hiddenSceneItem),
child: Slidable(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class _ScenePreviewState extends State<ScenePreview> {
child: Padding(
padding: const EdgeInsets.all(12.0),
child: Observer(
builder: (_) => Stack(
builder: (context) => Stack(
children: [
if (dashboardStore.scenePreviewImageBytes != null)
Column(
Expand Down
Loading

0 comments on commit 1551186

Please sign in to comment.