Skip to content

Commit

Permalink
Merge pull request #69 from mono0926/67-support-for-macos-style-alert…
Browse files Browse the repository at this point in the history
…-dialog

67 support for macos style alert dialog
  • Loading branch information
mono0926 authored Apr 28, 2022
2 parents 6dfc99a + 44c6ecb commit 906e9e1
Show file tree
Hide file tree
Showing 30 changed files with 1,803 additions and 125 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 1.6.0

- Support for macOS dialogs
- Add `AdaptiveDialog.instance.updateConfiguration`, a method used for changing default configuration

## 1.5.1

- Add `autocorrect` to `DialogTextField` (#63)
Expand Down
Binary file added example/assets/images/love.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 2 additions & 6 deletions example/lib/app.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'package:example/pages/home_page.dart';
import 'package:flutter/material.dart' hide Router;
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
Expand All @@ -13,13 +12,10 @@ class App extends ConsumerWidget {
@override
Widget build(BuildContext context, WidgetRef ref) {
final router = ref.watch(routerProvider);
final platform = ref.watch(
adaptiveStyleNotifier.select((s) => s.platform),
);
return MaterialApp.router(
title: title,
theme: lightTheme().copyWith(platform: platform),
darkTheme: darkTheme().copyWith(platform: platform),
theme: lightTheme(),
darkTheme: darkTheme(),
routeInformationParser: router.routeInformationParser,
routerDelegate: router.routerDelegate,
localizationsDelegates: const [
Expand Down
9 changes: 9 additions & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:adaptive_dialog/adaptive_dialog.dart';
import 'package:flutter/material.dart' hide Router;
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:go_router/go_router.dart';
Expand All @@ -7,6 +8,14 @@ import 'app.dart';
void main() {
WidgetsFlutterBinding.ensureInitialized();
GoRouter.setUrlPathStrategy(UrlPathStrategy.path);
AdaptiveDialog.instance.updateConfiguration(
macOS: AdaptiveDialogMacOSConfiguration(
applicationIcon: ClipRRect(
borderRadius: BorderRadius.circular(16),
child: Image.asset('assets/images/love.png'),
),
),
);
runApp(
const ProviderScope(
child: App(),
Expand Down
2 changes: 1 addition & 1 deletion example/lib/pages/alert_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ class AlertPage extends StatelessWidget {
message: 'This is message.',
isDestructiveAction: true,
cancelLabel: 'No!',
useActionSheetForCupertino: true,
useActionSheetForIOS: true,
);
logger.info(result);
},
Expand Down
31 changes: 14 additions & 17 deletions example/lib/pages/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import 'package:example/router/router.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:go_router/go_router.dart';
import 'package:recase/recase.dart';
import 'package:url_launcher/url_launcher.dart';

class HomePage extends StatelessWidget {
Expand Down Expand Up @@ -62,36 +61,34 @@ class _StyleDropdownButton extends ConsumerWidget {
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 4),
child: DropdownButton<AdaptiveStyle>(
value: ref.watch(adaptiveStyleNotifier),
value: ref.watch(adaptiveStyleProvider),
items: AdaptiveStyle.values
// ignore: deprecated_member_use
.where((style) => style != AdaptiveStyle.cupertino)
.map(
(style) => DropdownMenuItem(
value: style,
child: Text(
style.name.pascalCase,
),
child: Text(style.label),
),
)
.toList(),
onChanged: (style) =>
ref.read(adaptiveStyleNotifier.notifier).update((_) => style!),
ref.read(adaptiveStyleProvider.notifier).update(style!),
),
),
);
}
}

final adaptiveStyleNotifier = StateProvider((ref) => AdaptiveStyle.adaptive);
final adaptiveStyleProvider =
StateNotifierProvider<AdaptiveStyleNotifier, AdaptiveStyle>(
(ref) => AdaptiveStyleNotifier(),
);

extension AdaptiveStyleX on AdaptiveStyle {
TargetPlatform? get platform {
switch (this) {
case AdaptiveStyle.material:
return TargetPlatform.android;
case AdaptiveStyle.cupertino:
return TargetPlatform.iOS;
case AdaptiveStyle.adaptive:
return null;
}
class AdaptiveStyleNotifier extends StateNotifier<AdaptiveStyle> {
AdaptiveStyleNotifier() : super(AdaptiveStyle.adaptive);
void update(AdaptiveStyle style) {
AdaptiveDialog.instance.updateConfiguration(defaultStyle: style);
state = style;
}
}
15 changes: 10 additions & 5 deletions example/lib/pages/text_input_dialog_page.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import 'package:adaptive_dialog/adaptive_dialog.dart';
import 'package:example/pages/home_page.dart';
import 'package:example/router/router.dart';
import 'package:example/util/util.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:go_router/go_router.dart';

class TextInputDialogRoute extends GoRouteData {
Expand All @@ -10,11 +12,11 @@ class TextInputDialogRoute extends GoRouteData {
Widget build(BuildContext context) => const TextInputDialogPage();
}

class TextInputDialogPage extends StatelessWidget {
class TextInputDialogPage extends ConsumerWidget {
const TextInputDialogPage({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
Widget build(BuildContext context, WidgetRef ref) {
final theme = Theme.of(context);
return Scaffold(
appBar: AppBar(
Expand Down Expand Up @@ -163,9 +165,12 @@ class TextInputDialogPage extends StatelessWidget {
hintText: 'Start with "F"',
retryTitle: 'Incorrect',
retryMessage: 'Retry?',
retryOkLabel: AdaptiveStyle.adaptive.isCupertinoStyle(theme)
? 'Retry'
: 'RETRY',
retryOkLabel: ref
.watch(adaptiveStyleProvider)
.effectiveStyle(theme)
.isMaterial(theme)
? 'RETRY'
: 'Retry',
);
logger.info('ok: $ok');
if (!ok) {
Expand Down
1 change: 1 addition & 0 deletions example/macos/Flutter/ephemeral/.app_filename
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
example.app
14 changes: 14 additions & 0 deletions example/macos/Flutter/ephemeral/Flutter-Generated.xcconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// This is a generated file; do not edit or check into version control.
FLUTTER_ROOT=/Users/mono/fvm/versions/stable
FLUTTER_APPLICATION_PATH=/Users/mono/Git/adaptive_dialog/example
COCOAPODS_PARALLEL_CODE_SIGN=true
FLUTTER_TARGET=/Users/mono/Git/adaptive_dialog/example/lib/main.dart
FLUTTER_BUILD_DIR=build
FLUTTER_BUILD_NAME=1.0.0
FLUTTER_BUILD_NUMBER=1
EXCLUDED_ARCHS=arm64
DART_DEFINES=RkxVVFRFUl9XRUJfQVVUT19ERVRFQ1Q9dHJ1ZQ==
DART_OBFUSCATION=false
TRACK_WIDGET_CREATION=true
TREE_SHAKE_ICONS=false
PACKAGE_CONFIG=/Users/mono/Git/adaptive_dialog/example/.dart_tool/package_config.json
Loading

0 comments on commit 906e9e1

Please sign in to comment.