Skip to content

Commit 996b107

Browse files
committed
cleanup and optimize logic
- update launch Url logic because of deprecation
1 parent 4d39c4c commit 996b107

File tree

5 files changed

+45
-29
lines changed

5 files changed

+45
-29
lines changed

lib/main.dart

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ class MyApp extends StatelessWidget {
1818
create: (context) => ThemeProvider(),
1919
builder: (context, _) {
2020
final themeProvider = Provider.of<ThemeProvider>(context);
21+
themeProvider.toggleTheme(!themeProvider.isDarkMode);
22+
themeProvider.toggleTheme(!themeProvider.isDarkMode);
2123

2224
return MaterialApp(
2325
scrollBehavior: AppScrollBehavior(),
@@ -81,6 +83,7 @@ class _HomeViewState extends State<HomeView> {
8183
}
8284

8385
Widget _body() {
86+
ThemeData _themeData = Theme.of(context);
8487
return SafeArea(
8588
child: Container(
8689
// width: 1280,
@@ -97,25 +100,25 @@ class _HomeViewState extends State<HomeView> {
97100
),
98101
for (CustomListTile listTile in listTileList)
99102
ListTile(
100-
leading: Icon(listTile.iconData),
101-
title: Text(listTile.title),
102-
subtitle: Text('Version: ${listTile.version}'),
103+
leading: Icon(listTile.iconData, color: _themeData.textTheme.titleMedium?.color),
104+
title: Text(listTile.title, style: _themeData.textTheme.titleMedium),
105+
subtitle: Text('Version: ${listTile.version}', style: _themeData.textTheme.titleSmall),
103106
onTap: () {
104107
setState(() {
105108
Navigator.of(context).pushNamed(listTile.route);
106109
});
107110
},
108-
trailing: Icon(Icons.arrow_forward),
111+
trailing: Icon(Icons.arrow_forward, color: _themeData.textTheme.titleMedium?.color),
109112
),
110113
Padding(
111114
padding: const EdgeInsets.symmetric(horizontal: 16.0),
112115
child: Divider(),
113116
),
114117
ListTile(
115-
leading: Icon(Icons.assistant),
116-
trailing: Icon(Icons.launch),
117-
title: Text('Upcoming'),
118-
subtitle: Text('...'),
118+
leading: Icon(Icons.assistant, color: _themeData.textTheme.titleMedium?.color),
119+
trailing: Icon(Icons.launch, color: _themeData.textTheme.titleMedium?.color),
120+
title: Text('Upcoming', style: _themeData.textTheme.titleMedium),
121+
subtitle: Text('...', style: _themeData.textTheme.titleSmall),
119122
onTap: () {
120123
setState(() {
121124
_launchUrl(Uri.parse('https://lucianojung.medium.com/'));

lib/packages/custom_carousel/custom_carousel_main.dart

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import 'dart:ui';
21

32
import 'package:expandable/expandable.dart';
43
import 'package:flutter/material.dart';
@@ -177,8 +176,8 @@ class _CustomCarouselState extends State<CustomCarouselMain> {
177176
max: 1,
178177
divisions: 20,
179178
labels: RangeLabels(
180-
_flipH.start.toStringAsFixed(1).toString(),
181-
_flipH.end.toStringAsFixed(1).toString(),
179+
'${(_flipH.start * 10).roundToDouble() / 10}',
180+
'${(_flipH.end * 10).roundToDouble() / 10}',
182181
),
183182
onChanged: (newRange) {
184183
setState(() {
@@ -192,8 +191,8 @@ class _CustomCarouselState extends State<CustomCarouselMain> {
192191
max: 1,
193192
divisions: 20,
194193
labels: RangeLabels(
195-
_flipV.start.toStringAsFixed(1).toString(),
196-
_flipV.end.toStringAsFixed(1).toString(),
194+
'${(_flipV.start * 10).roundToDouble() / 10}',
195+
'${(_flipV.end * 10).roundToDouble() / 10}',
197196
),
198197
onChanged: (newRange) {
199198
setState(() {
@@ -241,8 +240,8 @@ class _CustomCarouselState extends State<CustomCarouselMain> {
241240
max: 1,
242241
divisions: 20,
243242
labels: RangeLabels(
244-
_slideX.start.toStringAsFixed(1).toString(),
245-
_slideX.end.toStringAsFixed(1).toString(),
243+
'${(_slideX.start * 10).roundToDouble() / 10}',
244+
'${(_slideX.end * 10).roundToDouble() / 10}',
246245
),
247246
onChanged: (newRange) {
248247
setState(() {
@@ -256,8 +255,8 @@ class _CustomCarouselState extends State<CustomCarouselMain> {
256255
max: 5,
257256
divisions: 50,
258257
labels: RangeLabels(
259-
_slideY.start.toStringAsFixed(1).toString(),
260-
_slideY.end.toStringAsFixed(1).toString(),
258+
'${(_slideY.start * 10).roundToDouble() / 10}',
259+
'${(_slideY.end * 10).roundToDouble() / 10}',
261260
),
262261
onChanged: (newRange) {
263262
setState(() {

lib/packages/url_launcher/url_launcher_main.dart

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -250,20 +250,20 @@ class _UrlLauncherState extends State<UrlLauncher> {
250250
}
251251

252252
void _launchUrl(String url) async {
253-
if (await canLaunch(url)) {
253+
if (await canLaunchUrl(Uri.parse(url))) {
254254
if (!_isWebUrl)
255-
launch(url);
255+
launchUrl(Uri.parse(url));
256256
else
257-
launch(
258-
url,
259-
forceSafariVC: _forceSafarieVC,
260-
forceWebView: _forceWebView,
261-
enableJavaScript: _javaScriptEnabled,
262-
enableDomStorage: _enableDomStorage,
263-
universalLinksOnly: _universalLinksOnly,
257+
launchUrl(
258+
Uri.parse(url),
259+
// forceSafariVC: _forceSafarieVC,
260+
// forceWebView: _forceWebView,
261+
// enableJavaScript: _javaScriptEnabled,
262+
// enableDomStorage: _enableDomStorage,
263+
// universalLinksOnly: _universalLinksOnly,
264264
webOnlyWindowName: _webOnlyWindowName ? '_self' : '_blank',
265-
statusBarBrightness: _statusBarBrigthness ? Brightness.dark : Brightness.light,
266-
headers: (_sendHeaderInfos) ? _headers : {}
265+
// statusBarBrightness: _statusBarBrigthness ? Brightness.dark : Brightness.light,
266+
// headers: (_sendHeaderInfos) ? _headers : {}
267267
);
268268
} else {
269269
throw 'Could not launch $url';

lib/service/MyTheme.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ class MyTheme {
1717
static TextStyle _blackTextStyle = TextStyle(color: Colors.black);
1818
static TextStyle _black54TextStyle = TextStyle(color: Colors.black54);
1919
static TextStyle _black87TextStyle = TextStyle(color: Colors.black87);
20+
static TextStyle _whiteTextStyle = TextStyle(color: Colors.white);
21+
static TextStyle _white54TextStyle = TextStyle(color: Colors.white54);
22+
static TextStyle _white70TextStyle = TextStyle(color: Colors.white70);
2023

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

3942
static final darkTheme = ThemeData.dark().copyWith(
4043
primaryColor: _mainColor,
44+
textTheme: TextTheme(
45+
displayLarge: _whiteTextStyle,
46+
displayMedium: _whiteTextStyle,
47+
displaySmall: _whiteTextStyle,
48+
headlineMedium: _whiteTextStyle,
49+
headlineSmall: _whiteTextStyle,
50+
titleLarge: _whiteTextStyle,
51+
bodyLarge: _white54TextStyle,
52+
bodyMedium: _white54TextStyle,
53+
titleMedium: _white70TextStyle,
54+
titleSmall: _white70TextStyle,
55+
),
4156
appBarTheme: _appBarTheme,
4257
colorScheme: ColorScheme.fromSwatch().copyWith(secondary: _secondaryColor),
4358
);

test/widget_test.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
// gestures. You can also use WidgetTester to find child widgets in the widget
66
// tree, read text, and verify that the values of widget properties are correct.
77

8-
import 'package:flutter/material.dart';
98
import 'package:flutter_test/flutter_test.dart';
109

1110

0 commit comments

Comments
 (0)