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. 30
      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", "flutterCacheManagerDesc": "Desc",
"@_FLUTTER_LOCAL_NOTIFICATIONS": {}, "@_FLUTTER_LOCAL_NOTIFICATIONS": {},
"flutterLocalNotificationsTitle": "Title", "flutterLocalNotificationsHintTitle": "Notification title",
"flutterLocalNotificationsDesc": "Desc", "flutterLocalNotificationsHintBody": "Notification body",
"flutterLocalNotificationsBtn": "Send",
"@_FLUTTER_SECURE_STORAGE": {}, "@_FLUTTER_SECURE_STORAGE": {},
"flutterSecureStorageTitle": "Title", "flutterSecureStorageTitle": "Title",

5
example/lib/l10n/app_ru.arb

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

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

@ -1,10 +1,17 @@
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import 'package:scoped_model/scoped_model.dart'; import 'package:scoped_model/scoped_model.dart';
/// Model for [FlutterLocalNotificationsPage] /// Model for [FlutterLocalNotificationsPage]
class FlutterLocalNotificationsModel extends Model { class FlutterLocalNotificationsModel extends Model {
/// Get [ScopedModel] /// 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 /// Error
String? _error; String? _error;
@ -14,4 +21,25 @@ class FlutterLocalNotificationsModel extends Model {
/// Public is error /// Public is error
bool get isError => _error != null; 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/base/export.dart';
import 'package:flutter_example_packages/widgets/blocks/block_alert.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_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/layouts/block_layout.dart';
import 'package:flutter_example_packages/widgets/texts/export.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart';
class FlutterLocalNotificationsPage extends AppStatefulWidget { class FlutterLocalNotificationsPage extends AppStatefulWidget {
@ -23,6 +23,9 @@ class FlutterLocalNotificationsPage extends AppStatefulWidget {
class _FlutterLocalNotificationsPageState class _FlutterLocalNotificationsPageState
extends AppState<FlutterLocalNotificationsPage> { extends AppState<FlutterLocalNotificationsPage> {
final TextEditingController _titleController = TextEditingController();
final TextEditingController _bodyController = TextEditingController();
@override @override
Widget buildWide( Widget buildWide(
BuildContext context, BuildContext context,
@ -44,10 +47,36 @@ class _FlutterLocalNotificationsPageState
Column( Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
BlockItem( TextField(
title: l10n.flutterLocalNotificationsTitle, controller: _titleController,
desc: l10n.flutterLocalNotificationsDesc, decoration: InputDecoration(
value: null, 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, mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
TextTitleLarge( TextHeadlineMedium(
l10n.homeWelcomeTitle, l10n.homeWelcomeTitle,
color: Colors.white, color: Colors.white,
), ),
@ -143,7 +143,7 @@ class _HomePageState extends AppState<HomePage> {
height: height:
media.orientation == Orientation.portrait ? 40 : 20, media.orientation == Orientation.portrait ? 40 : 20,
), ),
TextBodyLarge( TextTitleMedium(
l10n.homeWelcomeText(packages.length), l10n.homeWelcomeText(packages.length),
color: Colors.white, color: Colors.white,
) )

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

@ -66,13 +66,14 @@ class _HomeAppBarState extends AppState<HomeAppBar> {
? TextField( ? TextField(
focusNode: _searchFocus, focusNode: _searchFocus,
controller: _searchController, controller: _searchController,
style: theme.textTheme.titleSmall?.copyWith(color: Colors.white), style: theme.textTheme.titleLarge?.copyWith(color: Colors.white),
cursorColor: Colors.white, cursorColor: Colors.white,
decoration: InputDecoration( decoration: InputDecoration(
hintText: l10n.homeSearchTitle, hintText: l10n.homeSearchTitle,
hintStyle: hintStyle:
theme.textTheme.titleSmall?.copyWith(color: Colors.white54), theme.textTheme.titleLarge?.copyWith(color: Colors.white54),
border: InputBorder.none, border: InputBorder.none,
contentPadding: const EdgeInsets.all(0),
), ),
onChanged: (value) { onChanged: (value) {
widget.onChangeSearch.call(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( child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
TextTitleSmall(item.key), TextTitleLarge(item.key),
const SizedBox(height: 10), const SizedBox(height: 10),
TextBodyMedium( TextBodyMedium(
item.desc, item.desc,

62
example/lib/theme/theme.dart

@ -8,6 +8,8 @@ final appTheme = ThemeData(
primary: AppColors.primary, primary: AppColors.primary,
secondary: AppColors.secondary, secondary: AppColors.secondary,
), ),
/// [Card]
cardTheme: CardTheme( cardTheme: CardTheme(
clipBehavior: Clip.antiAlias, clipBehavior: Clip.antiAlias,
margin: const EdgeInsets.all(0), 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] /// [OutlinedButton]
outlinedButtonTheme: OutlinedButtonThemeData( outlinedButtonTheme: OutlinedButtonThemeData(
style: ButtonStyle( style: ButtonStyle(
foregroundColor: MaterialStateProperty.resolveWith<Color>( foregroundColor:
(Set<MaterialState> states) { MaterialStateProperty.resolveWith<Color>((Set<MaterialState> states) {
if (states.contains(MaterialState.disabled)) { if (states.contains(MaterialState.disabled)) {
return AppColors.secondary.withOpacity(0.4); return AppColors.secondary.withOpacity(0.4);
} else { } else {
return AppColors.secondary; return AppColors.secondary;
} }
} }),
),
side: MaterialStateProperty.resolveWith<BorderSide>( side: MaterialStateProperty.resolveWith<BorderSide>(
(Set<MaterialState> states) { (Set<MaterialState> states) {
if (states.contains(MaterialState.disabled)) { if (states.contains(MaterialState.disabled)) {
return BorderSide(color: AppColors.secondary.withOpacity(0.4)); return BorderSide(color: AppColors.secondary.withOpacity(0.4));
} else { } else {
return const BorderSide(color: AppColors.secondary); return const BorderSide(color: AppColors.secondary);
} }
} }),
),
), ),
), ),
@ -49,7 +66,7 @@ final appTheme = ThemeData(
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
), ),
headlineMedium: GoogleFonts.roboto( headlineMedium: GoogleFonts.roboto(
fontSize: 36, fontSize: 30,
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
), ),
headlineSmall: GoogleFonts.roboto( headlineSmall: GoogleFonts.roboto(
@ -57,13 +74,16 @@ final appTheme = ThemeData(
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
), ),
titleLarge: GoogleFonts.roboto( titleLarge: GoogleFonts.roboto(
fontSize: 44, fontSize: 20,
height: 1.3,
), ),
titleMedium: GoogleFonts.roboto( titleMedium: GoogleFonts.roboto(
fontSize: 36, fontSize: 18,
height: 1.3,
), ),
titleSmall: GoogleFonts.roboto( titleSmall: GoogleFonts.roboto(
fontSize: 24, fontSize: 14,
height: 1.3,
), ),
bodyLarge: GoogleFonts.openSans( bodyLarge: GoogleFonts.openSans(
fontSize: 18, fontSize: 18,

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

@ -27,7 +27,7 @@ class BlockItem<T> extends AppStatelessWidget {
return Column( return Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
TextTitleSmall(title), TextTitleLarge(title),
const SizedBox(height: 8), const SizedBox(height: 8),
TextBodyMedium(desc), TextBodyMedium(desc),
const SizedBox(height: 8), 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, backgroundColor: AppColors.primary,
title: TextTitleSmall( title: TextTitleLarge(
title!, title!,
color: Colors.white, color: Colors.white,
), ),

35
example/pubspec.lock

@ -244,6 +244,34 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.0.1" 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: flutter_localizations:
dependency: "direct main" dependency: "direct main"
description: flutter description: flutter
@ -593,6 +621,13 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.4.12" version: "0.4.12"
timezone:
dependency: transitive
description:
name: timezone
url: "https://pub.dartlang.org"
source: hosted
version: "0.9.2"
timing: timing:
dependency: transitive dependency: transitive
description: description:

12
example/pubspec.yaml

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

Loading…
Cancel
Save