Skip to content

Commit

Permalink
Apply some refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidMina96 committed Mar 28, 2023
1 parent 79d354f commit d74a441
Show file tree
Hide file tree
Showing 15 changed files with 143 additions and 147 deletions.
20 changes: 14 additions & 6 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:provider/provider.dart';

import 'package:instabug_flutter/instabug_flutter.dart';

import '../models/app_theme.dart';
import '../providers/bug_reporting_state.dart';
import '../providers/core_state.dart';
import '../providers/settings_state.dart';
Expand All @@ -24,18 +25,21 @@ void main() async {
Zone.current.handleUncaughtError(details.exception, details.stack!);
};

runZonedGuarded(() => runApp(const MyApp()), CrashReporting.reportCrash);
runZonedGuarded(
() => runApp(const InstabugApp()),
CrashReporting.reportCrash,
);
}

class MyApp extends StatelessWidget {
const MyApp({super.key});
class InstabugApp extends StatelessWidget {
const InstabugApp({super.key});

@override
Widget build(BuildContext context) {
return MultiProvider(
providers: [
ChangeNotifierProvider<BugReportingState>(
create: (ctx) => BugReportingState(),
create: (_) => BugReportingState(),
),
ChangeNotifierProvider(
create: (_) => CoreState(),
Expand All @@ -45,10 +49,14 @@ class MyApp extends StatelessWidget {
),
],
child: Consumer<SettingsState>(
builder: (context, themeState, child) {
builder: (context, state, child) {
return MaterialApp(
title: 'Instabug Flutter Example',
theme: themeState.getThemeData(),
themeMode: state.colorTheme == ColorTheme.light
? ThemeMode.light
: ThemeMode.dark,
theme: AppTheme.light,
darkTheme: AppTheme.dark,
home: const MainScreen(),
);
},
Expand Down
32 changes: 16 additions & 16 deletions example/lib/models/app_theme.dart
Original file line number Diff line number Diff line change
@@ -1,55 +1,55 @@
import 'package:flutter/material.dart';

abstract class AppColors {
static const primaryColor = Color(0xFF00287a);
static const secondaryColor = Color(0xFF5DAAF0);
static const primaryColorDark = Color(0xFF212121);
static const primary = Color(0xFF00287a);
static const secondary = Color(0xFF5DAAF0);
static const primaryDark = Color(0xFF212121);
}

class AppTheme {
static final lightTheme = ThemeData(
static final light = ThemeData(
colorScheme: ColorScheme.fromSwatch().copyWith(
brightness: Brightness.light,
primary: AppColors.primaryColor,
secondary: AppColors.secondaryColor,
primary: AppColors.primary,
secondary: AppColors.secondary,
),
scaffoldBackgroundColor: Colors.grey[100],
appBarTheme: const AppBarTheme(
color: AppColors.primaryColor,
color: AppColors.primary,
),
visualDensity: VisualDensity.adaptivePlatformDensity,
bottomNavigationBarTheme: const BottomNavigationBarThemeData(
backgroundColor: AppColors.primaryColor,
backgroundColor: AppColors.primary,
unselectedItemColor: Colors.white,
selectedItemColor: AppColors.secondaryColor,
selectedItemColor: AppColors.secondary,
),
chipTheme: const ChipThemeData(
selectedColor: AppColors.secondaryColor,
selectedColor: AppColors.secondary,
),
iconTheme: IconThemeData(color: Colors.grey[600]),
textTheme: const TextTheme(
headlineMedium: TextStyle(
fontFamily: 'Axiforma',
fontSize: 16.0,
color: AppColors.primaryColor,
color: AppColors.primary,
fontWeight: FontWeight.w600,
),
),
);

static final darkTheme = ThemeData.dark().copyWith(
static final dark = ThemeData.dark().copyWith(
colorScheme: ColorScheme.fromSwatch().copyWith(
secondary: AppColors.secondaryColor,
secondary: AppColors.secondary,
),
appBarTheme: const AppBarTheme(
color: AppColors.primaryColorDark,
color: AppColors.primaryDark,
),
visualDensity: VisualDensity.adaptivePlatformDensity,
bottomNavigationBarTheme: const BottomNavigationBarThemeData(
backgroundColor: AppColors.primaryColorDark,
backgroundColor: AppColors.primaryDark,
),
chipTheme: const ChipThemeData(
selectedColor: AppColors.secondaryColor,
selectedColor: AppColors.secondary,
backgroundColor: Color(0xFFB3B3B3),
),
iconTheme: const IconThemeData(color: Colors.white),
Expand Down
6 changes: 6 additions & 0 deletions example/lib/models/attachment_type.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
enum AttachmentType {
screenshot,
extraScreenshot,
galleryImage,
screenRecording
}
61 changes: 28 additions & 33 deletions example/lib/providers/bug_reporting_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,58 +3,53 @@ import 'dart:io';
import 'package:flutter/material.dart';

import 'package:instabug_flutter/instabug_flutter.dart';
import '../models/attachment_type.dart';

class BugReportingState with ChangeNotifier {
var _extraAttachments = {
'Screenshot': true,
'Extra Screenshot': true,
'Gallery Image': true,
'Screen Recording': true
var _extraAttachments = <AttachmentType>{
AttachmentType.screenshot,
AttachmentType.extraScreenshot,
AttachmentType.galleryImage,
AttachmentType.screenRecording,
};
Map<String, bool> get extraAttachments => _extraAttachments;
set extraAttachments(Map<String, bool> attachments) {
Set<AttachmentType> get extraAttachments => _extraAttachments;
set extraAttachments(Set<AttachmentType> attachments) {
_extraAttachments = attachments;
notifyListeners();
}

var _selectedInvocationOptions = <InvocationOption>{};
Set<InvocationOption> get selectedInvocationOptions =>
_selectedInvocationOptions;
set selectedInvocationOptions(Set<InvocationOption> options) {
_selectedInvocationOptions = options;
var _invocationOptions = <InvocationOption>{};
Set<InvocationOption> get invocationOptions => _invocationOptions;
set invocationOptions(Set<InvocationOption> options) {
_invocationOptions = options;
notifyListeners();
}

var _selectedInvocationEvents = <InvocationEvent>{
InvocationEvent.floatingButton
};
Set<InvocationEvent> get selectedInvocationEvents =>
_selectedInvocationEvents;
set selectedInvocationEvents(Set<InvocationEvent> events) {
_selectedInvocationEvents = events;
var _invocationEvents = <InvocationEvent>{InvocationEvent.floatingButton};
Set<InvocationEvent> get invocationEvents => _invocationEvents;
set invocationEvents(Set<InvocationEvent> events) {
_invocationEvents = events;
notifyListeners();
}

var _selectedExtendedMode = ExtendedBugReportMode.disabled;
ExtendedBugReportMode get selectedExtendedMode => _selectedExtendedMode;
set selectedExtendedMode(ExtendedBugReportMode mode) {
_selectedExtendedMode = mode;
var _extendedMode = ExtendedBugReportMode.disabled;
ExtendedBugReportMode get extendedMode => _extendedMode;
set extendedMode(ExtendedBugReportMode mode) {
_extendedMode = mode;
notifyListeners();
}

var _selectedVideoRecordingPosition = Position.bottomRight;
Position get selectedVideoRecordingPosition =>
_selectedVideoRecordingPosition;
set selectedVideoRecordingPosition(Position position) {
_selectedVideoRecordingPosition = position;
var _videoRecordingPosition = Position.bottomRight;
Position get videoRecordingPosition => _videoRecordingPosition;
set videoRecordingPosition(Position position) {
_videoRecordingPosition = position;
notifyListeners();
}

var _selectedFloatingButtonEdge = FloatingButtonEdge.right;
FloatingButtonEdge get selectedFloatingButtonEdge =>
_selectedFloatingButtonEdge;
set selectedFloatingButtonEdge(FloatingButtonEdge edge) {
_selectedFloatingButtonEdge = edge;
var _floatingButtonEdge = FloatingButtonEdge.right;
FloatingButtonEdge get floatingButtonEdge => _floatingButtonEdge;
set floatingButtonEdge(FloatingButtonEdge edge) {
_floatingButtonEdge = edge;
notifyListeners();
}

Expand Down
8 changes: 4 additions & 4 deletions example/lib/providers/core_state.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import 'package:flutter/material.dart';

class CoreState extends ChangeNotifier {
bool _isDisabled = false;
bool _isEnabled = true;

bool get isDisabled => _isDisabled;
set isDisabled(bool value) {
_isDisabled = value;
bool get isEnabled => _isEnabled;
set isEnabled(bool value) {
_isEnabled = value;
notifyListeners();
}
}
19 changes: 10 additions & 9 deletions example/lib/providers/settings_state.dart
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import 'package:flutter/material.dart';

import '../models/app_theme.dart';
import 'package:instabug_flutter/instabug_flutter.dart';

class SettingsState extends ChangeNotifier {
bool _isDarkTheme = false;
ThemeData _themeData = AppTheme.lightTheme;
ColorTheme _theme = ColorTheme.light;
// bool _isDarkTheme = false;
// ThemeData _themeData = AppTheme.lightTheme;

bool get isDarkTheme => _isDarkTheme;
// bool get isDarkTheme => _isDarkTheme;

ThemeData getThemeData() => _themeData;
void setThemeData(bool isDarkMode) {
_isDarkTheme = !_isDarkTheme;
_themeData = isDarkMode ? AppTheme.darkTheme : AppTheme.lightTheme;
ColorTheme get colorTheme => _theme;
void setColorTheme(ColorTheme theme) {
// _isDarkTheme = !_isDarkTheme;
// _themeData = isDarkMode ? AppTheme.dark : AppTheme.light;
_theme = theme;
notifyListeners();
}

Expand Down
Loading

0 comments on commit d74a441

Please sign in to comment.