Merge pull request #417 from DenserMeerkat/resolve-issue-deprecations

fix: color, deprecations and tests
This commit is contained in:
Ashita Prasad
2024-06-30 16:44:04 +05:30
committed by GitHub
40 changed files with 459 additions and 227 deletions

View File

@ -26,7 +26,7 @@ final kIsAndroid = !kIsWeb && Platform.isAndroid;
final kIsMobile = !kIsWeb && (Platform.isIOS || Platform.isAndroid);
final kColorTransparentState =
MaterialStateProperty.all<Color>(Colors.transparent);
WidgetStateProperty.all<Color>(Colors.transparent);
const kColorTransparent = Colors.transparent;
const kColorWhite = Colors.white;
const kColorBlack = Colors.black;
@ -65,6 +65,7 @@ const kFormDataButtonLabelTextStyle = TextStyle(
fontSize: 12,
fontWeight: FontWeight.w600,
);
const kTextStylePopupMenuItem = TextStyle(fontSize: 16);
const kBorderRadius4 = BorderRadius.all(Radius.circular(4));
const kBorderRadius8 = BorderRadius.all(Radius.circular(8));

View File

@ -70,8 +70,8 @@ class EditorTitleActions extends StatelessWidget {
message: tooltip,
child: IconButton(
style: ButtonStyle(
padding: MaterialStateProperty.all(const EdgeInsets.all(0) + padding),
shape: MaterialStateProperty.all(const ContinuousRectangleBorder()),
padding: WidgetStateProperty.all(const EdgeInsets.all(0) + padding),
shape: WidgetStateProperty.all(const ContinuousRectangleBorder()),
),
onPressed: onPressed,
icon: Icon(

View File

@ -44,7 +44,7 @@ class EnvCellField extends StatelessWidget {
),
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(
color: clrScheme.surfaceVariant,
color: clrScheme.surfaceContainerHighest,
),
),
),

View File

@ -19,7 +19,7 @@ class SidebarFilter extends StatelessWidget {
decoration: BoxDecoration(
borderRadius: kBorderRadius8,
border: Border.all(
color: Theme.of(context).colorScheme.surfaceVariant,
color: Theme.of(context).colorScheme.surfaceContainerHighest,
),
),
child: Row(

View File

@ -88,7 +88,7 @@ class Dashboard extends ConsumerWidget {
VerticalDivider(
thickness: 1,
width: 1,
color: Theme.of(context).colorScheme.surfaceVariant,
color: Theme.of(context).colorScheme.surfaceContainerHighest,
),
Expanded(
child: IndexedStack(

View File

@ -177,7 +177,7 @@ class EditEnvironmentSecretsState
children: [
Container(
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.background,
color: Theme.of(context).colorScheme.surface,
borderRadius: kBorderRadius12,
),
margin: kP10,

View File

@ -178,7 +178,7 @@ class EditEnvironmentVariablesState
children: [
Container(
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.background,
color: Theme.of(context).colorScheme.surface,
borderRadius: kBorderRadius12,
),
margin: kP10,

View File

@ -17,59 +17,54 @@ class EditRequestBody extends ConsumerWidget {
final contentType = ref.watch(selectedRequestModelProvider
.select((value) => value?.httpRequestModel?.bodyContentType));
return Container(
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.background,
),
child: Column(
children: [
const SizedBox(
height: kHeaderHeight,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
"Select Content Type:",
),
DropdownButtonBodyContentType(),
],
),
return Column(
children: [
const SizedBox(
height: kHeaderHeight,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
"Select Content Type:",
),
DropdownButtonBodyContentType(),
],
),
Expanded(
child: switch (contentType) {
ContentType.formdata =>
const Padding(padding: kPh4, child: FormDataWidget()),
// TODO: Fix JsonTextFieldEditor & plug it here
ContentType.json => Padding(
padding: kPt5o10,
child: TextFieldEditor(
key: Key("$selectedId-json-body"),
fieldKey: "$selectedId-json-body-editor",
initialValue: requestModel?.httpRequestModel?.body,
onChanged: (String value) {
ref
.read(collectionStateNotifierProvider.notifier)
.update(selectedId, body: value);
},
),
),
Expanded(
child: switch (contentType) {
ContentType.formdata =>
const Padding(padding: kPh4, child: FormDataWidget()),
// TODO: Fix JsonTextFieldEditor & plug it here
ContentType.json => Padding(
padding: kPt5o10,
child: TextFieldEditor(
key: Key("$selectedId-json-body"),
fieldKey: "$selectedId-json-body-editor",
initialValue: requestModel?.httpRequestModel?.body,
onChanged: (String value) {
ref
.read(collectionStateNotifierProvider.notifier)
.update(selectedId, body: value);
},
),
_ => Padding(
padding: kPt5o10,
child: TextFieldEditor(
key: Key("$selectedId-body"),
fieldKey: "$selectedId-body-editor",
initialValue: requestModel?.httpRequestModel?.body,
onChanged: (String value) {
ref
.read(collectionStateNotifierProvider.notifier)
.update(selectedId, body: value);
},
),
),
_ => Padding(
padding: kPt5o10,
child: TextFieldEditor(
key: Key("$selectedId-body"),
fieldKey: "$selectedId-body-editor",
initialValue: requestModel?.httpRequestModel?.body,
onChanged: (String value) {
ref
.read(collectionStateNotifierProvider.notifier)
.update(selectedId, body: value);
},
),
},
)
],
),
),
},
)
],
);
}
}

View File

@ -201,10 +201,6 @@ class _FormDataBodyState extends ConsumerState<FormDataWidget> {
return Stack(
children: [
Container(
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.background,
borderRadius: kBorderRadius12,
),
margin: kP10,
child: Column(
children: [

View File

@ -179,10 +179,6 @@ class EditRequestHeadersState extends ConsumerState<EditRequestHeaders> {
return Stack(
children: [
Container(
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.background,
borderRadius: kBorderRadius12,
),
margin: kP10,
child: Column(
children: [

View File

@ -179,10 +179,6 @@ class EditRequestURLParamsState extends ConsumerState<EditRequestURLParams> {
return Stack(
children: [
Container(
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.background,
borderRadius: kBorderRadius12,
),
margin: kP10,
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,

View File

@ -12,10 +12,12 @@ class EditorPaneRequestURLCard extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Card(
color: kColorTransparent,
surfaceTintColor: kColorTransparent,
elevation: 0,
shape: RoundedRectangleBorder(
side: BorderSide(
color: Theme.of(context).colorScheme.surfaceVariant,
color: Theme.of(context).colorScheme.surfaceContainerHighest,
),
borderRadius: kBorderRadius12,
),
@ -32,7 +34,6 @@ class EditorPaneRequestURLCard extends StatelessWidget {
Expanded(
child: URLTextField(),
),
SizedBox.shrink(),
],
)
: const Row(

View File

@ -21,9 +21,9 @@ class PageBase extends ConsumerWidget {
final isDarkMode =
ref.watch(settingsProvider.select((value) => value.isDark));
final scaffold = Scaffold(
backgroundColor: Theme.of(context).colorScheme.background,
backgroundColor: Theme.of(context).colorScheme.surface,
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.background,
backgroundColor: Theme.of(context).colorScheme.surface,
primary: true,
title: Text(title),
centerTitle: true,

View File

@ -4,7 +4,7 @@ import '../providers/providers.dart';
import '../widgets/widgets.dart';
import '../common/utils.dart';
import '../consts.dart';
import 'package:apidash/extensions/extensions.dart';
import '../extensions/extensions.dart';
class SettingsPage extends ConsumerWidget {
const SettingsPage({super.key});
@ -76,27 +76,36 @@ class SettingsPage extends ConsumerWidget {
),
borderRadius: kBorderRadius8,
),
child: DropdownButtonHideUnderline(
child: DropdownButton<String>(
borderRadius: kBorderRadius8,
onChanged: (value) {
ref
.read(settingsProvider.notifier)
.update(defaultUriScheme: value);
},
value: settings.defaultUriScheme,
items: kSupportedUriSchemes
.map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,
child: Padding(
padding: kP10,
child: Text(value),
),
);
}).toList(),
),
child: URIPopupMenu(
value: settings.defaultUriScheme,
onChanged: (value) {
ref
.read(settingsProvider.notifier)
.update(defaultUriScheme: value);
},
items: kSupportedUriSchemes,
),
// DropdownButtonHideUnderline(
// child: DropdownButton<String>(
// borderRadius: kBorderRadius8,
// onChanged: (value) {
// ref
// .read(settingsProvider.notifier)
// .update(defaultUriScheme: value);
// },
// value: settings.defaultUriScheme,
// items: kSupportedUriSchemes
// .map<DropdownMenuItem<String>>((String value) {
// return DropdownMenuItem<String>(
// value: value,
// child: Padding(
// padding: kP10,
// child: Text(value),
// ),
// );
// }).toList(),
// ),
// ),
),
),
ListTile(
@ -110,26 +119,35 @@ class SettingsPage extends ConsumerWidget {
),
borderRadius: kBorderRadius8,
),
child: DropdownButtonHideUnderline(
child: DropdownButton<CodegenLanguage>(
borderRadius: kBorderRadius8,
value: settings.defaultCodeGenLang,
onChanged: (value) {
ref
.read(settingsProvider.notifier)
.update(defaultCodeGenLang: value);
},
items: CodegenLanguage.values.map((value) {
return DropdownMenuItem<CodegenLanguage>(
value: value,
child: Padding(
padding: kP10,
child: Text(value.label),
),
);
}).toList(),
),
child: CodegenPopupMenu(
value: settings.defaultCodeGenLang,
onChanged: (value) {
ref
.read(settingsProvider.notifier)
.update(defaultCodeGenLang: value);
},
items: CodegenLanguage.values,
),
// DropdownButtonHideUnderline(
// child: DropdownButton<CodegenLanguage>(
// borderRadius: kBorderRadius8,
// value: settings.defaultCodeGenLang,
// onChanged: (value) {
// ref
// .read(settingsProvider.notifier)
// .update(defaultCodeGenLang: value);
// },
// items: CodegenLanguage.values.map((value) {
// return DropdownMenuItem<CodegenLanguage>(
// value: value,
// child: Padding(
// padding: kP10,
// child: Text(value.label),
// ),
// );
// }).toList(),
// ),
// ),
),
),
CheckboxListTile(

View File

@ -9,9 +9,11 @@ class RequestDetailsCard extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Card(
color: kColorTransparent,
surfaceTintColor: kColorTransparent,
shape: RoundedRectangleBorder(
side: BorderSide(
color: Theme.of(context).colorScheme.surfaceVariant,
color: Theme.of(context).colorScheme.surfaceContainerHighest,
),
borderRadius: kBorderRadius12,
),

View File

@ -42,7 +42,8 @@ class SidebarEnvironmentCard extends StatelessWidget {
final colorScheme = Theme.of(context).colorScheme;
final Color color =
isGlobal ? colorScheme.secondaryContainer : colorScheme.surface;
final Color colorVariant = colorScheme.surfaceVariant.withOpacity(0.5);
final Color colorVariant =
colorScheme.surfaceContainerHighest.withOpacity(0.5);
final Color surfaceTint = colorScheme.primary;
bool isSelected = selectedId == id;
bool inEditMode = editRequestId == id;

View File

@ -42,7 +42,7 @@ class SidebarRequestCard extends StatelessWidget {
Widget build(BuildContext context) {
final Color color = Theme.of(context).colorScheme.surface;
final Color colorVariant =
Theme.of(context).colorScheme.surfaceVariant.withOpacity(0.5);
Theme.of(context).colorScheme.surfaceContainerHighest.withOpacity(0.5);
final Color surfaceTint = Theme.of(context).colorScheme.primary;
bool isSelected = selectedId == id;
bool inEditMode = editRequestId == id;

View File

@ -22,16 +22,16 @@ class CheckBox extends StatelessWidget {
borderRadius: BorderRadius.circular(3),
),
side: BorderSide(
color: colorScheme.surfaceVariant,
color: colorScheme.surfaceContainerHighest,
width: 1.5,
),
splashRadius: 0,
value: value,
onChanged: onChanged,
checkColor: colorScheme.onPrimary,
fillColor: MaterialStateProperty.resolveWith<Color?>(
(Set<MaterialState> states) {
if (states.contains(MaterialState.selected)) {
fillColor: WidgetStateProperty.resolveWith<Color?>(
(Set<WidgetState> states) {
if (states.contains(WidgetState.selected)) {
return colorScheme.primary;
}
return null;

View File

@ -121,7 +121,8 @@ class ViewCodePane extends StatelessWidget {
: Theme.of(context).colorScheme.primaryContainer)
.withOpacity(kForegroundOpacity),
Theme.of(context).colorScheme.surface),
border: Border.all(color: Theme.of(context).colorScheme.surfaceVariant),
border: Border.all(
color: Theme.of(context).colorScheme.surfaceContainerHighest),
borderRadius: kBorderRadius8,
);

View File

@ -93,7 +93,7 @@ class _TextFieldEditorState extends State<TextFieldEditor> {
enabledBorder: OutlineInputBorder(
borderRadius: kBorderRadius8,
borderSide: BorderSide(
color: Theme.of(context).colorScheme.surfaceVariant,
color: Theme.of(context).colorScheme.surfaceContainerHighest,
),
),
filled: true,

View File

@ -110,7 +110,7 @@ class _JsonTextFieldEditorState extends State<JsonTextFieldEditor> {
enabledBorder: OutlineInputBorder(
borderRadius: kBorderRadius8,
borderSide: BorderSide(
color: Theme.of(context).colorScheme.surfaceVariant,
color: Theme.of(context).colorScheme.surfaceContainerHighest,
),
),
filled: true,

View File

@ -43,7 +43,7 @@ class CellField extends StatelessWidget {
),
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(
color: clrScheme.surfaceVariant,
color: clrScheme.surfaceContainerHighest,
),
),
),

View File

@ -57,7 +57,7 @@ class ObscurableCellField extends HookWidget {
),
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(
color: clrScheme.surfaceVariant,
color: clrScheme.surfaceContainerHighest,
),
),
),

View File

@ -93,7 +93,7 @@ class _HeaderFieldState extends State<HeaderField> {
),
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(
color: colorScheme.surfaceVariant,
color: colorScheme.surfaceContainerHighest,
),
),
),

View File

@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:apidash/consts.dart';
class RawTextField extends StatelessWidget {
const RawTextField({
@ -24,6 +25,7 @@ class RawTextField extends StatelessWidget {
isDense: true,
border: InputBorder.none,
hintText: hintText,
contentPadding: kPv8,
),
onTapOutside: (PointerDownEvent event) {
FocusManager.instance.primaryFocus?.unfocus();

View File

@ -246,9 +246,11 @@ class _JsonPreviewerState extends State<JsonPreviewer> {
),
Container(
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.background,
color: Theme.of(context).colorScheme.surface,
border: Border.all(
color: Theme.of(context).colorScheme.surfaceVariant),
color: Theme.of(context)
.colorScheme
.surfaceContainerHighest),
borderRadius: kBorderRadius8,
),
child: Row(

View File

@ -0,0 +1,53 @@
import 'package:apidash/consts.dart';
import 'package:apidash/extensions/extensions.dart';
import 'package:flutter/material.dart';
class CodegenPopupMenu extends StatelessWidget {
const CodegenPopupMenu({
super.key,
required this.value,
this.onChanged,
this.items,
});
final CodegenLanguage value;
final void Function(CodegenLanguage? value)? onChanged;
final List<CodegenLanguage>? items;
@override
Widget build(BuildContext context) {
final textClipLength = context.isCompactWindow ? 12 : 22;
final double boxLength = context.isCompactWindow ? 150 : 220;
return PopupMenuButton<CodegenLanguage>(
tooltip: "Select Code Generation Language",
surfaceTintColor: kColorTransparent,
constraints: BoxConstraints(minWidth: boxLength),
itemBuilder: (BuildContext context) => items!
.map((item) => PopupMenuItem<CodegenLanguage>(
value: item,
child: Text(
item.label,
style: kTextStylePopupMenuItem,
),
))
.toList(),
onSelected: onChanged,
child: Container(
width: boxLength,
padding: const EdgeInsets.all(8.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
value.label.clip(textClipLength),
style: kTextStylePopupMenuItem,
),
const Icon(
Icons.unfold_more,
size: 16,
)
],
),
),
);
}
}

View File

@ -0,0 +1,52 @@
import 'package:apidash/consts.dart';
import 'package:apidash/extensions/extensions.dart';
import 'package:flutter/material.dart';
class URIPopupMenu extends StatelessWidget {
const URIPopupMenu({
super.key,
required this.value,
this.onChanged,
this.items,
});
final String value;
final void Function(String? value)? onChanged;
final List<String>? items;
@override
Widget build(BuildContext context) {
final double boxLength = context.isCompactWindow ? 90 : 130;
return PopupMenuButton(
tooltip: "Select URI Scheme",
surfaceTintColor: kColorTransparent,
constraints: BoxConstraints(minWidth: boxLength),
itemBuilder: (BuildContext context) => items!
.map((item) => PopupMenuItem(
value: item,
child: Text(
item,
style: kTextStylePopupMenuItem,
),
))
.toList(),
onSelected: onChanged,
child: Container(
width: boxLength,
padding: const EdgeInsets.all(8.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
value,
style: kTextStylePopupMenuItem,
),
const Icon(
Icons.unfold_more,
size: 16,
)
],
),
),
);
}
}

View File

@ -405,7 +405,8 @@ class _BodySuccessState extends State<BodySuccess> {
: Theme.of(context).colorScheme.primaryContainer)
.withOpacity(kForegroundOpacity),
Theme.of(context).colorScheme.surface),
border: Border.all(color: Theme.of(context).colorScheme.surfaceVariant),
border: Border.all(
color: Theme.of(context).colorScheme.surfaceContainerHighest),
borderRadius: kBorderRadius8,
);
@ -425,7 +426,7 @@ class _BodySuccessState extends State<BodySuccess> {
? const SizedBox()
: SegmentedButton<ResponseBodyView>(
style: const ButtonStyle(
padding: MaterialStatePropertyAll(
padding: WidgetStatePropertyAll(
EdgeInsets.symmetric(
horizontal: 8,
),

View File

@ -35,7 +35,7 @@ class DashboardSplitViewState extends State<DashboardSplitView> {
data: MultiSplitViewThemeData(
dividerThickness: 3,
dividerPainter: DividerPainters.background(
color: Theme.of(context).colorScheme.surfaceVariant,
color: Theme.of(context).colorScheme.surfaceContainerHighest,
highlightedColor: Theme.of(context).colorScheme.outline.withOpacity(
kHintOpacity,
),

View File

@ -60,7 +60,7 @@ class DrawerSplitView extends StatelessWidget {
child: IconButton(
icon: Icon(
rightDrawerIcon ?? Icons.arrow_forward,
color: Theme.of(context).colorScheme.onBackground,
color: Theme.of(context).colorScheme.onSurface,
),
onPressed: () {
scaffoldKey.currentState!.openEndDrawer();

View File

@ -30,7 +30,7 @@ class _EqualSplitViewState extends State<EqualSplitView> {
data: MultiSplitViewThemeData(
dividerThickness: 3,
dividerPainter: DividerPainters.background(
color: Theme.of(context).colorScheme.surfaceVariant,
color: Theme.of(context).colorScheme.surfaceContainerHighest,
highlightedColor: Theme.of(context).colorScheme.outline.withOpacity(
kHintOpacity,
),

View File

@ -18,7 +18,7 @@ class MapTable extends StatelessWidget {
return Table(
border: TableBorder(
horizontalInside: BorderSide(
color: Theme.of(context).colorScheme.surfaceVariant,
color: Theme.of(context).colorScheme.surfaceContainerHighest,
),
),
columnWidths: const <int, TableColumnWidth>{

View File

@ -31,7 +31,9 @@ export 'json_previewer.dart';
export 'markdown.dart';
export 'menus.dart';
export 'overlay_widget.dart';
export 'popup_menus.dart';
export 'popup_menu_codegen.dart';
export 'popup_menu_env.dart';
export 'popup_menu_uri.dart';
export 'previewer.dart';
export 'request_widgets.dart';
export 'response_widgets.dart';

View File

@ -0,0 +1,33 @@
import 'dart:ui';
import 'package:flutter_test/flutter_test.dart';
class ScreenSize {
const ScreenSize(this.name, this.width, this.height, this.pixelDensity);
final String name;
final double width, height, pixelDensity;
}
const compactWidthDevice = ScreenSize('compact__width_device', 500, 600, 1);
const mediumWidthDevice = ScreenSize('medium__width_device', 800, 800, 1);
const largeWidthDevice = ScreenSize('large_width_device', 1300, 800, 1);
extension ScreenSizeManager on WidgetTester {
Future<void> setScreenSize(ScreenSize screenSize) async {
return _setScreenSize(
width: screenSize.width,
height: screenSize.height,
pixelDensity: screenSize.pixelDensity,
);
}
Future<void> _setScreenSize({
required double width,
required double height,
required double pixelDensity,
}) async {
final size = Size(width, height);
await binding.setSurfaceSize(size);
view.physicalSize = size;
view.devicePixelRatio = pixelDensity;
}
}

View File

@ -13,6 +13,7 @@ void main() {
defaultCodeGenLang: CodegenLanguage.curl,
saveResponses: true,
promptBeforeClosing: true,
activeEnvironmentId: null,
);
test('Testing toJson()', () {
@ -26,7 +27,8 @@ void main() {
"defaultUriScheme": "http",
"defaultCodeGenLang": "curl",
"saveResponses": true,
"promptBeforeClosing": true
"promptBeforeClosing": true,
'activeEnvironmentId': null
};
expect(sm.toJson(), expectedResult);
});
@ -42,7 +44,8 @@ void main() {
"defaultUriScheme": "http",
"defaultCodeGenLang": "curl",
"saveResponses": true,
"promptBeforeClosing": true
"promptBeforeClosing": true,
'activeEnvironmentId': null
};
expect(SettingsModel.fromJson(input), sm);
});
@ -57,6 +60,7 @@ void main() {
defaultCodeGenLang: CodegenLanguage.curl,
saveResponses: false,
promptBeforeClosing: true,
activeEnvironmentId: null,
);
expect(
sm.copyWith(
@ -68,7 +72,7 @@ void main() {
test('Testing toString()', () {
const expectedResult =
"{isDark: false, alwaysShowCollectionPaneScrollbar: true, width: 300.0, height: 200.0, dx: 100.0, dy: 150.0, defaultUriScheme: http, defaultCodeGenLang: curl, saveResponses: true, promptBeforeClosing: true}";
"{isDark: false, alwaysShowCollectionPaneScrollbar: true, width: 300.0, height: 200.0, dx: 100.0, dy: 150.0, defaultUriScheme: http, defaultCodeGenLang: curl, saveResponses: true, promptBeforeClosing: true, activeEnvironmentId: null}";
expect(sm.toString(), expectedResult);
});

View File

@ -1,7 +1,9 @@
import 'dart:io';
import 'package:apidash/providers/providers.dart';
import 'package:apidash/screens/common_widgets/common_widgets.dart';
import 'package:apidash/screens/dashboard.dart';
import 'package:apidash/screens/envvar/environment_page.dart';
import 'package:apidash/screens/home_page/collection_pane.dart';
import 'package:apidash/screens/home_page/editor_pane/details_card/code_pane.dart';
import 'package:apidash/screens/home_page/editor_pane/details_card/response_pane.dart';
@ -15,9 +17,12 @@ import 'package:apidash/services/hive_services.dart';
import 'package:apidash/widgets/widgets.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_portal/flutter_portal.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mention_tag_text_field/mention_tag_text_field.dart';
import '../extensions/widget_tester_extensions.dart';
import '../test_consts.dart';
void main() {
@ -52,12 +57,13 @@ void main() {
// Verify that the HomePage is displayed initially
expect(find.byType(HomePage), findsOneWidget);
expect(find.byType(EnvironmentPage), findsNothing);
expect(find.byType(IntroPage), findsNothing);
expect(find.byType(SettingsPage), findsNothing);
});
testWidgets(
"Dashboard should display IntroPage when navRailIndexStateProvider is 1",
"Dashboard should display EnvironmentPage when navRailIndexStateProvider is 1",
(WidgetTester tester) async {
await tester.pumpWidget(
ProviderScope(
@ -70,30 +76,57 @@ void main() {
),
);
// Verify that the IntroPage is displayed
expect(find.byType(IntroPage), findsOneWidget);
// Verify that the EnvironmentPage is displayed
expect(find.byType(HomePage), findsNothing);
expect(find.byType(EnvironmentPage), findsOneWidget);
expect(find.byType(IntroPage), findsNothing);
expect(find.byType(SettingsPage), findsNothing);
});
testWidgets(
"Dashboard should display SettingsPage when navRailIndexStateProvider is 2",
"Dashboard should display IntroPage when navRailIndexStateProvider is 2",
(WidgetTester tester) async {
await tester.pumpWidget(
ProviderScope(
overrides: [
navRailIndexStateProvider.overrideWith((ref) => 2),
],
child: const MaterialApp(
home: Dashboard(),
child: const Portal(
child: MaterialApp(
home: Dashboard(),
),
),
),
);
// Verify that the IntroPage is displayed
expect(find.byType(HomePage), findsNothing);
expect(find.byType(EnvironmentPage), findsNothing);
expect(find.byType(IntroPage), findsOneWidget);
expect(find.byType(SettingsPage), findsNothing);
});
testWidgets(
"Dashboard should display SettingsPage when navRailIndexStateProvider is 3",
(WidgetTester tester) async {
await tester.pumpWidget(
ProviderScope(
overrides: [
navRailIndexStateProvider.overrideWith((ref) => 3),
],
child: const Portal(
child: MaterialApp(
home: Dashboard(),
),
),
),
);
// Verify that the SettingsPage is displayed
expect(find.byType(SettingsPage), findsOneWidget);
expect(find.byType(IntroPage), findsNothing);
expect(find.byType(HomePage), findsNothing);
expect(find.byType(EnvironmentPage), findsNothing);
expect(find.byType(IntroPage), findsNothing);
expect(find.byType(SettingsPage), findsOneWidget);
});
testWidgets(
@ -101,8 +134,10 @@ void main() {
(tester) async {
await tester.pumpWidget(
const ProviderScope(
child: MaterialApp(
home: Dashboard(),
child: Portal(
child: MaterialApp(
home: Dashboard(),
),
),
),
);
@ -114,7 +149,7 @@ void main() {
// Verify that the navRailIndexStateProvider is updated
final dashboard = tester.element(find.byType(Dashboard));
final container = ProviderScope.containerOf(dashboard);
expect(container.read(navRailIndexStateProvider), 1);
expect(container.read(navRailIndexStateProvider), 2);
});
testWidgets(
@ -123,21 +158,25 @@ void main() {
// Pump the initial widget tree
await tester.pumpWidget(
const ProviderScope(
child: MaterialApp(
home: Dashboard(),
child: Portal(
child: MaterialApp(
home: Dashboard(),
),
),
),
);
// Tap on the Settings icon to change the index to 2
// Tap on the Settings icon to change the index to 3
await tester.tap(find.byIcon(Icons.settings_outlined));
await tester.pump();
// Rebuild the widget tree with the same ProviderScope
await tester.pumpWidget(
const ProviderScope(
child: MaterialApp(
home: Dashboard(),
child: Portal(
child: MaterialApp(
home: Dashboard(),
),
),
),
);
@ -145,12 +184,13 @@ void main() {
// Verify that the navRailIndexStateProvider still has the updated value
final dashboard = tester.element(find.byType(Dashboard));
final container = ProviderScope.containerOf(dashboard);
expect(container.read(navRailIndexStateProvider), 2);
expect(container.read(navRailIndexStateProvider), 3);
// Verify that the SettingsPage is still displayed after the rebuild
expect(find.byType(SettingsPage), findsOneWidget);
expect(find.byType(IntroPage), findsNothing);
expect(find.byType(HomePage), findsNothing);
expect(find.byType(EnvironmentPage), findsNothing);
});
testWidgets(
@ -158,8 +198,10 @@ void main() {
(tester) async {
await tester.pumpWidget(
const ProviderScope(
child: MaterialApp(
home: Dashboard(),
child: Portal(
child: MaterialApp(
home: Dashboard(),
),
),
),
);
@ -168,17 +210,26 @@ void main() {
final dashboard = tester.element(find.byType(Dashboard));
final container = ProviderScope.containerOf(dashboard);
// Go to IntroPage
// Go to EnvironmentPage
container.read(navRailIndexStateProvider.notifier).state = 1;
await tester.pump();
// Verify that the EnvironmentPage is displayed
expect(find.byType(EnvironmentPage), findsOneWidget);
// Verify that the selected icon is the filled version (selectedIcon)
expect(find.byIcon(Icons.computer_rounded), findsOneWidget);
// Go to IntroPage
container.read(navRailIndexStateProvider.notifier).state = 2;
await tester.pump();
// Verify that the IntroPage is displayed
expect(find.byType(IntroPage), findsOneWidget);
// Verify that the selected icon is the filled version (selectedIcon)
expect(find.byIcon(Icons.help), findsOneWidget);
// Go to SettingsPage
container.read(navRailIndexStateProvider.notifier).state = 2;
container.read(navRailIndexStateProvider.notifier).state = 3;
await tester.pump();
// Verify that the SettingsPage is displayed
@ -192,8 +243,10 @@ void main() {
(tester) async {
await tester.pumpWidget(
const ProviderScope(
child: MaterialApp(
home: Dashboard(),
child: Portal(
child: MaterialApp(
home: Dashboard(),
),
),
),
);
@ -364,53 +417,14 @@ void main() {
testWidgets("When state is false ResponsePane should be visible",
(tester) async {
await tester.setScreenSize(largeWidthDevice);
await tester.pumpWidget(
const ProviderScope(
child: MaterialApp(
home: RequestEditorPane(),
),
),
);
expect(find.byType(RequestEditorDefault), findsOneWidget);
// Tap on the "Plus New" button
Finder plusNewButton = find.descendant(
of: find.byType(RequestEditorDefault),
matching: find.byType(ElevatedButton),
);
await tester.tap(plusNewButton);
await tester.pump();
// Verify that NotSentWidget is visible
expect(find.byType(NotSentWidget), findsOneWidget);
// Add some data in URLTextField
Finder field = find.descendant(
of: find.byType(URLField),
matching: find.byType(TextFormField),
);
await tester.enterText(field, kTestUrl);
await tester.pump();
// Tap on the "Send" button
Finder sendButton = find.byType(SendRequestButton);
await tester.tap(sendButton);
await tester.pump();
final editorPane = tester.element(find.byType(RequestEditorPane));
final container = ProviderScope.containerOf(editorPane);
expect(container.read(codePaneVisibleStateProvider), false);
expect(find.byType(ResponsePane), findsOneWidget);
});
testWidgets("When state is true CodePane should be visible",
(tester) async {
await tester.pumpWidget(
const ProviderScope(
child: MaterialApp(
home: Scaffold(
body: RequestEditorPane(),
child: Portal(
child: MaterialApp(
home: Material(
child: RequestEditorPane(),
),
),
),
),
@ -431,8 +445,55 @@ void main() {
// Add some data in URLTextField
Finder field = find.descendant(
of: find.byType(URLField),
matching: find.byType(TextFormField),
of: find.byType(EnvURLField),
matching: find.byType(MentionTagTextField),
);
await tester.enterText(field, kTestUrl);
await tester.pump();
// Tap on the "Send" button
Finder sendButton = find.byType(SendRequestButton);
await tester.tap(sendButton);
await tester.pump();
final editorPane = tester.element(find.byType(RequestEditorPane));
final container = ProviderScope.containerOf(editorPane);
expect(container.read(codePaneVisibleStateProvider), false);
expect(find.byType(ResponsePane), findsOneWidget);
});
testWidgets("When state is true CodePane should be visible",
(tester) async {
await tester.setScreenSize(largeWidthDevice);
await tester.pumpWidget(
const ProviderScope(
child: Portal(
child: MaterialApp(
home: Scaffold(
body: RequestEditorPane(),
),
),
),
),
);
expect(find.byType(RequestEditorDefault), findsOneWidget);
// Tap on the "Plus New" button
Finder plusNewButton = find.descendant(
of: find.byType(RequestEditorDefault),
matching: find.byType(ElevatedButton),
);
await tester.tap(plusNewButton);
await tester.pump();
// Verify that NotSentWidget is visible
expect(find.byType(NotSentWidget), findsOneWidget);
// Add some data in URLTextField
Finder field = find.descendant(
of: find.byType(EnvURLField),
matching: find.byType(MentionTagTextField),
);
await tester.enterText(field, kTestUrl);
await tester.pump();
@ -454,11 +515,14 @@ void main() {
});
testWidgets("Hide/View Code button toggles the state", (tester) async {
await tester.setScreenSize(largeWidthDevice);
await tester.pumpWidget(
const ProviderScope(
child: MaterialApp(
home: Scaffold(
body: RequestEditorPane(),
child: Portal(
child: MaterialApp(
home: Scaffold(
body: RequestEditorPane(),
),
),
),
),
@ -479,8 +543,8 @@ void main() {
// Add some data in URLTextField
Finder field = find.descendant(
of: find.byType(URLField),
matching: find.byType(TextFormField),
of: find.byType(EnvURLField),
matching: find.byType(MentionTagTextField),
);
await tester.enterText(field, kTestUrl);
await tester.pump();
@ -511,11 +575,14 @@ void main() {
});
testWidgets("That state persists across widget rebuilds", (tester) async {
await tester.setScreenSize(largeWidthDevice);
await tester.pumpWidget(
const ProviderScope(
child: MaterialApp(
home: Scaffold(
body: RequestEditorPane(),
child: Portal(
child: MaterialApp(
home: Scaffold(
body: RequestEditorPane(),
),
),
),
),
@ -536,8 +603,8 @@ void main() {
// Add some data in URLTextField
Finder field = find.descendant(
of: find.byType(URLField),
matching: find.byType(TextFormField),
of: find.byType(EnvURLField),
matching: find.byType(MentionTagTextField),
);
await tester.enterText(field, kTestUrl);
await tester.pump();
@ -562,9 +629,11 @@ void main() {
// Rebuild the widget tree
await tester.pumpWidget(
const ProviderScope(
child: MaterialApp(
home: Scaffold(
body: RequestEditorPane(),
child: Portal(
child: MaterialApp(
home: Scaffold(
body: RequestEditorPane(),
),
),
),
),

View File

@ -2,6 +2,7 @@ import 'dart:typed_data';
import 'package:apidash/screens/common_widgets/sidebar_save_button.dart';
import 'package:apidash/widgets/widgets.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:apidash/consts.dart';
import '../test_consts.dart';
@ -175,11 +176,13 @@ void main() {
testWidgets('Testing for Save button', (tester) async {
await tester.pumpWidget(
MaterialApp(
title: 'Save button',
theme: kThemeDataLight,
home: const Scaffold(
body: SaveButton(),
ProviderScope(
child: MaterialApp(
title: 'Save button',
theme: kThemeDataLight,
home: const Scaffold(
body: SaveButton(),
),
),
),
);

View File

@ -1,10 +1,12 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:apidash/widgets/request_widgets.dart';
import '../extensions/widget_tester_extensions.dart';
import '../test_consts.dart';
void main() {
testWidgets('Testing Request Pane for 1st tab', (tester) async {
await tester.setScreenSize(largeWidthDevice);
await tester.pumpWidget(
MaterialApp(
title: 'Request Pane',
@ -34,6 +36,7 @@ void main() {
expect(find.byIcon(Icons.code_rounded), findsNothing);
});
testWidgets('Testing Request Pane for 2nd tab', (tester) async {
await tester.setScreenSize(largeWidthDevice);
await tester.pumpWidget(
MaterialApp(
title: 'Request Pane',
@ -64,6 +67,7 @@ void main() {
expect(find.byIcon(Icons.code_rounded), findsNothing);
});
testWidgets('Testing Request Pane for 3rd tab', (tester) async {
await tester.setScreenSize(largeWidthDevice);
await tester.pumpWidget(
MaterialApp(
title: 'Request Pane',