Skip to content

Commit

Permalink
cleanup and optimize logic
Browse files Browse the repository at this point in the history
- update launch Url logic because of deprecation
  • Loading branch information
lucianojung committed Apr 28, 2024
1 parent 4d39c4c commit 996b107
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 29 deletions.
19 changes: 11 additions & 8 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class MyApp extends StatelessWidget {
create: (context) => ThemeProvider(),
builder: (context, _) {
final themeProvider = Provider.of<ThemeProvider>(context);
themeProvider.toggleTheme(!themeProvider.isDarkMode);
themeProvider.toggleTheme(!themeProvider.isDarkMode);

return MaterialApp(
scrollBehavior: AppScrollBehavior(),
Expand Down Expand Up @@ -81,6 +83,7 @@ class _HomeViewState extends State<HomeView> {
}

Widget _body() {
ThemeData _themeData = Theme.of(context);
return SafeArea(
child: Container(
// width: 1280,
Expand All @@ -97,25 +100,25 @@ class _HomeViewState extends State<HomeView> {
),
for (CustomListTile listTile in listTileList)
ListTile(
leading: Icon(listTile.iconData),
title: Text(listTile.title),
subtitle: Text('Version: ${listTile.version}'),
leading: Icon(listTile.iconData, color: _themeData.textTheme.titleMedium?.color),
title: Text(listTile.title, style: _themeData.textTheme.titleMedium),
subtitle: Text('Version: ${listTile.version}', style: _themeData.textTheme.titleSmall),
onTap: () {
setState(() {
Navigator.of(context).pushNamed(listTile.route);
});
},
trailing: Icon(Icons.arrow_forward),
trailing: Icon(Icons.arrow_forward, color: _themeData.textTheme.titleMedium?.color),
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: Divider(),
),
ListTile(
leading: Icon(Icons.assistant),
trailing: Icon(Icons.launch),
title: Text('Upcoming'),
subtitle: Text('...'),
leading: Icon(Icons.assistant, color: _themeData.textTheme.titleMedium?.color),
trailing: Icon(Icons.launch, color: _themeData.textTheme.titleMedium?.color),
title: Text('Upcoming', style: _themeData.textTheme.titleMedium),
subtitle: Text('...', style: _themeData.textTheme.titleSmall),
onTap: () {
setState(() {
_launchUrl(Uri.parse('https://lucianojung.medium.com/'));
Expand Down
17 changes: 8 additions & 9 deletions lib/packages/custom_carousel/custom_carousel_main.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'dart:ui';

import 'package:expandable/expandable.dart';
import 'package:flutter/material.dart';
Expand Down Expand Up @@ -177,8 +176,8 @@ class _CustomCarouselState extends State<CustomCarouselMain> {
max: 1,
divisions: 20,
labels: RangeLabels(
_flipH.start.toStringAsFixed(1).toString(),
_flipH.end.toStringAsFixed(1).toString(),
'${(_flipH.start * 10).roundToDouble() / 10}',
'${(_flipH.end * 10).roundToDouble() / 10}',
),
onChanged: (newRange) {
setState(() {
Expand All @@ -192,8 +191,8 @@ class _CustomCarouselState extends State<CustomCarouselMain> {
max: 1,
divisions: 20,
labels: RangeLabels(
_flipV.start.toStringAsFixed(1).toString(),
_flipV.end.toStringAsFixed(1).toString(),
'${(_flipV.start * 10).roundToDouble() / 10}',
'${(_flipV.end * 10).roundToDouble() / 10}',
),
onChanged: (newRange) {
setState(() {
Expand Down Expand Up @@ -241,8 +240,8 @@ class _CustomCarouselState extends State<CustomCarouselMain> {
max: 1,
divisions: 20,
labels: RangeLabels(
_slideX.start.toStringAsFixed(1).toString(),
_slideX.end.toStringAsFixed(1).toString(),
'${(_slideX.start * 10).roundToDouble() / 10}',
'${(_slideX.end * 10).roundToDouble() / 10}',
),
onChanged: (newRange) {
setState(() {
Expand All @@ -256,8 +255,8 @@ class _CustomCarouselState extends State<CustomCarouselMain> {
max: 5,
divisions: 50,
labels: RangeLabels(
_slideY.start.toStringAsFixed(1).toString(),
_slideY.end.toStringAsFixed(1).toString(),
'${(_slideY.start * 10).roundToDouble() / 10}',
'${(_slideY.end * 10).roundToDouble() / 10}',
),
onChanged: (newRange) {
setState(() {
Expand Down
22 changes: 11 additions & 11 deletions lib/packages/url_launcher/url_launcher_main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -250,20 +250,20 @@ class _UrlLauncherState extends State<UrlLauncher> {
}

void _launchUrl(String url) async {
if (await canLaunch(url)) {
if (await canLaunchUrl(Uri.parse(url))) {
if (!_isWebUrl)
launch(url);
launchUrl(Uri.parse(url));
else
launch(
url,
forceSafariVC: _forceSafarieVC,
forceWebView: _forceWebView,
enableJavaScript: _javaScriptEnabled,
enableDomStorage: _enableDomStorage,
universalLinksOnly: _universalLinksOnly,
launchUrl(
Uri.parse(url),
// forceSafariVC: _forceSafarieVC,
// forceWebView: _forceWebView,
// enableJavaScript: _javaScriptEnabled,
// enableDomStorage: _enableDomStorage,
// universalLinksOnly: _universalLinksOnly,
webOnlyWindowName: _webOnlyWindowName ? '_self' : '_blank',
statusBarBrightness: _statusBarBrigthness ? Brightness.dark : Brightness.light,
headers: (_sendHeaderInfos) ? _headers : {}
// statusBarBrightness: _statusBarBrigthness ? Brightness.dark : Brightness.light,
// headers: (_sendHeaderInfos) ? _headers : {}
);
} else {
throw 'Could not launch $url';
Expand Down
15 changes: 15 additions & 0 deletions lib/service/MyTheme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ class MyTheme {
static TextStyle _blackTextStyle = TextStyle(color: Colors.black);
static TextStyle _black54TextStyle = TextStyle(color: Colors.black54);
static TextStyle _black87TextStyle = TextStyle(color: Colors.black87);
static TextStyle _whiteTextStyle = TextStyle(color: Colors.white);
static TextStyle _white54TextStyle = TextStyle(color: Colors.white54);
static TextStyle _white70TextStyle = TextStyle(color: Colors.white70);

static final lightTheme = ThemeData.light().copyWith(
primaryColor: _mainColor,
Expand All @@ -38,6 +41,18 @@ class MyTheme {

static final darkTheme = ThemeData.dark().copyWith(
primaryColor: _mainColor,
textTheme: TextTheme(
displayLarge: _whiteTextStyle,
displayMedium: _whiteTextStyle,
displaySmall: _whiteTextStyle,
headlineMedium: _whiteTextStyle,
headlineSmall: _whiteTextStyle,
titleLarge: _whiteTextStyle,
bodyLarge: _white54TextStyle,
bodyMedium: _white54TextStyle,
titleMedium: _white70TextStyle,
titleSmall: _white70TextStyle,
),
appBarTheme: _appBarTheme,
colorScheme: ColorScheme.fromSwatch().copyWith(secondary: _secondaryColor),
);
Expand Down
1 change: 0 additions & 1 deletion test/widget_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
// gestures. You can also use WidgetTester to find child widgets in the widget
// tree, read text, and verify that the values of widget properties are correct.

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';


Expand Down

0 comments on commit 996b107

Please sign in to comment.