Skip to content

Commit a609c97

Browse files
committed
Apply some refactoring
1 parent 79d354f commit a609c97

15 files changed

+143
-146
lines changed

example/lib/main.dart

+14-6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import 'package:provider/provider.dart';
44

55
import 'package:instabug_flutter/instabug_flutter.dart';
66

7+
import '../models/app_theme.dart';
78
import '../providers/bug_reporting_state.dart';
89
import '../providers/core_state.dart';
910
import '../providers/settings_state.dart';
@@ -24,18 +25,21 @@ void main() async {
2425
Zone.current.handleUncaughtError(details.exception, details.stack!);
2526
};
2627

27-
runZonedGuarded(() => runApp(const MyApp()), CrashReporting.reportCrash);
28+
runZonedGuarded(
29+
() => runApp(const InstabugApp()),
30+
CrashReporting.reportCrash,
31+
);
2832
}
2933

30-
class MyApp extends StatelessWidget {
31-
const MyApp({super.key});
34+
class InstabugApp extends StatelessWidget {
35+
const InstabugApp({super.key});
3236

3337
@override
3438
Widget build(BuildContext context) {
3539
return MultiProvider(
3640
providers: [
3741
ChangeNotifierProvider<BugReportingState>(
38-
create: (ctx) => BugReportingState(),
42+
create: (_) => BugReportingState(),
3943
),
4044
ChangeNotifierProvider(
4145
create: (_) => CoreState(),
@@ -45,10 +49,14 @@ class MyApp extends StatelessWidget {
4549
),
4650
],
4751
child: Consumer<SettingsState>(
48-
builder: (context, themeState, child) {
52+
builder: (context, state, child) {
4953
return MaterialApp(
5054
title: 'Instabug Flutter Example',
51-
theme: themeState.getThemeData(),
55+
themeMode: state.colorTheme == ColorTheme.light
56+
? ThemeMode.light
57+
: ThemeMode.dark,
58+
theme: AppTheme.light,
59+
darkTheme: AppTheme.dark,
5260
home: const MainScreen(),
5361
);
5462
},

example/lib/models/app_theme.dart

+16-16
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,55 @@
11
import 'package:flutter/material.dart';
22

33
abstract class AppColors {
4-
static const primaryColor = Color(0xFF00287a);
5-
static const secondaryColor = Color(0xFF5DAAF0);
6-
static const primaryColorDark = Color(0xFF212121);
4+
static const primary = Color(0xFF00287a);
5+
static const secondary = Color(0xFF5DAAF0);
6+
static const primaryDark = Color(0xFF212121);
77
}
88

99
class AppTheme {
10-
static final lightTheme = ThemeData(
10+
static final light = ThemeData(
1111
colorScheme: ColorScheme.fromSwatch().copyWith(
1212
brightness: Brightness.light,
13-
primary: AppColors.primaryColor,
14-
secondary: AppColors.secondaryColor,
13+
primary: AppColors.primary,
14+
secondary: AppColors.secondary,
1515
),
1616
scaffoldBackgroundColor: Colors.grey[100],
1717
appBarTheme: const AppBarTheme(
18-
color: AppColors.primaryColor,
18+
color: AppColors.primary,
1919
),
2020
visualDensity: VisualDensity.adaptivePlatformDensity,
2121
bottomNavigationBarTheme: const BottomNavigationBarThemeData(
22-
backgroundColor: AppColors.primaryColor,
22+
backgroundColor: AppColors.primary,
2323
unselectedItemColor: Colors.white,
24-
selectedItemColor: AppColors.secondaryColor,
24+
selectedItemColor: AppColors.secondary,
2525
),
2626
chipTheme: const ChipThemeData(
27-
selectedColor: AppColors.secondaryColor,
27+
selectedColor: AppColors.secondary,
2828
),
2929
iconTheme: IconThemeData(color: Colors.grey[600]),
3030
textTheme: const TextTheme(
3131
headlineMedium: TextStyle(
3232
fontFamily: 'Axiforma',
3333
fontSize: 16.0,
34-
color: AppColors.primaryColor,
34+
color: AppColors.primary,
3535
fontWeight: FontWeight.w600,
3636
),
3737
),
3838
);
3939

40-
static final darkTheme = ThemeData.dark().copyWith(
40+
static final dark = ThemeData.dark().copyWith(
4141
colorScheme: ColorScheme.fromSwatch().copyWith(
42-
secondary: AppColors.secondaryColor,
42+
secondary: AppColors.secondary,
4343
),
4444
appBarTheme: const AppBarTheme(
45-
color: AppColors.primaryColorDark,
45+
color: AppColors.primaryDark,
4646
),
4747
visualDensity: VisualDensity.adaptivePlatformDensity,
4848
bottomNavigationBarTheme: const BottomNavigationBarThemeData(
49-
backgroundColor: AppColors.primaryColorDark,
49+
backgroundColor: AppColors.primaryDark,
5050
),
5151
chipTheme: const ChipThemeData(
52-
selectedColor: AppColors.secondaryColor,
52+
selectedColor: AppColors.secondary,
5353
backgroundColor: Color(0xFFB3B3B3),
5454
),
5555
iconTheme: const IconThemeData(color: Colors.white),
+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
enum AttachmentType {
2+
screenshot,
3+
extraScreenshot,
4+
galleryImage,
5+
screenRecording
6+
}

example/lib/providers/bug_reporting_state.dart

+28-33
Original file line numberDiff line numberDiff line change
@@ -3,58 +3,53 @@ import 'dart:io';
33
import 'package:flutter/material.dart';
44

55
import 'package:instabug_flutter/instabug_flutter.dart';
6+
import '../models/attachment_type.dart';
67

78
class BugReportingState with ChangeNotifier {
8-
var _extraAttachments = {
9-
'Screenshot': true,
10-
'Extra Screenshot': true,
11-
'Gallery Image': true,
12-
'Screen Recording': true
9+
var _extraAttachments = <AttachmentType>{
10+
AttachmentType.screenshot,
11+
AttachmentType.extraScreenshot,
12+
AttachmentType.galleryImage,
13+
AttachmentType.screenRecording,
1314
};
14-
Map<String, bool> get extraAttachments => _extraAttachments;
15-
set extraAttachments(Map<String, bool> attachments) {
15+
Set<AttachmentType> get extraAttachments => _extraAttachments;
16+
set extraAttachments(Set<AttachmentType> attachments) {
1617
_extraAttachments = attachments;
1718
notifyListeners();
1819
}
1920

20-
var _selectedInvocationOptions = <InvocationOption>{};
21-
Set<InvocationOption> get selectedInvocationOptions =>
22-
_selectedInvocationOptions;
23-
set selectedInvocationOptions(Set<InvocationOption> options) {
24-
_selectedInvocationOptions = options;
21+
var _invocationOptions = <InvocationOption>{};
22+
Set<InvocationOption> get invocationOptions => _invocationOptions;
23+
set invocationOptions(Set<InvocationOption> options) {
24+
_invocationOptions = options;
2525
notifyListeners();
2626
}
2727

28-
var _selectedInvocationEvents = <InvocationEvent>{
29-
InvocationEvent.floatingButton
30-
};
31-
Set<InvocationEvent> get selectedInvocationEvents =>
32-
_selectedInvocationEvents;
33-
set selectedInvocationEvents(Set<InvocationEvent> events) {
34-
_selectedInvocationEvents = events;
28+
var _invocationEvents = <InvocationEvent>{InvocationEvent.floatingButton};
29+
Set<InvocationEvent> get invocationEvents => _invocationEvents;
30+
set invocationEvents(Set<InvocationEvent> events) {
31+
_invocationEvents = events;
3532
notifyListeners();
3633
}
3734

38-
var _selectedExtendedMode = ExtendedBugReportMode.disabled;
39-
ExtendedBugReportMode get selectedExtendedMode => _selectedExtendedMode;
40-
set selectedExtendedMode(ExtendedBugReportMode mode) {
41-
_selectedExtendedMode = mode;
35+
var _extendedMode = ExtendedBugReportMode.disabled;
36+
ExtendedBugReportMode get extendedMode => _extendedMode;
37+
set extendedMode(ExtendedBugReportMode mode) {
38+
_extendedMode = mode;
4239
notifyListeners();
4340
}
4441

45-
var _selectedVideoRecordingPosition = Position.bottomRight;
46-
Position get selectedVideoRecordingPosition =>
47-
_selectedVideoRecordingPosition;
48-
set selectedVideoRecordingPosition(Position position) {
49-
_selectedVideoRecordingPosition = position;
42+
var _videoRecordingPosition = Position.bottomRight;
43+
Position get videoRecordingPosition => _videoRecordingPosition;
44+
set videoRecordingPosition(Position position) {
45+
_videoRecordingPosition = position;
5046
notifyListeners();
5147
}
5248

53-
var _selectedFloatingButtonEdge = FloatingButtonEdge.right;
54-
FloatingButtonEdge get selectedFloatingButtonEdge =>
55-
_selectedFloatingButtonEdge;
56-
set selectedFloatingButtonEdge(FloatingButtonEdge edge) {
57-
_selectedFloatingButtonEdge = edge;
49+
var _floatingButtonEdge = FloatingButtonEdge.right;
50+
FloatingButtonEdge get floatingButtonEdge => _floatingButtonEdge;
51+
set floatingButtonEdge(FloatingButtonEdge edge) {
52+
_floatingButtonEdge = edge;
5853
notifyListeners();
5954
}
6055

example/lib/providers/core_state.dart

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import 'package:flutter/material.dart';
22

33
class CoreState extends ChangeNotifier {
4-
bool _isDisabled = false;
4+
bool _isEnabled = true;
55

6-
bool get isDisabled => _isDisabled;
7-
set isDisabled(bool value) {
8-
_isDisabled = value;
6+
bool get isEnabled => _isEnabled;
7+
set isEnabled(bool value) {
8+
_isEnabled = value;
99
notifyListeners();
1010
}
1111
}

example/lib/providers/settings_state.dart

+10-9
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
import 'package:flutter/material.dart';
2-
3-
import '../models/app_theme.dart';
2+
import 'package:instabug_flutter/instabug_flutter.dart';
43

54
class SettingsState extends ChangeNotifier {
6-
bool _isDarkTheme = false;
7-
ThemeData _themeData = AppTheme.lightTheme;
5+
ColorTheme _theme = ColorTheme.light;
6+
// bool _isDarkTheme = false;
7+
// ThemeData _themeData = AppTheme.lightTheme;
88

9-
bool get isDarkTheme => _isDarkTheme;
9+
// bool get isDarkTheme => _isDarkTheme;
1010

11-
ThemeData getThemeData() => _themeData;
12-
void setThemeData(bool isDarkMode) {
13-
_isDarkTheme = !_isDarkTheme;
14-
_themeData = isDarkMode ? AppTheme.darkTheme : AppTheme.lightTheme;
11+
ColorTheme get colorTheme => _theme;
12+
void setColorTheme(ColorTheme theme) {
13+
// _isDarkTheme = !_isDarkTheme;
14+
// _themeData = isDarkMode ? AppTheme.dark : AppTheme.light;
15+
_theme = theme;
1516
notifyListeners();
1617
}
1718

0 commit comments

Comments
 (0)