This commit is contained in:
Yoshi 2024-07-09 23:03:40 +03:00
parent 9a7858f279
commit dd3339bc3b
8 changed files with 1067 additions and 950 deletions

View file

@ -45,205 +45,208 @@ class _CreateWeatherCardState extends State<CreateWeatherCard> {
@override
Widget build(BuildContext context) {
const kTextFieldElevation = 4.0;
return Form(
key: formKey,
child: SingleChildScrollView(
child: Stack(
children: [
Padding(
padding: EdgeInsets.only(
bottom: MediaQuery.of(context).viewInsets.bottom,
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: [
Padding(
padding: const EdgeInsets.fromLTRB(10, 10, 10, 0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
IconButton(
onPressed: () {
Get.back();
},
icon: const Icon(
Iconsax.close_square,
size: 18,
),
),
Text(
'create'.tr,
style: context.textTheme.titleLarge?.copyWith(
fontSize: 20,
),
textAlign: TextAlign.center,
),
IconButton(
onPressed: () async {
if (formKey.currentState!.validate()) {
textTrim(_controllerLat);
textTrim(_controllerLon);
textTrim(_controllerCity);
textTrim(_controllerDistrict);
setState(() => isLoading = true);
await weatherController.addCardWeather(
double.parse(_controllerLat.text),
double.parse(_controllerLon.text),
_controllerCity.text,
_controllerDistrict.text,
);
setState(() => isLoading = false);
return Padding(
padding: EdgeInsets.only(bottom: MediaQuery.of(context).padding.bottom),
child: Form(
key: formKey,
child: SingleChildScrollView(
child: Stack(
children: [
Padding(
padding: EdgeInsets.only(
bottom: MediaQuery.of(context).viewInsets.bottom,
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: [
Padding(
padding: const EdgeInsets.fromLTRB(10, 10, 10, 0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
IconButton(
onPressed: () {
Get.back();
}
},
icon: const Icon(
Iconsax.tick_square,
size: 18,
),
),
],
),
),
RawAutocomplete<Result>(
focusNode: _focusNode,
textEditingController: _controller,
fieldViewBuilder: (BuildContext context,
TextEditingController fieldTextEditingController,
FocusNode fieldFocusNode,
VoidCallback onFieldSubmitted) {
return MyTextForm(
elevation: kTextFieldElevation,
labelText: 'search'.tr,
type: TextInputType.text,
icon: const Icon(Iconsax.global_search),
controller: _controller,
margin:
const EdgeInsets.only(left: 10, right: 10, top: 10),
focusNode: _focusNode,
);
},
optionsBuilder: (TextEditingValue textEditingValue) {
if (textEditingValue.text.isEmpty) {
return const Iterable<Result>.empty();
}
return WeatherAPI()
.getCity(textEditingValue.text, locale);
},
onSelected: (Result selection) => fillController(selection),
displayStringForOption: (Result option) =>
'${option.name}, ${option.admin1}',
optionsViewBuilder: (BuildContext context,
AutocompleteOnSelected<Result> onSelected,
Iterable<Result> options) {
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 10),
child: Align(
alignment: Alignment.topCenter,
child: Material(
borderRadius: BorderRadius.circular(20),
elevation: 4.0,
child: ListView.builder(
padding: EdgeInsets.zero,
shrinkWrap: true,
itemCount: options.length,
itemBuilder: (BuildContext context, int index) {
final Result option = options.elementAt(index);
return InkWell(
onTap: () => onSelected(option),
child: ListTile(
title: Text(
'${option.name}, ${option.admin1}',
style: context.textTheme.labelLarge,
),
),
);
},
},
icon: const Icon(
Iconsax.close_square,
size: 18,
),
),
),
);
},
),
MyTextForm(
elevation: kTextFieldElevation,
controller: _controllerLat,
labelText: 'lat'.tr,
type: TextInputType.number,
icon: const Icon(Iconsax.location),
margin: const EdgeInsets.only(left: 10, right: 10, top: 10),
validator: (value) {
if (value == null || value.isEmpty) {
return 'validateValue'.tr;
}
double? numericValue = double.tryParse(value);
if (numericValue == null) {
return 'validateNumber'.tr;
}
if (numericValue < -90 || numericValue > 90) {
return 'validate90'.tr;
}
return null;
},
),
MyTextForm(
elevation: kTextFieldElevation,
controller: _controllerLon,
labelText: 'lon'.tr,
type: TextInputType.number,
icon: const Icon(Iconsax.location),
margin: const EdgeInsets.only(left: 10, right: 10, top: 10),
validator: (value) {
if (value == null || value.isEmpty) {
return 'validateValue'.tr;
}
double? numericValue = double.tryParse(value);
if (numericValue == null) {
return 'validateNumber'.tr;
}
if (numericValue < -180 || numericValue > 180) {
return 'validate180'.tr;
}
return null;
},
),
MyTextForm(
elevation: kTextFieldElevation,
controller: _controllerCity,
labelText: 'city'.tr,
type: TextInputType.name,
icon: const Icon(Icons.location_city_rounded),
margin: const EdgeInsets.only(left: 10, right: 10, top: 10),
validator: (value) {
if (value == null || value.isEmpty) {
return 'validateName'.tr;
}
return null;
},
),
MyTextForm(
elevation: kTextFieldElevation,
controller: _controllerDistrict,
labelText: 'district'.tr,
type: TextInputType.streetAddress,
icon: const Icon(Iconsax.global),
margin: const EdgeInsets.only(left: 10, right: 10, top: 10),
validator: (value) {
if (value == null || value.isEmpty) {
return 'validateName'.tr;
}
return null;
},
),
const SizedBox(height: 20),
],
Text(
'create'.tr,
style: context.textTheme.titleLarge?.copyWith(
fontSize: 20,
),
textAlign: TextAlign.center,
),
IconButton(
onPressed: () async {
if (formKey.currentState!.validate()) {
textTrim(_controllerLat);
textTrim(_controllerLon);
textTrim(_controllerCity);
textTrim(_controllerDistrict);
setState(() => isLoading = true);
await weatherController.addCardWeather(
double.parse(_controllerLat.text),
double.parse(_controllerLon.text),
_controllerCity.text,
_controllerDistrict.text,
);
setState(() => isLoading = false);
Get.back();
}
},
icon: const Icon(
Iconsax.tick_square,
size: 18,
),
),
],
),
),
RawAutocomplete<Result>(
focusNode: _focusNode,
textEditingController: _controller,
fieldViewBuilder: (BuildContext context,
TextEditingController fieldTextEditingController,
FocusNode fieldFocusNode,
VoidCallback onFieldSubmitted) {
return MyTextForm(
elevation: kTextFieldElevation,
labelText: 'search'.tr,
type: TextInputType.text,
icon: const Icon(Iconsax.global_search),
controller: _controller,
margin:
const EdgeInsets.only(left: 10, right: 10, top: 10),
focusNode: _focusNode,
);
},
optionsBuilder: (TextEditingValue textEditingValue) {
if (textEditingValue.text.isEmpty) {
return const Iterable<Result>.empty();
}
return WeatherAPI()
.getCity(textEditingValue.text, locale);
},
onSelected: (Result selection) => fillController(selection),
displayStringForOption: (Result option) =>
'${option.name}, ${option.admin1}',
optionsViewBuilder: (BuildContext context,
AutocompleteOnSelected<Result> onSelected,
Iterable<Result> options) {
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 10),
child: Align(
alignment: Alignment.topCenter,
child: Material(
borderRadius: BorderRadius.circular(20),
elevation: 4.0,
child: ListView.builder(
padding: EdgeInsets.zero,
shrinkWrap: true,
itemCount: options.length,
itemBuilder: (BuildContext context, int index) {
final Result option = options.elementAt(index);
return InkWell(
onTap: () => onSelected(option),
child: ListTile(
title: Text(
'${option.name}, ${option.admin1}',
style: context.textTheme.labelLarge,
),
),
);
},
),
),
),
);
},
),
MyTextForm(
elevation: kTextFieldElevation,
controller: _controllerLat,
labelText: 'lat'.tr,
type: TextInputType.number,
icon: const Icon(Iconsax.location),
margin: const EdgeInsets.only(left: 10, right: 10, top: 10),
validator: (value) {
if (value == null || value.isEmpty) {
return 'validateValue'.tr;
}
double? numericValue = double.tryParse(value);
if (numericValue == null) {
return 'validateNumber'.tr;
}
if (numericValue < -90 || numericValue > 90) {
return 'validate90'.tr;
}
return null;
},
),
MyTextForm(
elevation: kTextFieldElevation,
controller: _controllerLon,
labelText: 'lon'.tr,
type: TextInputType.number,
icon: const Icon(Iconsax.location),
margin: const EdgeInsets.only(left: 10, right: 10, top: 10),
validator: (value) {
if (value == null || value.isEmpty) {
return 'validateValue'.tr;
}
double? numericValue = double.tryParse(value);
if (numericValue == null) {
return 'validateNumber'.tr;
}
if (numericValue < -180 || numericValue > 180) {
return 'validate180'.tr;
}
return null;
},
),
MyTextForm(
elevation: kTextFieldElevation,
controller: _controllerCity,
labelText: 'city'.tr,
type: TextInputType.name,
icon: const Icon(Icons.location_city_rounded),
margin: const EdgeInsets.only(left: 10, right: 10, top: 10),
validator: (value) {
if (value == null || value.isEmpty) {
return 'validateName'.tr;
}
return null;
},
),
MyTextForm(
elevation: kTextFieldElevation,
controller: _controllerDistrict,
labelText: 'district'.tr,
type: TextInputType.streetAddress,
icon: const Icon(Iconsax.global),
margin: const EdgeInsets.only(left: 10, right: 10, top: 10),
validator: (value) {
if (value == null || value.isEmpty) {
return 'validateName'.tr;
}
return null;
},
),
const SizedBox(height: 20),
],
),
),
),
if (isLoading)
const Center(
child: CircularProgressIndicator(),
),
],
if (isLoading)
const Center(
child: CircularProgressIndicator(),
),
],
),
),
),
);

File diff suppressed because it is too large Load diff

View file

@ -18,6 +18,7 @@ import 'package:rain/app/modules/geolocation.dart';
import 'package:rain/app/modules/home.dart';
import 'package:rain/app/modules/onboarding.dart';
import 'package:rain/theme/theme.dart';
import 'package:rain/utils/device_info.dart';
import 'package:time_machine/time_machine.dart';
import 'package:timezone/data/latest_all.dart' as tz;
import 'package:timezone/timezone.dart' as tz;
@ -92,8 +93,7 @@ void main() async {
? isOnline.value = Future(() => false)
: isOnline.value = InternetConnection().hasInternetAccess;
});
SystemChrome.setSystemUIOverlayStyle(
const SystemUiOverlayStyle(systemNavigationBarColor: Colors.black));
DeviceFeature().init();
if (Platform.isAndroid) {
Workmanager().initialize(callbackDispatcher, isInDebugMode: kDebugMode);
await setOptimalDisplayMode();
@ -284,34 +284,42 @@ class _MyAppState extends State<MyApp> {
@override
Widget build(BuildContext context) {
final edgeToEdgeAvailable = DeviceFeature().isEdgeToEdgeAvailable();
SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);
return GestureDetector(
onTap: () => FocusManager.instance.primaryFocus?.unfocus(),
child: DynamicColorBuilder(
builder: (lightColorScheme, darkColorScheme) {
final lightMaterialTheme =
lightTheme(lightColorScheme?.surface, lightColorScheme);
final darkMaterialTheme =
darkTheme(darkColorScheme?.surface, darkColorScheme);
final darkMaterialThemeOled = darkTheme(oledColor, darkColorScheme);
final lightMaterialTheme = lightTheme(
lightColorScheme?.surface, lightColorScheme, edgeToEdgeAvailable);
final darkMaterialTheme = darkTheme(
darkColorScheme?.surface, darkColorScheme, edgeToEdgeAvailable);
final darkMaterialThemeOled =
darkTheme(oledColor, darkColorScheme, edgeToEdgeAvailable);
return GetMaterialApp(
themeMode: themeController.theme,
theme: materialColor
? lightColorScheme != null
? lightMaterialTheme
: lightTheme(lightColor, colorSchemeLight)
: lightTheme(lightColor, colorSchemeLight),
: lightTheme(
lightColor, colorSchemeLight, edgeToEdgeAvailable)
: lightTheme(lightColor, colorSchemeLight, edgeToEdgeAvailable),
darkTheme: amoledTheme
? materialColor
? darkColorScheme != null
? darkMaterialThemeOled
: darkTheme(oledColor, colorSchemeDark)
: darkTheme(oledColor, colorSchemeDark)
: darkTheme(
oledColor, colorSchemeDark, edgeToEdgeAvailable)
: darkTheme(oledColor, colorSchemeDark, edgeToEdgeAvailable)
: materialColor
? darkColorScheme != null
? darkMaterialTheme
: darkTheme(darkColor, colorSchemeDark)
: darkTheme(darkColor, colorSchemeDark),
: darkTheme(
darkColor, colorSchemeDark, edgeToEdgeAvailable)
: darkTheme(
darkColor, colorSchemeDark, edgeToEdgeAvailable),
localizationsDelegates: const [
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,

View file

@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:dynamic_color/dynamic_color.dart';
@ -18,7 +19,8 @@ ColorScheme colorSchemeDark = ColorScheme.fromSeed(
brightness: Brightness.dark,
);
ThemeData lightTheme(Color? color, ColorScheme? colorScheme) {
ThemeData lightTheme(
Color? color, ColorScheme? colorScheme, bool edgeToEdgeAvailable) {
return baseLigth.copyWith(
brightness: Brightness.light,
colorScheme: colorScheme
@ -34,6 +36,16 @@ ThemeData lightTheme(Color? color, ColorScheme? colorScheme) {
shadowColor: Colors.transparent,
surfaceTintColor: Colors.transparent,
elevation: 0,
systemOverlayStyle: SystemUiOverlayStyle(
statusBarIconBrightness: Brightness.dark,
statusBarColor: Colors.transparent,
systemStatusBarContrastEnforced: false,
systemNavigationBarContrastEnforced: false,
systemNavigationBarDividerColor: Colors.transparent,
systemNavigationBarIconBrightness: Brightness.dark,
systemNavigationBarColor:
edgeToEdgeAvailable ? Colors.transparent : colorScheme?.surface,
),
),
primaryColor: color,
canvasColor: color,
@ -74,7 +86,8 @@ ThemeData lightTheme(Color? color, ColorScheme? colorScheme) {
);
}
ThemeData darkTheme(Color? color, ColorScheme? colorScheme) {
ThemeData darkTheme(
Color? color, ColorScheme? colorScheme, bool edgeToEdgeAvailable) {
return baseDark.copyWith(
brightness: Brightness.dark,
colorScheme: colorScheme
@ -90,6 +103,16 @@ ThemeData darkTheme(Color? color, ColorScheme? colorScheme) {
shadowColor: Colors.transparent,
surfaceTintColor: Colors.transparent,
elevation: 0,
systemOverlayStyle: SystemUiOverlayStyle(
statusBarIconBrightness: Brightness.light,
statusBarColor: Colors.transparent,
systemStatusBarContrastEnforced: false,
systemNavigationBarContrastEnforced: false,
systemNavigationBarDividerColor: Colors.transparent,
systemNavigationBarIconBrightness: Brightness.light,
systemNavigationBarColor:
edgeToEdgeAvailable ? Colors.transparent : colorScheme?.surface,
),
),
primaryColor: color,
canvasColor: color,

View file

@ -0,0 +1,31 @@
import 'package:device_info_plus/device_info_plus.dart';
import 'package:flutter/foundation.dart';
class DeviceFeature {
DeviceFeature._internal();
static final DeviceFeature _singleton = DeviceFeature._internal();
factory DeviceFeature() {
return _singleton;
}
final _deviceInfoPlugin = DeviceInfoPlugin();
AndroidDeviceInfo? _androidDeviceInfo;
Future<void> init() async {
try {
_androidDeviceInfo = await _deviceInfoPlugin.androidInfo;
} catch (e) {
if (kDebugMode) {
print('Error initializing device info: $e');
}
}
}
bool isEdgeToEdgeAvailable() {
return _androidDeviceInfo != null &&
_androidDeviceInfo!.version.sdkInt > 28;
}
}

View file

@ -6,6 +6,7 @@ import FlutterMacOS
import Foundation
import connectivity_plus
import device_info_plus
import dynamic_color
import flutter_local_notifications
import flutter_timezone
@ -17,6 +18,7 @@ import url_launcher_macos
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
ConnectivityPlusPlugin.register(with: registry.registrar(forPlugin: "ConnectivityPlusPlugin"))
DeviceInfoPlusMacosPlugin.register(with: registry.registrar(forPlugin: "DeviceInfoPlusMacosPlugin"))
DynamicColorPlugin.register(with: registry.registrar(forPlugin: "DynamicColorPlugin"))
FlutterLocalNotificationsPlugin.register(with: registry.registrar(forPlugin: "FlutterLocalNotificationsPlugin"))
FlutterTimezonePlugin.register(with: registry.registrar(forPlugin: "FlutterTimezonePlugin"))

View file

@ -233,6 +233,22 @@ packages:
url: "https://pub.dev"
source: hosted
version: "0.7.10"
device_info_plus:
dependency: "direct main"
description:
name: device_info_plus
sha256: eead12d1a1ed83d8283ab4c2f3fca23ac4082f29f25f29dff0f758f57d06ec91
url: "https://pub.dev"
source: hosted
version: "10.1.0"
device_info_plus_platform_interface:
dependency: transitive
description:
name: device_info_plus_platform_interface
sha256: d3b01d5868b50ae571cd1dc6e502fc94d956b665756180f7b16ead09e836fd64
url: "https://pub.dev"
source: hosted
version: "7.0.0"
dio:
dependency: "direct main"
description:
@ -302,6 +318,15 @@ packages:
url: "https://pub.dev"
source: hosted
version: "0.6.0"
flutter_glow:
dependency: "direct main"
description:
path: "."
ref: HEAD
resolved-ref: "7c5e1fd34583db4b40073add9ca329b03bf52a51"
url: "https://github.com/payam-zahedi/flutter-glow.git"
source: git
version: "0.3.1"
flutter_hsvcolor_picker:
dependency: "direct main"
description:
@ -372,10 +397,10 @@ packages:
dependency: "direct main"
description:
name: flutter_timezone
sha256: b7448ff8a9e1350606727e40b3f314aa798a6a1cc07127eba58f09b98a66f03f
sha256: f9c328f66d58cd2af8a0cbd2f84d0c211fda8b7332b5e458d9848bd9ec936120
url: "https://pub.dev"
source: hosted
version: "2.0.0"
version: "2.0.1"
flutter_web_plugins:
dependency: transitive
description: flutter
@ -393,10 +418,10 @@ packages:
dependency: "direct main"
description:
name: freezed_annotation
sha256: f54946fdb1fa7b01f780841937b1a80783a20b393485f3f6cdf336fd6f4705f2
sha256: f9f6597ac43cc262fa7d7f2e65259a6060c23a560525d1f2631be374540f2a9b
url: "https://pub.dev"
source: hosted
version: "2.4.2"
version: "2.4.3"
frontend_server_client:
dependency: transitive
description:
@ -625,18 +650,10 @@ packages:
dependency: transitive
description:
name: js
sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3
sha256: c1b2e9b5ea78c45e1a0788d29606ba27dc5f71f019f32ca5140f61ef071838cf
url: "https://pub.dev"
source: hosted
version: "0.6.7"
js_interop:
dependency: transitive
description:
name: js_interop
sha256: "7ec859c296958ccea34dc770504bd3ff4ae52fdd9e7eeb2bacc7081ad476a1f5"
url: "https://pub.dev"
source: hosted
version: "0.0.1"
version: "0.7.1"
json_annotation:
dependency: "direct main"
description:
@ -785,10 +802,10 @@ packages:
dependency: transitive
description:
name: path_provider_android
sha256: bca87b0165ffd7cdb9cad8edd22d18d2201e886d9a9f19b4fb3452ea7df3a72a
sha256: "30c5aa827a6ae95ce2853cdc5fe3971daaac00f6f081c419c013f7f57bff2f5e"
url: "https://pub.dev"
source: hosted
version: "2.2.6"
version: "2.2.7"
path_provider_foundation:
dependency: transitive
description:
@ -817,10 +834,10 @@ packages:
dependency: transitive
description:
name: path_provider_windows
sha256: "8bc9f22eee8690981c22aa7fc602f5c85b497a6fb2ceb35ee5a5e5ed85ad8170"
sha256: bd6f00dbd873bfb70d0761682da2b3a2c2fccc2b9e84c495821639601d81afe7
url: "https://pub.dev"
source: hosted
version: "2.2.1"
version: "2.3.0"
petitparser:
dependency: transitive
description:
@ -1162,6 +1179,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "5.5.1"
win32_registry:
dependency: transitive
description:
name: win32_registry
sha256: "10589e0d7f4e053f2c61023a31c9ce01146656a70b7b7f0828c0b46d7da2a9bb"
url: "https://pub.dev"
source: hosted
version: "1.1.3"
workmanager:
dependency: "direct main"
description:

View file

@ -29,14 +29,18 @@ dependencies:
google_fonts: ^6.2.1
url_launcher: ^6.3.0
time_machine: ^0.9.17
flutter_glow:
git:
url: https://github.com/payam-zahedi/flutter-glow.git
dynamic_color: ^1.7.0
path_provider: ^2.1.3
# quick_settings: ^1.0.1
json_annotation: ^4.9.0
flutter_timezone: ^2.0.0
flutter_timezone: ^2.0.1
device_info_plus: ^10.1.0
package_info_plus: ^8.0.0
connectivity_plus: ^6.0.3
freezed_annotation: ^2.4.2
freezed_annotation: ^2.4.3
isar_flutter_libs:
version: ^3.1.7
hosted: https://pub.isar-community.dev/