Skip to content

Commit

Permalink
update SelectionPage on example app
Browse files Browse the repository at this point in the history
  • Loading branch information
josxha committed Feb 6, 2024
1 parent f51c7b3 commit c685c44
Show file tree
Hide file tree
Showing 8 changed files with 124 additions and 78 deletions.
87 changes: 60 additions & 27 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import 'dart:math';

import 'package:flutter/material.dart';
import 'package:flutter_map_plugins_example/flutter_map_cache/page.dart';
import 'package:flutter_map_plugins_example/flutter_map_pmtiles/page.dart';
import 'package:flutter_map_plugins_example/vector_map_tiles_pmtiles/page.dart';
import 'package:url_launcher/url_launcher_string.dart';
import 'package:url_strategy/url_strategy.dart';

void main() {
setPathUrlStrategy();
runApp(const MyApp());
}

Expand All @@ -17,7 +22,13 @@ class MyApp extends StatelessWidget {
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.white),
),
home: const Material(child: SelectionPage()),
initialRoute: '/',
routes: <String, WidgetBuilder>{
'/': (context) => const SelectionPage(),
'flutter_map_cache': (context) => const FlutterMapCachePage(),
'flutter_map_pmtiles': (context) => const FlutterMapPmTilesPage(),
'vector_map_tiles_pmtiles': (context) => VectorMapTilesPmTilesPage(),
},
);
}
}
Expand All @@ -27,67 +38,89 @@ class SelectionPage extends StatelessWidget {

@override
Widget build(BuildContext context) {
final children = [
const children = [
SelectionItemWidget(
title: 'flutter_map_cache',
desc: 'A slim yet powerful caching plugin for flutter_map '
'tile layers.',
pageBuilder: (context) => const FlutterMapCachePage(),
routeName: 'flutter_map_cache',
),
SelectionItemWidget(
title: 'flutter_map_pmtiles',
desc: 'PMTiles for flutter_map',
pageBuilder: (context) => const FlutterMapPmTilesPage(),
routeName: 'flutter_map_pmtiles',
),
SelectionItemWidget(
title: 'vector_map_tiles_pmtiles',
desc: 'PMTiles for vector_map_files / flutter_map',
pageBuilder: (context) => VectorMapTilesPmTilesPage(),
routeName: 'vector_map_tiles_pmtiles',
),
];

final size = MediaQuery.sizeOf(context);

if (size.width > 900) {
return Padding(
padding: const EdgeInsets.all(8),
child: GridView.count(
crossAxisCount: 2,
childAspectRatio: 5,
children: children,
final width = MediaQuery.sizeOf(context).width;
final githubButton = width < 350
? IconButton(onPressed: _openGithub, icon: const Icon(Icons.link))
: TextButton(
onPressed: _openGithub,
child: const Text('Source Code'),
);
return Scaffold(
appBar: AppBar(
title: const Text('flutter_map_plugins'),
actions: [githubButton],
),
body: ColoredBox(
color: Colors.blueGrey.withOpacity(0.3),
child: Padding(
padding: const EdgeInsets.all(8),
child: GridView.count(
crossAxisCount: max(width ~/ 250, 1),
childAspectRatio: 2,
children: children,
),
),
);
}
return Padding(
padding: const EdgeInsets.all(8),
child: ListView(
children: children,
),
);
}

void _openGithub() => launchUrlString(
'https://github.com/josxha/flutter_map_plugins',
);
}

class SelectionItemWidget extends StatelessWidget {
static const _titleStyle = TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
);
final String title;
final String desc;
final WidgetBuilder pageBuilder;
final String routeName;

const SelectionItemWidget({
super.key,
required this.title,
required this.desc,
required this.pageBuilder,
required this.routeName,
});

@override
Widget build(BuildContext context) {
return Card(
color: Colors.white,
child: InkWell(
onTap: () =>
Navigator.of(context).push(MaterialPageRoute(builder: pageBuilder)),
child: ListTile(
title: Text(title),
subtitle: Text(desc),
onTap: () => Navigator.of(context).pushNamed(routeName),
child: Padding(
padding: const EdgeInsets.all(12),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(title, style: _titleStyle, textAlign: TextAlign.center),
const Spacer(),
Text(desc, textAlign: TextAlign.center),
const Spacer(),
],
),
),
),
);
Expand Down
4 changes: 4 additions & 0 deletions example/linux/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@
#include "generated_plugin_registrant.h"

#include <sqlite3_flutter_libs/sqlite3_flutter_libs_plugin.h>
#include <url_launcher_linux/url_launcher_plugin.h>

void fl_register_plugins(FlPluginRegistry* registry) {
g_autoptr(FlPluginRegistrar) sqlite3_flutter_libs_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "Sqlite3FlutterLibsPlugin");
sqlite3_flutter_libs_plugin_register_with_registrar(sqlite3_flutter_libs_registrar);
g_autoptr(FlPluginRegistrar) url_launcher_linux_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "UrlLauncherPlugin");
url_launcher_plugin_register_with_registrar(url_launcher_linux_registrar);
}
1 change: 1 addition & 0 deletions example/linux/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

list(APPEND FLUTTER_PLUGIN_LIST
sqlite3_flutter_libs
url_launcher_linux
)

list(APPEND FLUTTER_FFI_PLUGIN_LIST
Expand Down
2 changes: 2 additions & 0 deletions example/macos/Flutter/GeneratedPluginRegistrant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ import Foundation
import connectivity_plus
import path_provider_foundation
import sqlite3_flutter_libs
import url_launcher_macos

func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
ConnectivityPlugin.register(with: registry.registrar(forPlugin: "ConnectivityPlugin"))
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
Sqlite3FlutterLibsPlugin.register(with: registry.registrar(forPlugin: "Sqlite3FlutterLibsPlugin"))
UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin"))
}
2 changes: 2 additions & 0 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ dependencies:
# commom packages
flutter_map: ^6.0.0
latlong2: ^0.9.0
url_launcher: ^6.2.4
url_strategy: ^0.2.0

# flutter_map_cache specific packages
flutter_map_cache:
Expand Down
102 changes: 51 additions & 51 deletions example/web/index.html
Original file line number Diff line number Diff line change
@@ -1,59 +1,59 @@
<!DOCTYPE html>
<html>
<head>
<!--
If you are serving your web app in a path other than the root, change the
href value below to reflect the base path you are serving from.
The path provided below has to start and end with a slash "/" in order for
it to work correctly.
For more details:
* https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base
This is a placeholder for base href that will be replaced by the value of
the `--base-href` argument provided to `flutter build`.
-->
<base href="$FLUTTER_BASE_HREF">

<meta charset="UTF-8">
<meta content="IE=Edge" http-equiv="X-UA-Compatible">
<meta name="description" content="A new Flutter project.">

<!-- iOS meta tags & icons -->
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="apple-mobile-web-app-title" content="example">
<link rel="apple-touch-icon" href="icons/Icon-192.png">

<!-- Favicon -->
<link rel="icon" type="image/png" href="favicon.png"/>

<title>example</title>
<link rel="manifest" href="manifest.json">

<script>
// The value below is injected by flutter build, do not touch.
const serviceWorkerVersion = null;
</script>
<!-- This script adds the flutter initialization JS code -->
<script src="flutter.js" defer></script>
<!--
If you are serving your web app in a path other than the root, change the
href value below to reflect the base path you are serving from.
The path provided below has to start and end with a slash "/" in order for
it to work correctly.
For more details:
* https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base
This is a placeholder for base href that will be replaced by the value of
the `--base-href` argument provided to `flutter build`.
-->
<base href="/">

<meta charset="UTF-8">
<meta content="IE=Edge" http-equiv="X-UA-Compatible">
<meta content="A new Flutter project." name="description">

<!-- iOS meta tags & icons -->
<meta content="yes" name="apple-mobile-web-app-capable">
<meta content="black" name="apple-mobile-web-app-status-bar-style">
<meta content="example" name="apple-mobile-web-app-title">
<link href="icons/Icon-192.png" rel="apple-touch-icon">

<!-- Favicon -->
<link href="favicon.png" rel="icon" type="image/png"/>

<title>example</title>
<link href="manifest.json" rel="manifest">

<script>
// The value below is injected by flutter build, do not touch.
const serviceWorkerVersion = null;
</script>
<!-- This script adds the flutter initialization JS code -->
<script defer src="flutter.js"></script>
</head>
<body>
<script>
window.addEventListener('load', function(ev) {
// Download page.dart.js
_flutter.loader.loadEntrypoint({
serviceWorker: {
serviceWorkerVersion: serviceWorkerVersion,
},
onEntrypointLoaded: function(engineInitializer) {
engineInitializer.initializeEngine().then(function(appRunner) {
appRunner.runApp();
});
}
});
<script>
window.addEventListener('load', function (ev) {
// Download page.dart.js
_flutter.loader.loadEntrypoint({
serviceWorker: {
serviceWorkerVersion: serviceWorkerVersion,
},
onEntrypointLoaded: function (engineInitializer) {
engineInitializer.initializeEngine().then(function (appRunner) {
appRunner.runApp();
});
}
});
});
</script>
</script>
</body>
</html>
3 changes: 3 additions & 0 deletions example/windows/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@

#include <connectivity_plus/connectivity_plus_windows_plugin.h>
#include <sqlite3_flutter_libs/sqlite3_flutter_libs_plugin.h>
#include <url_launcher_windows/url_launcher_windows.h>

void RegisterPlugins(flutter::PluginRegistry* registry) {
ConnectivityPlusWindowsPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("ConnectivityPlusWindowsPlugin"));
Sqlite3FlutterLibsPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("Sqlite3FlutterLibsPlugin"));
UrlLauncherWindowsRegisterWithRegistrar(
registry->GetRegistrarForPlugin("UrlLauncherWindows"));
}
1 change: 1 addition & 0 deletions example/windows/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
list(APPEND FLUTTER_PLUGIN_LIST
connectivity_plus
sqlite3_flutter_libs
url_launcher_windows
)

list(APPEND FLUTTER_FFI_PLUGIN_LIST
Expand Down

0 comments on commit c685c44

Please sign in to comment.