Skip to content
Permalink
Browse files

updated flutter SDK; adapted to dart2; cleanup; using fluro for routing

  • Loading branch information...
namiwang committed Sep 4, 2018
1 parent 58592fe commit 51e61b6a78baacc7a9ac43d285bab4de00266564
@@ -1 +1,2 @@
#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"
#include "Generated.xcconfig"
@@ -1 +1,2 @@
#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"
#include "Generated.xcconfig"
@@ -0,0 +1,65 @@
# Uncomment this line to define a global platform for your project
# platform :ios, '9.0'

# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'

def parse_KV_file(file, separator='=')
file_abs_path = File.expand_path(file)
if !File.exists? file_abs_path
return [];
end
pods_ary = []
skip_line_start_symbols = ["#", "/"]
File.foreach(file_abs_path) { |line|
next if skip_line_start_symbols.any? { |symbol| line =~ /^\s*#{symbol}/ }
plugin = line.split(pattern=separator)
if plugin.length == 2
podname = plugin[0].strip()
path = plugin[1].strip()
podpath = File.expand_path("#{path}", file_abs_path)
pods_ary.push({:name => podname, :path => podpath});
else
puts "Invalid plugin specification: #{line}"
end
}
return pods_ary
end

target 'Runner' do
use_frameworks!

# Prepare symlinks folder. We use symlinks to avoid having Podfile.lock
# referring to absolute paths on developers' machines.
system('rm -rf .symlinks')
system('mkdir -p .symlinks/plugins')

# Flutter Pods
generated_xcode_build_settings = parse_KV_file('./Flutter/Generated.xcconfig')
if generated_xcode_build_settings.empty?
puts "Generated.xcconfig must exist. If you're running pod install manually, make sure flutter packages get is executed first."
end
generated_xcode_build_settings.map { |p|
if p[:name] == 'FLUTTER_FRAMEWORK_DIR'
symlink = File.join('.symlinks', 'flutter')
File.symlink(File.dirname(p[:path]), symlink)
pod 'Flutter', :path => File.join(symlink, File.basename(p[:path]))
end
}

# Plugin Pods
plugin_pods = parse_KV_file('../.flutter-plugins')
plugin_pods.map { |p|
symlink = File.join('.symlinks', 'plugins', p[:name])
File.symlink(p[:path], symlink)
pod p[:name], :path => File.join(symlink, 'ios')
}
end

post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['ENABLE_BITCODE'] = 'NO'
end
end
end
@@ -0,0 +1,16 @@
import 'package:fluro/fluro.dart';

import './routes.dart';

class Application {
static Router router;

static initApp() {
_initRouter();
}

static _initRouter() {
router = new Router();
Routes.configureRoutes(router);
}
}
@@ -0,0 +1,19 @@
import 'package:fluro/fluro.dart';
import 'package:flutter/material.dart';

import '../views/entries/show.dart';

class Routes {
static void configureRoutes(Router router) {
router.notFoundHandler = new Handler(handlerFunc: (BuildContext context, Map<String, List<String>> params) {
// TODO handle error via sentry
throw "ROUTE NOT FOUND";
});

router.define("/entries/:title", handler: new Handler(handlerFunc: (BuildContext context, Map<String, dynamic> params) {
final title = params['title'][0];
return new EntriesShow(title: title);
}));

}
}
@@ -1,13 +1,16 @@
import 'package:flutter/material.dart';

import './config/application.dart';

import './views/pages/home.dart';
import './views/entries/show.dart';

void main() {
runApp(new WikiFlutterApp());
Application.initApp();

runApp(new App());
}

class WikiFlutterApp extends StatelessWidget {
class App extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new Banner(
@@ -20,30 +23,10 @@ class WikiFlutterApp extends StatelessWidget {
theme: new ThemeData(
primarySwatch: Colors.blueGrey,
),
routes: <String, WidgetBuilder>{
'/': (BuildContext context) => new PagesHome(),
},
onGenerateRoute: _handleRoute,
home: new PagesHome(),
onGenerateRoute: Application.router.generator,
)
);
}

Route<Null> _handleRoute(RouteSettings settings) {
print('--- handling route: ' + settings.toString());

final List<String> path = settings.name.split('/');

// /entries/:title
if ( path.length == 3 && path[0] == '' && path[1] == 'entries' ) {
final String title = path[2];

return new MaterialPageRoute<Null>(
settings: settings,
builder: (BuildContext context) => new EntriesShow(title: title)
);
}

return null;
}

}
@@ -41,12 +41,13 @@ class Entry {
}

static List<String> _extractHatnotes(Map map) {
// \"EU\" redirects here. For other uses, see <a href=\"/wiki/EU_(disambiguation)\" title=\"EU (disambiguation)\">EU (disambiguation)</a>.
return ( map['lead']['hatnotes'] ?? [] ) as List;
if ( map['lead']['hatnotes'] == null ) { return []; }

return ( map['lead']['hatnotes'] as List ).map((h){ return h as String; }).toList();
}

static List<Section> _extractSections(Map map){
return ( map['lead']['sections'] as List ).map((Map section){
return ( map['lead']['sections'] as List ).cast<Map>().map((Map section){
final int id = section['id'];
final int tocLevel = id == 0 ? 0 : section['toclevel'];
final String title = id == 0 ? null : inlineHtmlWrap(section['line']);
@@ -5,17 +5,17 @@ import 'package:http/http.dart' as http;

import '../models/entry.dart';

abstract class Classic {
static Future<List<String>> getRandomEntriesTitles([int amount = 10]) async {
final String url = "https://en.wikipedia.org/w/api.php?action=query&format=json&list=random&rnnamespace=0&rnlimit=$amount";
final Map map = JSON.decode(await http.read(url));
return (map['query']['random'] as List).map((Map map) => map['title'] ).toList();
}
}
// abstract class Classic {
// static Future<List<String>> getRandomEntriesTitles([int amount = 10]) async {
// final String url = "https://en.wikipedia.org/w/api.php?action=query&format=json&list=random&rnnamespace=0&rnlimit=$amount";
// final Map map = json.decode(await http.read(url));
// return (map['query']['random'] as List).map((Map map) => map['title'] ).toList();
// }
// }

abstract class Restful {
static Future<Entry> getEntry(String title) async {
final url = "https://en.wikipedia.org/api/rest_v1/page/mobile-sections/${title}";
return new Entry(JSON.decode(await http.read(url)));
return new Entry(json.decode(await http.read(url)));
}
}
@@ -19,7 +19,6 @@ class _PagesHomeState extends State<PagesHome> {

@override
Widget build(BuildContext context) {
print('************ REBUILDING PagesHome');
return new Scaffold(
body: new CustomScrollView(
slivers: <Widget>[
@@ -149,11 +148,7 @@ class _Fetcher {

final String url = "https://en.wikipedia.org/w/api.php?action=opensearch&format=json&errorformat=bc&search=$str&namespace=0&limit=10&suggest=1&utf8=1&formatversion=2";

print('UUU fetching $str');

final List fetched = JSON.decode( await client.read(url) ) as List;

print('UUU fetched');
final List fetched = json.decode( await client.read(url) ) as List;

client.close();

@@ -19,7 +19,7 @@ class HtmlParser {
List<TextSpan> _currentTextSpans = [];

Widget parseFromElement (html.Element element) {
print('*** parsing html...');
// print('*** parsing html...');

_parseNode(element);
_tryCloseCurrentTextSpan();
@@ -28,7 +28,7 @@ class HtmlParser {
}

Widget parseFromStr (String htmlStr) {
print('*** parsing html...');
// print('*** parsing html...');

final html.Node body = html.parse(htmlStr).body;

@@ -192,7 +192,7 @@ class HtmlParser {

return;
default:
print('=== MET UNSUPPORTED TAG: ${element.localName}');
// print('=== MET UNSUPPORTED TAG: ${element.localName}');

// still traverse down the tree
for (var subNode in element.nodes) { _parseNode(subNode); }
@@ -18,7 +18,7 @@ class HtmlWrap extends StatelessWidget {
// this is a quick, yet not elegant way to parse inline html
// it just remove all expecting tags and return a string
String inlineHtmlWrap(String htmlStr) {
print('*** parsing inline html...');
// print('*** parsing inline html...');

return htmlStr.replaceAll(new RegExp("<\/*(i|b|span)>"), '');
}
@@ -7,12 +7,13 @@ dependencies:
html: any
image: any
url_launcher: any
# flutter_animated: any

# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.0

fluro: any

dev_dependencies:
flutter_test:
sdk: flutter
@@ -1,29 +1,29 @@
// This is a basic Flutter widget test.
// To perform an interaction with a widget in your test, use the WidgetTester utility that Flutter
// provides. For example, you can send tap and scroll 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.
// // This is a basic Flutter widget test.
// // To perform an interaction with a widget in your test, use the WidgetTester utility that Flutter
// // provides. For example, you can send tap and scroll 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';
// import 'package:flutter/material.dart';
// import 'package:flutter_test/flutter_test.dart';

import 'package:wiki_flutter/main.dart';
// import 'package:wiki_flutter/main.dart';

void main() {
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
// Build our app and trigger a frame.
await tester.pumpWidget(new MyApp());
// void main() {
// testWidgets('Counter increments smoke test', (WidgetTester tester) async {
// // Build our app and trigger a frame.
// await tester.pumpWidget(new MyApp());

// Verify that our counter starts at 0.
expect(find.text('0'), findsOneWidget);
expect(find.text('1'), findsNothing);
// // Verify that our counter starts at 0.
// expect(find.text('0'), findsOneWidget);
// expect(find.text('1'), findsNothing);

// Tap the '+' icon and trigger a frame.
await tester.tap(find.byIcon(Icons.add));
await tester.pump();
// // Tap the '+' icon and trigger a frame.
// await tester.tap(find.byIcon(Icons.add));
// await tester.pump();

// Verify that our counter has incremented.
expect(find.text('0'), findsNothing);
expect(find.text('1'), findsOneWidget);
});
}
// // Verify that our counter has incremented.
// expect(find.text('0'), findsNothing);
// expect(find.text('1'), findsOneWidget);
// });
// }

0 comments on commit 51e61b6

Please sign in to comment.
You can’t perform that action at this time.