Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvement/fl chart app #1488

Merged
merged 5 commits into from
Nov 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions .github/workflows/gh-pages.yml
Original file line number Diff line number Diff line change
@@ -9,8 +9,16 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4 # Only works with v2
- uses: subosito/flutter-action@v2
- uses: actions/checkout@v4
- name: Install Flutter
uses: subosito/flutter-action@v2

- name: Set fl_chart Version
run: |
VERSION=$(grep "version:" fl_chart.yaml | awk '{ print $2 }')
echo "USING_FL_CHART_VERSION=$VERSION" >> $GITHUB_ENV
- uses: bluefireteam/flutter-gh-pages@v8
with:
workingDir: example
workingDir: example
customArgs: --dart-define="USING_FL_CHART_VERSION=${{ env.USING_FL_CHART_VERSION }}"
27 changes: 27 additions & 0 deletions example/lib/cubits/app/app_cubit.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:package_info_plus/package_info_plus.dart';
import 'package:equatable/equatable.dart';

part 'app_state.dart';

class AppCubit extends Cubit<AppState> {
AppCubit() : super(const AppState()) {
initialize();
}

void initialize() async {
PackageInfo packageInfo = await PackageInfo.fromPlatform();
emit(state.copyWith(
currentPackageInfo: packageInfo,
availableVersionToUpdate: '',
usingFlChartVersion: BuildConstants.usingFlChartVersion,
));
}
}

class BuildConstants {
static const String usingFlChartVersion = String.fromEnvironment(
'USING_FL_CHART_VERSION',
defaultValue: '',
);
}
34 changes: 34 additions & 0 deletions example/lib/cubits/app/app_state.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
part of 'app_cubit.dart';

class AppState extends Equatable {
final PackageInfo? currentPackageInfo;
final String availableVersionToUpdate;
final String usingFlChartVersion;

String? get appVersion => currentPackageInfo?.version;

const AppState([
this.currentPackageInfo,
this.availableVersionToUpdate = '',
this.usingFlChartVersion = '',
]);

AppState copyWith({
PackageInfo? currentPackageInfo,
String? availableVersionToUpdate,
String? usingFlChartVersion,
}) {
return AppState(
currentPackageInfo ?? this.currentPackageInfo,
availableVersionToUpdate ?? this.availableVersionToUpdate,
usingFlChartVersion ?? this.usingFlChartVersion,
);
}

@override
List<Object?> get props => [
currentPackageInfo,
availableVersionToUpdate,
usingFlChartVersion,
];
}
29 changes: 18 additions & 11 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import 'package:fl_chart_app/cubits/app/app_cubit.dart';
import 'package:fl_chart_app/presentation/resources/app_resources.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:google_fonts/google_fonts.dart';

import 'presentation/router/app_router.dart';
@@ -13,19 +15,24 @@ class MyApp extends StatelessWidget {

@override
Widget build(BuildContext context) {
return MaterialApp.router(
title: AppTexts.appName,
theme: ThemeData(
brightness: Brightness.dark,
useMaterial3: true,
textTheme: GoogleFonts.assistantTextTheme(
Theme.of(context).textTheme.apply(
bodyColor: AppColors.mainTextColor3,
),
return MultiBlocProvider(
providers: [
BlocProvider<AppCubit>(create: (BuildContext context) => AppCubit()),
],
child: MaterialApp.router(
title: AppTexts.appName,
theme: ThemeData(
brightness: Brightness.dark,
useMaterial3: true,
textTheme: GoogleFonts.assistantTextTheme(
Theme.of(context).textTheme.apply(
bodyColor: AppColors.mainTextColor3,
),
),
scaffoldBackgroundColor: AppColors.pageBackground,
),
scaffoldBackgroundColor: AppColors.pageBackground,
routerConfig: appRouterConfig,
),
routerConfig: appRouterConfig,
);
}
}
100 changes: 71 additions & 29 deletions example/lib/presentation/menu/app_menu.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import 'package:dartx/dartx.dart';
import 'package:fl_chart_app/cubits/app/app_cubit.dart';
import 'package:fl_chart_app/presentation/resources/app_resources.dart';
import 'package:fl_chart_app/urls.dart';
import 'package:fl_chart_app/util/app_helper.dart';
import 'package:fl_chart_app/util/app_utils.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:url_launcher/url_launcher.dart';

import 'fl_chart_banner.dart';
@@ -11,12 +15,14 @@ class AppMenu extends StatefulWidget {
final List<ChartMenuItem> menuItems;
final int currentSelectedIndex;
final Function(int, ChartMenuItem) onItemSelected;
final VoidCallback? onBannerClicked;

const AppMenu({
Key? key,
required this.menuItems,
required this.currentSelectedIndex,
required this.onItemSelected,
required this.onBannerClicked,
}) : super(key: key);

@override
@@ -26,7 +32,6 @@ class AppMenu extends StatefulWidget {
class AppMenuState extends State<AppMenu> {
@override
Widget build(BuildContext context) {
const needToUpdateTheApp = 1 == 0;
return Container(
color: AppColors.itemsBackground,
child: Column(
@@ -36,12 +41,7 @@ class AppMenuState extends State<AppMenu> {
aspectRatio: 3,
child: Center(
child: InkWell(
onTap: () async {
final url = Uri.parse(Urls.flChartUrl);
if (await canLaunchUrl(url)) {
await launchUrl(url);
}
},
onTap: widget.onBannerClicked,
child: const FlChartBanner(),
),
),
@@ -69,40 +69,82 @@ class AppMenuState extends State<AppMenu> {
itemCount: widget.menuItems.length,
),
),
if (needToUpdateTheApp)
Container(
margin: const EdgeInsets.all(12),
child: Row(
children: [
const Expanded(
child: Padding(
padding: EdgeInsets.all(10.0),
child: Text(
'FL Chart v 1.00 - update to get the latest features!',
style: TextStyle(
color: Colors.white,
fontSize: 12,
const _AppVersionRow(),
],
),
);
}
}

class _AppVersionRow extends StatelessWidget {
const _AppVersionRow();

@override
Widget build(BuildContext context) {
return BlocBuilder<AppCubit, AppState>(builder: (context, state) {
if (state.appVersion.isNullOrBlank) {
return Container();
}
return Container(
margin: const EdgeInsets.all(12),
child: Row(
children: [
Expanded(
child: Padding(
padding: const EdgeInsets.all(10.0),
child: RichText(
text: TextSpan(
text: '',
style: DefaultTextStyle.of(context).style,
children: <TextSpan>[
const TextSpan(text: 'App version: '),
TextSpan(
text: 'v${state.appVersion!}',
style: const TextStyle(
fontWeight: FontWeight.bold,
),
),
),
if (state.usingFlChartVersion.isNotBlank) ...[
const TextSpan(text: '\nfl_chart: '),
TextSpan(
text: 'v${state.usingFlChartVersion}',
style: const TextStyle(
fontWeight: FontWeight.bold,
),
),
]
],
),
TextButton(
),
),
),
state.availableVersionToUpdate.isNotBlank
? TextButton(
onPressed: () {},
child: Text(
'Update to ${state.availableVersionToUpdate}',
style: const TextStyle(
color: AppColors.primary,
fontSize: 12,
fontWeight: FontWeight.bold,
),
),
)
: TextButton(
onPressed: () => AppUtils().tryToLaunchUrl(Urls.aboutUrl),
child: const Text(
'Update',
'About',
style: TextStyle(
color: AppColors.primary,
fontSize: 12,
fontWeight: FontWeight.bold,
),
),
),
],
),
)
],
),
);
],
),
);
});
}
}

15 changes: 15 additions & 0 deletions example/lib/presentation/pages/home_page.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import 'package:dartx/dartx.dart';
import 'package:fl_chart_app/presentation/menu/app_menu.dart';
import 'package:fl_chart_app/presentation/resources/app_resources.dart';
import 'package:fl_chart_app/urls.dart';
import 'package:fl_chart_app/util/app_helper.dart';
import 'package:fl_chart_app/util/app_utils.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';

@@ -50,6 +53,18 @@ class HomePage extends StatelessWidget {
Navigator.of(context).pop();
}
},
onBannerClicked: kIsWeb || needsDrawer
? () async {
if (kIsWeb) {
await AppUtils().tryToLaunchUrl(Urls.flChartUrl);
return;
}
if (needsDrawer) {
Navigator.of(context).pop();
return;
}
}
: null,
);
final samplesSectionWidget =
ChartSamplesPage(chartType: showingChartType);
9 changes: 2 additions & 7 deletions example/lib/presentation/widgets/chart_holder.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:fl_chart_app/presentation/resources/app_resources.dart';
import 'package:fl_chart_app/presentation/samples/chart_sample.dart';
import 'package:fl_chart_app/util/app_utils.dart';
import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';

class ChartHolder extends StatelessWidget {
final ChartSample chartSample;
@@ -30,12 +30,7 @@ class ChartHolder extends StatelessWidget {
),
Expanded(child: Container()),
IconButton(
onPressed: () async {
final url = Uri.parse(chartSample.url);
if (await canLaunchUrl(url)) {
await launchUrl(url);
}
},
onPressed: () => AppUtils().tryToLaunchUrl(chartSample.url),
icon: const Icon(
Icons.code,
color: AppColors.primary,
2 changes: 2 additions & 0 deletions example/lib/urls.dart
Original file line number Diff line number Diff line change
@@ -11,4 +11,6 @@ class Urls {
final chartDir = chartType.name.toLowerCase();
return 'https://github.com/imaNNeo/fl_chart/blob/master/repo_files/documentations/${chartDir}_chart.md';
}

static String get aboutUrl => '$flChartUrl/about';
}
10 changes: 10 additions & 0 deletions example/lib/util/app_utils.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import 'dart:math' as math;

import 'package:url_launcher/url_launcher.dart';

class AppUtils {
factory AppUtils() {
return _singleton;
@@ -15,4 +17,12 @@ class AppUtils {
double radianToDegree(double radian) {
return radian * 180 / math.pi;
}

Future<bool> tryToLaunchUrl(String url) async {
final uri = Uri.parse(url);
if (await canLaunchUrl(uri)) {
return await launchUrl(uri);
}
return false;
}
}
2 changes: 2 additions & 0 deletions example/macos/Flutter/GeneratedPluginRegistrant.swift
Original file line number Diff line number Diff line change
@@ -5,10 +5,12 @@
import FlutterMacOS
import Foundation

import package_info_plus
import path_provider_foundation
import url_launcher_macos

func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
FPPPackageInfoPlusPlugin.register(with: registry.registrar(forPlugin: "FPPPackageInfoPlusPlugin"))
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin"))
}
6 changes: 6 additions & 0 deletions example/macos/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
PODS:
- FlutterMacOS (1.0.0)
- package_info_plus (0.0.1):
- FlutterMacOS
- path_provider_foundation (0.0.1):
- Flutter
- FlutterMacOS
@@ -8,19 +10,23 @@ PODS:

DEPENDENCIES:
- FlutterMacOS (from `Flutter/ephemeral`)
- package_info_plus (from `Flutter/ephemeral/.symlinks/plugins/package_info_plus/macos`)
- path_provider_foundation (from `Flutter/ephemeral/.symlinks/plugins/path_provider_foundation/darwin`)
- url_launcher_macos (from `Flutter/ephemeral/.symlinks/plugins/url_launcher_macos/macos`)

EXTERNAL SOURCES:
FlutterMacOS:
:path: Flutter/ephemeral
package_info_plus:
:path: Flutter/ephemeral/.symlinks/plugins/package_info_plus/macos
path_provider_foundation:
:path: Flutter/ephemeral/.symlinks/plugins/path_provider_foundation/darwin
url_launcher_macos:
:path: Flutter/ephemeral/.symlinks/plugins/url_launcher_macos/macos

SPEC CHECKSUMS:
FlutterMacOS: 8f6f14fa908a6fb3fba0cd85dbd81ec4b251fb24
package_info_plus: 02d7a575e80f194102bef286361c6c326e4c29ce
path_provider_foundation: 29f094ae23ebbca9d3d0cec13889cd9060c0e943
url_launcher_macos: d2691c7dd33ed713bf3544850a623080ec693d95

3 changes: 3 additions & 0 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -20,6 +20,9 @@ dependencies:
dartx: ^1.2.0
fl_chart:
path: ../
flutter_bloc: ^8.1.3
package_info_plus: ^4.2.0
equatable: ^2.0.5

dev_dependencies:
flutter_test: