Skip to content

Commit

Permalink
Add very_good_analysis and update dialogTheme
Browse files Browse the repository at this point in the history
  • Loading branch information
prateekmedia committed Jan 31, 2022
1 parent aa2395c commit 3241353
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 107 deletions.
24 changes: 7 additions & 17 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,20 +1,10 @@
include: package:flutter_lints/flutter.yaml

# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options
include: package:very_good_analysis/analysis_options.yaml

linter:
# The lint rules applied to this project can be customized in the
# section below to disable rules from the `package:flutter_lints/flutter.yaml`
# included above or to enable additional rules. A list of all available lints
# and their documentation is published at
# https://dart-lang.github.io/linter/lints/index.html.
#
# Instead of disabling a lint rule for the entire project in the
# section below, it can also be suppressed for a single line of code
# or a specific dart file by using the `// ignore: name_of_lint` and
# `// ignore_for_file: name_of_lint` syntax on the line or in the file
# producing the lint.
rules:
# avoid_print: false # Uncomment to disable the `avoid_print` rule
# prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule
public_member_api_docs: false
library_private_types_in_public_api: false
avoid_setters_without_getters: false

# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options
55 changes: 28 additions & 27 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,33 +1,35 @@
import 'package:flutter/material.dart';
import 'package:adwaita/adwaita.dart';
import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
final ValueNotifier<ThemeMode> themeNotifier = ValueNotifier(ThemeMode.light);

MyApp({Key? key}) : super(key: key);

final ValueNotifier<ThemeMode> themeNotifier = ValueNotifier(ThemeMode.light);

@override
Widget build(BuildContext context) {
return ValueListenableBuilder<ThemeMode>(
valueListenable: themeNotifier,
builder: (_, ThemeMode currentMode, __) {
return MaterialApp(
theme: AdwaitaThemeData.light(),
darkTheme: AdwaitaThemeData.dark(),
debugShowCheckedModeBanner: false,
home: MyHomePage(themeNotifier: themeNotifier),
themeMode: currentMode);
});
valueListenable: themeNotifier,
builder: (_, ThemeMode currentMode, __) {
return MaterialApp(
theme: AdwaitaThemeData.light(),
darkTheme: AdwaitaThemeData.dark(),
debugShowCheckedModeBanner: false,
home: MyHomePage(themeNotifier: themeNotifier),
themeMode: currentMode,
);
},
);
}
}

class MyHomePage extends StatefulWidget {
final ValueNotifier<ThemeMode> themeNotifier;

const MyHomePage({Key? key, required this.themeNotifier}) : super(key: key);

final ValueNotifier<ThemeMode> themeNotifier;

@override
State<MyHomePage> createState() => _MyHomePageState();
}
Expand All @@ -43,19 +45,18 @@ class _MyHomePageState extends State<MyHomePage> {
Column(
children: [
SwitchListTile(
title: Text(
"Dark mode",
style: Theme.of(context).textTheme.bodyText1,
),
value: widget.themeNotifier.value == ThemeMode.light
? false
: true,
onChanged: (value) {
widget.themeNotifier.value =
widget.themeNotifier.value == ThemeMode.light
? ThemeMode.dark
: ThemeMode.light;
}),
title: Text(
'Dark mode',
style: Theme.of(context).textTheme.bodyText1,
),
value: widget.themeNotifier.value != ThemeMode.light,
onChanged: (value) {
widget.themeNotifier.value =
widget.themeNotifier.value == ThemeMode.light
? ThemeMode.dark
: ThemeMode.light;
},
),
Card(
child: Column(
mainAxisSize: MainAxisSize.min,
Expand Down
28 changes: 14 additions & 14 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -62,32 +62,25 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
flutter_lints:
dependency: "direct dev"
description:
name: flutter_lints
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.4"
flutter_test:
dependency: "direct dev"
description: flutter
source: sdk
version: "0.0.0"
lints:
matcher:
dependency: transitive
description:
name: lints
name: matcher
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.1"
matcher:
version: "0.12.11"
material_color_utilities:
dependency: transitive
description:
name: matcher
name: material_color_utilities
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.11"
version: "0.1.3"
meta:
dependency: transitive
description:
Expand Down Expand Up @@ -148,7 +141,7 @@ packages:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.4.3"
version: "0.4.8"
typed_data:
dependency: transitive
description:
Expand All @@ -163,6 +156,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.1"
very_good_analysis:
dependency: "direct dev"
description:
name: very_good_analysis
url: "https://pub.dartlang.org"
source: hosted
version: "2.4.0"
sdks:
dart: ">=2.14.0 <3.0.0"
flutter: ">=1.17.0"
6 changes: 3 additions & 3 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ environment:
sdk: ">=2.12.0 <3.0.0"

dependencies:
flutter:
sdk: flutter
adwaita:
path: ../
flutter:
sdk: flutter

dev_dependencies:
flutter_test:
sdk: flutter
flutter_lints: ^1.0.0
very_good_analysis: ^2.4.0

flutter:
uses-material-design: true
59 changes: 19 additions & 40 deletions lib/src/theme.dart
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
import 'package:adwaita/src/utils/colors.dart';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart' show SystemUiOverlayStyle;
import 'package:adwaita/src/utils/colors.dart';

/// Generate Adwaita light and dark theme.
class AdwaitaThemeData {
const AdwaitaThemeData._();

static final _lightColorScheme = ColorScheme.fromSwatch(
// NOTE(robert-ancell): Light shades from 'Tint' on website, dark shades calculated.
// NOTE(robert-ancell): Light shades from 'Tint' on website, dark shades
// calculated.
primarySwatch: AdwaitaColors.primarySwatchColor,
primaryColorDark: AdwaitaColors.darkBackgroundColor,
accentColor: AdwaitaColors.blueAccent,
cardColor: AdwaitaColors.cardBackground,
backgroundColor: AdwaitaColors.backgroundColor,
errorColor: AdwaitaColors.red5,
brightness: Brightness.light,
);

static final _darkColorScheme = ColorScheme.fromSwatch(
// NOTE(robert-ancell): Light shades from 'Tint' on website, dark shades calculated.
// NOTE(robert-ancell): Light shades from 'Tint' on website, dark shades
// calculated.
primarySwatch: AdwaitaColors.primarySwatchColor,
primaryColorDark: AdwaitaColors.darkBackgroundColor,
accentColor: AdwaitaColors.blueAccent,
Expand All @@ -33,15 +35,14 @@ class AdwaitaThemeData {
tabBarTheme: TabBarTheme(labelColor: _lightColorScheme.onSurface),
brightness: Brightness.light,
primaryColor: _lightColorScheme.primary,
primaryColorBrightness:
ThemeData.estimateBrightnessForColor(_lightColorScheme.primary),
canvasColor: _lightColorScheme.background,
scaffoldBackgroundColor: _lightColorScheme.background,
bottomAppBarColor: _lightColorScheme.surface,
cardColor: _lightColorScheme.surface,
dividerColor: _lightColorScheme.onSurface.withOpacity(0.12),
backgroundColor: _lightColorScheme.background,
dialogBackgroundColor: _lightColorScheme.background,
dialogTheme: DialogTheme(backgroundColor: _lightColorScheme.background),
errorColor: _lightColorScheme.error,
indicatorColor: _lightColorScheme.secondary,
applyElevationOverlayColor: false,
Expand All @@ -65,22 +66,14 @@ class AdwaitaThemeData {
filled: true,
fillColor: AdwaitaColors.button,
enabledBorder: const OutlineInputBorder(
borderRadius: BorderRadius.all(
Radius.circular(8.0),
),
borderSide: BorderSide(
width: 1.0,
style: BorderStyle.solid,
color: Colors.transparent,
),
borderRadius: BorderRadius.all(Radius.circular(8)),
borderSide: BorderSide(color: Colors.transparent),
),
focusedBorder: const OutlineInputBorder(
borderRadius: BorderRadius.all(
Radius.circular(8.0),
Radius.circular(8),
),
borderSide: BorderSide(
width: 1.0,
style: BorderStyle.solid,
color: AdwaitaColors.blueAccent,
),
),
Expand All @@ -91,18 +84,14 @@ class AdwaitaThemeData {
static ThemeData dark() => ThemeData(
tabBarTheme: TabBarTheme(labelColor: _darkColorScheme.onBackground),
dialogTheme: DialogTheme(
backgroundColor: AdwaitaColors.dark3,
backgroundColor: _darkColorScheme.background,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(6),
side: BorderSide(
color: Colors.white.withOpacity(0.2),
),
side: BorderSide(color: Colors.white.withOpacity(0.2)),
),
),
brightness: Brightness.dark,
primaryColor: _darkColorScheme.primary,
primaryColorBrightness:
ThemeData.estimateBrightnessForColor(_darkColorScheme.primary),
canvasColor: _darkColorScheme.background,
scaffoldBackgroundColor: _darkColorScheme.background,
bottomAppBarColor: _darkColorScheme.surface,
Expand Down Expand Up @@ -135,24 +124,14 @@ class AdwaitaThemeData {
filled: true,
fillColor: AdwaitaColors.darkButton,
enabledBorder: const OutlineInputBorder(
borderRadius: BorderRadius.all(
Radius.circular(8.0),
),
borderSide: BorderSide(
width: 1.0,
style: BorderStyle.solid,
color: Colors.transparent,
),
borderRadius: BorderRadius.all(Radius.circular(8)),
borderSide: BorderSide(color: Colors.transparent),
),
focusedBorder: const OutlineInputBorder(
borderRadius: BorderRadius.all(
Radius.circular(8.0),
),
borderSide: BorderSide(
width: 1.0,
style: BorderStyle.solid,
color: AdwaitaColors.blueAccent,
Radius.circular(8),
),
borderSide: BorderSide(color: AdwaitaColors.blueAccent),
),
),
);
Expand Down Expand Up @@ -182,7 +161,7 @@ class AdwaitaThemeData {

static final _buttonThemeData = ButtonThemeData(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(4.0),
borderRadius: BorderRadius.circular(4),
),
);

Expand Down Expand Up @@ -360,7 +339,7 @@ class AdwaitaThemeData {
);

static const _appBarLightTheme = AppBarTheme(
elevation: 1.0,
elevation: 1,
systemOverlayStyle: SystemUiOverlayStyle.light,
backgroundColor: AdwaitaColors.headerBarBackground,
foregroundColor: AdwaitaColors.headerBarForeground,
Expand All @@ -369,7 +348,7 @@ class AdwaitaThemeData {
);

static const _appBarDarkTheme = AppBarTheme(
elevation: 1.0,
elevation: 1,
systemOverlayStyle: SystemUiOverlayStyle.dark,
backgroundColor: AdwaitaColors.darkHeaderBarBackground,
foregroundColor: AdwaitaColors.darkHeaderBarForeground,
Expand Down
10 changes: 5 additions & 5 deletions lib/src/utils/colors.dart
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,15 @@ class AdwaitaColors {
static Color darkBorder = dark5.withOpacity(0.75);

static MaterialColor _createMaterialColor(Color color) {
List strengths = <double>[.05];
final strengths = <double>[.05];
final swatch = <int, Color>{};
final int r = color.red, g = color.green, b = color.blue;
final r = color.red, g = color.green, b = color.blue;

for (int i = 1; i < 10; i++) {
for (var i = 1; i < 10; i++) {
strengths.add(0.1 * i);
}
for (var strength in strengths) {
final double ds = 0.5 - strength;
for (final strength in strengths) {
final ds = 0.5 - strength;
swatch[(strength * 1000).round()] = Color.fromRGBO(
r + ((ds < 0 ? r : (255 - r)) * ds).round(),
g + ((ds < 0 ? g : (255 - g)) * ds).round(),
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ dependencies:
dev_dependencies:
flutter_test:
sdk: flutter
flutter_lints: ^1.0.0
very_good_analysis: ^2.4.0

flutter:

0 comments on commit 3241353

Please sign in to comment.