Browse Source

[flutter_example_packages] Add flutter_local_notifications, refactoring text

merge-requests/21/head
Vitaliy Zarubin 2 years ago
parent
commit
24e5607d4a
  1. 5
      example/lib/l10n/app_en.arb
  2. 5
      example/lib/l10n/app_ru.arb
  3. 32
      example/lib/packages/flutter_local_notifications/model.dart
  4. 39
      example/lib/packages/flutter_local_notifications/page.dart
  5. 4
      example/lib/pages/home/page.dart
  6. 5
      example/lib/pages/home/widgets/home_app_bar.dart
  7. 2
      example/lib/pages/home/widgets/package_list_item.dart
  8. 62
      example/lib/theme/theme.dart
  9. 2
      example/lib/widgets/blocks/block_item.dart
  10. 2
      example/lib/widgets/layouts/block_layout.dart
  11. 35
      example/pubspec.lock
  12. 12
      example/pubspec.yaml

5
example/lib/l10n/app_en.arb

@ -56,8 +56,9 @@
"flutterCacheManagerDesc": "Desc",
"@_FLUTTER_LOCAL_NOTIFICATIONS": {},
"flutterLocalNotificationsTitle": "Title",
"flutterLocalNotificationsDesc": "Desc",
"flutterLocalNotificationsHintTitle": "Notification title",
"flutterLocalNotificationsHintBody": "Notification body",
"flutterLocalNotificationsBtn": "Send",
"@_FLUTTER_SECURE_STORAGE": {},
"flutterSecureStorageTitle": "Title",

5
example/lib/l10n/app_ru.arb

@ -56,8 +56,9 @@
"flutterCacheManagerDesc": "Описание",
"@_FLUTTER_LOCAL_NOTIFICATIONS": {},
"flutterLocalNotificationsTitle": "Заголовок",
"flutterLocalNotificationsDesc": "Описание",
"flutterLocalNotificationsHintTitle": "Заголовок уведомления",
"flutterLocalNotificationsHintBody": "Текст уведомления",
"flutterLocalNotificationsBtn": "Отправить",
"@_FLUTTER_SECURE_STORAGE": {},
"flutterSecureStorageTitle": "Заголовок",

32
example/lib/packages/flutter_local_notifications/model.dart

@ -1,10 +1,17 @@
import 'package:flutter/widgets.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import 'package:scoped_model/scoped_model.dart';
/// Model for [FlutterLocalNotificationsPage]
class FlutterLocalNotificationsModel extends Model {
/// Get [ScopedModel]
static FlutterLocalNotificationsModel of(BuildContext context) => ScopedModel.of<FlutterLocalNotificationsModel>(context);
static FlutterLocalNotificationsModel of(BuildContext context) =>
ScopedModel.of<FlutterLocalNotificationsModel>(context);
final FlutterLocalNotificationsPlugin notification =
FlutterLocalNotificationsPlugin();
final notificationID = 1;
/// Error
String? _error;
@ -14,4 +21,25 @@ class FlutterLocalNotificationsModel extends Model {
/// Public is error
bool get isError => _error != null;
}
/// Show local notification
Future<void> showNotification({
required String title,
required String body,
}) async {
try {
// Cansel if already run
await notification.cancel(notificationID);
// Show notification
await notification.show(
notificationID,
title,
body,
null,
);
} catch (e) {
_error = e.toString();
notifyListeners();
}
}
}

39
example/lib/packages/flutter_local_notifications/page.dart

@ -5,8 +5,8 @@ import 'package:flutter_example_packages/packages/flutter_local_notifications/pa
import 'package:flutter_example_packages/widgets/base/export.dart';
import 'package:flutter_example_packages/widgets/blocks/block_alert.dart';
import 'package:flutter_example_packages/widgets/blocks/block_info_package.dart';
import 'package:flutter_example_packages/widgets/blocks/block_item.dart';
import 'package:flutter_example_packages/widgets/layouts/block_layout.dart';
import 'package:flutter_example_packages/widgets/texts/export.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
class FlutterLocalNotificationsPage extends AppStatefulWidget {
@ -23,6 +23,9 @@ class FlutterLocalNotificationsPage extends AppStatefulWidget {
class _FlutterLocalNotificationsPageState
extends AppState<FlutterLocalNotificationsPage> {
final TextEditingController _titleController = TextEditingController();
final TextEditingController _bodyController = TextEditingController();
@override
Widget buildWide(
BuildContext context,
@ -44,10 +47,36 @@ class _FlutterLocalNotificationsPageState
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
BlockItem(
title: l10n.flutterLocalNotificationsTitle,
desc: l10n.flutterLocalNotificationsDesc,
value: null,
TextField(
controller: _titleController,
decoration: InputDecoration(
hintText: l10n.flutterLocalNotificationsHintTitle,
),
),
const SizedBox(height: 18),
TextField(
controller: _bodyController,
decoration: InputDecoration(
hintText: l10n.flutterLocalNotificationsHintBody,
),
),
const SizedBox(height: 20),
SizedBox(
width: double.infinity,
child: ElevatedButton(
onPressed: () => model.showNotification(
title: _titleController.text.isEmpty
? l10n.flutterLocalNotificationsHintTitle
: _titleController.text,
body: _bodyController.text.isEmpty
? l10n.flutterLocalNotificationsHintBody
: _bodyController.text,
),
child: TextBodyLarge(
l10n.flutterLocalNotificationsBtn,
color: Colors.white,
),
),
),
],
),

4
example/lib/pages/home/page.dart

@ -135,7 +135,7 @@ class _HomePageState extends AppState<HomePage> {
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
TextTitleLarge(
TextHeadlineMedium(
l10n.homeWelcomeTitle,
color: Colors.white,
),
@ -143,7 +143,7 @@ class _HomePageState extends AppState<HomePage> {
height:
media.orientation == Orientation.portrait ? 40 : 20,
),
TextBodyLarge(
TextTitleMedium(
l10n.homeWelcomeText(packages.length),
color: Colors.white,
)

5
example/lib/pages/home/widgets/home_app_bar.dart

@ -66,13 +66,14 @@ class _HomeAppBarState extends AppState<HomeAppBar> {
? TextField(
focusNode: _searchFocus,
controller: _searchController,
style: theme.textTheme.titleSmall?.copyWith(color: Colors.white),
style: theme.textTheme.titleLarge?.copyWith(color: Colors.white),
cursorColor: Colors.white,
decoration: InputDecoration(
hintText: l10n.homeSearchTitle,
hintStyle:
theme.textTheme.titleSmall?.copyWith(color: Colors.white54),
theme.textTheme.titleLarge?.copyWith(color: Colors.white54),
border: InputBorder.none,
contentPadding: const EdgeInsets.all(0),
),
onChanged: (value) {
widget.onChangeSearch.call(value);

2
example/lib/pages/home/widgets/package_list_item.dart

@ -67,7 +67,7 @@ class PackageListItemWidget extends AppStatelessWidget {
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
TextTitleSmall(item.key),
TextTitleLarge(item.key),
const SizedBox(height: 10),
TextBodyMedium(
item.desc,

62
example/lib/theme/theme.dart

@ -8,6 +8,8 @@ final appTheme = ThemeData(
primary: AppColors.primary,
secondary: AppColors.secondary,
),
/// [Card]
cardTheme: CardTheme(
clipBehavior: Clip.antiAlias,
margin: const EdgeInsets.all(0),
@ -18,27 +20,42 @@ final appTheme = ThemeData(
),
),
/// [TextField]
inputDecorationTheme: const InputDecorationTheme(
contentPadding: EdgeInsets.symmetric(
vertical: 14,
horizontal: 16,
),
border: OutlineInputBorder(),
),
/// [ElevatedButton]
elevatedButtonTheme: ElevatedButtonThemeData(
style: ElevatedButton.styleFrom(
backgroundColor: AppColors.secondary,
minimumSize: const Size.fromHeight(45),
),
),
/// [OutlinedButton]
outlinedButtonTheme: OutlinedButtonThemeData(
style: ButtonStyle(
foregroundColor: MaterialStateProperty.resolveWith<Color>(
(Set<MaterialState> states) {
if (states.contains(MaterialState.disabled)) {
return AppColors.secondary.withOpacity(0.4);
} else {
return AppColors.secondary;
}
}
),
foregroundColor:
MaterialStateProperty.resolveWith<Color>((Set<MaterialState> states) {
if (states.contains(MaterialState.disabled)) {
return AppColors.secondary.withOpacity(0.4);
} else {
return AppColors.secondary;
}
}),
side: MaterialStateProperty.resolveWith<BorderSide>(
(Set<MaterialState> states) {
if (states.contains(MaterialState.disabled)) {
return BorderSide(color: AppColors.secondary.withOpacity(0.4));
} else {
return const BorderSide(color: AppColors.secondary);
}
}
),
(Set<MaterialState> states) {
if (states.contains(MaterialState.disabled)) {
return BorderSide(color: AppColors.secondary.withOpacity(0.4));
} else {
return const BorderSide(color: AppColors.secondary);
}
}),
),
),
@ -49,7 +66,7 @@ final appTheme = ThemeData(
fontWeight: FontWeight.bold,
),
headlineMedium: GoogleFonts.roboto(
fontSize: 36,
fontSize: 30,
fontWeight: FontWeight.bold,
),
headlineSmall: GoogleFonts.roboto(
@ -57,13 +74,16 @@ final appTheme = ThemeData(
fontWeight: FontWeight.bold,
),
titleLarge: GoogleFonts.roboto(
fontSize: 44,
fontSize: 20,
height: 1.3,
),
titleMedium: GoogleFonts.roboto(
fontSize: 36,
fontSize: 18,
height: 1.3,
),
titleSmall: GoogleFonts.roboto(
fontSize: 24,
fontSize: 14,
height: 1.3,
),
bodyLarge: GoogleFonts.openSans(
fontSize: 18,

2
example/lib/widgets/blocks/block_item.dart

@ -27,7 +27,7 @@ class BlockItem<T> extends AppStatelessWidget {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
TextTitleSmall(title),
TextTitleLarge(title),
const SizedBox(height: 8),
TextBodyMedium(desc),
const SizedBox(height: 8),

2
example/lib/widgets/layouts/block_layout.dart

@ -46,7 +46,7 @@ class BlockLayout<T extends Model> extends AppStatelessWidget {
),
),
backgroundColor: AppColors.primary,
title: TextTitleSmall(
title: TextTitleLarge(
title!,
color: Colors.white,
),

35
example/pubspec.lock

@ -244,6 +244,34 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.1"
flutter_local_notifications:
dependency: "direct main"
description:
name: flutter_local_notifications
url: "https://pub.dartlang.org"
source: hosted
version: "14.1.1"
flutter_local_notifications_aurora:
dependency: "direct main"
description:
path: "../packages/flutter_local_notifications/flutter_local_notifications_aurora"
relative: true
source: path
version: "0.0.1"
flutter_local_notifications_linux:
dependency: transitive
description:
name: flutter_local_notifications_linux
url: "https://pub.dartlang.org"
source: hosted
version: "4.0.0+1"
flutter_local_notifications_platform_interface:
dependency: transitive
description:
name: flutter_local_notifications_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "7.0.0+1"
flutter_localizations:
dependency: "direct main"
description: flutter
@ -593,6 +621,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "0.4.12"
timezone:
dependency: transitive
description:
name: timezone
url: "https://pub.dartlang.org"
source: hosted
version: "0.9.2"
timing:
dependency: transitive
description:

12
example/pubspec.yaml

@ -42,12 +42,12 @@ dependencies:
device_info_plus_aurora:
path: ../packages/device_info_plus/device_info_plus_aurora
# ## https://pub.dev/packages/flutter_local_notifications
# flutter_local_notifications: ^14.1.1
# ## https://os-git.omprussia.ru/non-oss/flutter/flutter-plugins/-/tree/master/packages/flutter_local_notifications/flutter_local_notifications_aurora
# flutter_local_notifications_aurora:
# path: ../packages/flutter_local_notifications/flutter_local_notifications_aurora
#
## https://pub.dev/packages/flutter_local_notifications
flutter_local_notifications: ^14.1.1
## https://os-git.omprussia.ru/non-oss/flutter/flutter-plugins/-/tree/master/packages/flutter_local_notifications/flutter_local_notifications_aurora
flutter_local_notifications_aurora:
path: ../packages/flutter_local_notifications/flutter_local_notifications_aurora
# ## https://pub.dev/packages/flutter_secure_storage
# flutter_secure_storage: ^8.0.0
# ## https://os-git.omprussia.ru/non-oss/flutter/flutter-plugins/-/tree/master/packages/flutter_secure_storage/flutter_secure_storage_aurora

Loading…
Cancel
Save