mirror of
https://github.com/Iconica-Development/flutter_google_track_and_trace.git
synced 2025-05-19 05:03:45 +02:00
add controller template
This commit is contained in:
parent
124ab33217
commit
65262045f8
9 changed files with 134 additions and 15 deletions
|
@ -1 +1,2 @@
|
||||||
|
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"
|
||||||
#include "Generated.xcconfig"
|
#include "Generated.xcconfig"
|
||||||
|
|
|
@ -1 +1,2 @@
|
||||||
|
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"
|
||||||
#include "Generated.xcconfig"
|
#include "Generated.xcconfig"
|
||||||
|
|
41
example/ios/Podfile
Normal file
41
example/ios/Podfile
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
# 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'
|
||||||
|
|
||||||
|
project 'Runner', {
|
||||||
|
'Debug' => :debug,
|
||||||
|
'Profile' => :release,
|
||||||
|
'Release' => :release,
|
||||||
|
}
|
||||||
|
|
||||||
|
def flutter_root
|
||||||
|
generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__)
|
||||||
|
unless File.exist?(generated_xcode_build_settings_path)
|
||||||
|
raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first"
|
||||||
|
end
|
||||||
|
|
||||||
|
File.foreach(generated_xcode_build_settings_path) do |line|
|
||||||
|
matches = line.match(/FLUTTER_ROOT\=(.*)/)
|
||||||
|
return matches[1].strip if matches
|
||||||
|
end
|
||||||
|
raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get"
|
||||||
|
end
|
||||||
|
|
||||||
|
require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root)
|
||||||
|
|
||||||
|
flutter_ios_podfile_setup
|
||||||
|
|
||||||
|
target 'Runner' do
|
||||||
|
use_frameworks!
|
||||||
|
use_modular_headers!
|
||||||
|
|
||||||
|
flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
|
||||||
|
end
|
||||||
|
|
||||||
|
post_install do |installer|
|
||||||
|
installer.pods_project.targets.each do |target|
|
||||||
|
flutter_additional_ios_build_settings(target)
|
||||||
|
end
|
||||||
|
end
|
78
example/lib/controlled.dart
Normal file
78
example/lib/controlled.dart
Normal file
|
@ -0,0 +1,78 @@
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
main() {
|
||||||
|
runApp(MaterialApp(
|
||||||
|
home: Scaffold(
|
||||||
|
body: Center(
|
||||||
|
child: ControlledWidget(
|
||||||
|
initialString: 'old value',
|
||||||
|
onCreate: (controller) async {
|
||||||
|
Future.delayed(const Duration(seconds: 5), () {
|
||||||
|
controller.value = 'new value';
|
||||||
|
});
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
enum TimePrecision {
|
||||||
|
updateOnly,
|
||||||
|
everySecond,
|
||||||
|
everyMinute
|
||||||
|
}
|
||||||
|
|
||||||
|
class ControlledWidget extends StatefulWidget {
|
||||||
|
final void Function(MyController) onCreate;
|
||||||
|
final String? initialString;
|
||||||
|
final TimePrecision precision;
|
||||||
|
const ControlledWidget({
|
||||||
|
Key? key,
|
||||||
|
required this.onCreate,
|
||||||
|
this.initialString,
|
||||||
|
this.precision = TimePrecision.updateOnly,
|
||||||
|
}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
_ControlledWidgetState createState() => _ControlledWidgetState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _ControlledWidgetState extends State<ControlledWidget> {
|
||||||
|
late final MyController _controller;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
_controller = MyController(widget.initialString ?? '');
|
||||||
|
_controller.addListener(_onChange);
|
||||||
|
widget.onCreate(_controller);
|
||||||
|
super.initState();
|
||||||
|
}
|
||||||
|
|
||||||
|
void _onChange() {
|
||||||
|
setState(() {});
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Text(_controller.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
_controller.dispose();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class MyController extends ChangeNotifier {
|
||||||
|
String _currentString;
|
||||||
|
|
||||||
|
MyController(String initial) : _currentString = initial;
|
||||||
|
|
||||||
|
String get value => _currentString;
|
||||||
|
|
||||||
|
set value(String value) {
|
||||||
|
_currentString = value;
|
||||||
|
notifyListeners();
|
||||||
|
}
|
||||||
|
}
|
|
@ -3,6 +3,8 @@ import 'package:google_maps_flutter/google_maps_flutter.dart';
|
||||||
import 'package:google_track_trace/google_track_trace.dart';
|
import 'package:google_track_trace/google_track_trace.dart';
|
||||||
|
|
||||||
class TrackTraceDemo extends StatefulWidget {
|
class TrackTraceDemo extends StatefulWidget {
|
||||||
|
const TrackTraceDemo({Key? key}) : super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<TrackTraceDemo> createState() => _TrackTraceDemoState();
|
State<TrackTraceDemo> createState() => _TrackTraceDemoState();
|
||||||
}
|
}
|
||||||
|
@ -22,7 +24,7 @@ class _TrackTraceDemoState extends State<TrackTraceDemo> {
|
||||||
markerId: MarkerId('Eind locatie'),
|
markerId: MarkerId('Eind locatie'),
|
||||||
position: LatLng(51.958996, 6.296520),
|
position: LatLng(51.958996, 6.296520),
|
||||||
),
|
),
|
||||||
travelMode: TravelMode.Bicycling,
|
travelMode: TravelMode.bicycling,
|
||||||
onMapCreated: (ctr) => {controller = ctr},
|
onMapCreated: (ctr) => {controller = ctr},
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
@ -30,6 +32,6 @@ class _TrackTraceDemoState extends State<TrackTraceDemo> {
|
||||||
}
|
}
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
runApp(MaterialApp(home: TrackTraceDemo(
|
runApp(const MaterialApp(home: TrackTraceDemo(
|
||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,13 +7,13 @@
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
|
||||||
import 'package:tracktrace_example/main.dart';
|
import 'package:tracktrace_example/main.dart';
|
||||||
|
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
|
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
|
||||||
// Build our app and trigger a frame.
|
// Build our app and trigger a frame.
|
||||||
await tester.pumpWidget(const MyApp());
|
await tester.pumpWidget(const TrackTraceDemo());
|
||||||
|
|
||||||
// Verify that our counter starts at 0.
|
// Verify that our counter starts at 0.
|
||||||
expect(find.text('0'), findsOneWidget);
|
expect(find.text('0'), findsOneWidget);
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
part of google_track_trace;
|
part of google_track_trace;
|
||||||
|
|
||||||
enum TravelMode { Driving, Walking, Bicycling, Transit }
|
enum TravelMode { driving, walking, bicycling, transit }
|
||||||
|
|
||||||
class DirectionsRepository {
|
class DirectionsRepository {
|
||||||
static const String _baseUrl = '/maps/api/directions/json';
|
static const String _baseUrl = '/maps/api/directions/json';
|
||||||
|
@ -19,10 +19,10 @@ class DirectionsRepository {
|
||||||
'key':
|
'key':
|
||||||
key, // get this key from the controller
|
key, // get this key from the controller
|
||||||
'mode': <TravelMode, String>{
|
'mode': <TravelMode, String>{
|
||||||
TravelMode.Driving: 'driving',
|
TravelMode.driving: 'driving',
|
||||||
TravelMode.Bicycling: 'bicycling',
|
TravelMode.bicycling: 'bicycling',
|
||||||
TravelMode.Transit: 'transit',
|
TravelMode.transit: 'transit',
|
||||||
TravelMode.Walking: 'walking',
|
TravelMode.walking: 'walking',
|
||||||
}[mode],
|
}[mode],
|
||||||
};
|
};
|
||||||
final uri = Uri.https('maps.googleapis.com', _baseUrl, queryParameters);
|
final uri = Uri.https('maps.googleapis.com', _baseUrl, queryParameters);
|
||||||
|
|
|
@ -12,7 +12,7 @@ class GoogleTrackTraceMap extends StatefulWidget {
|
||||||
required this.startPosition,
|
required this.startPosition,
|
||||||
required this.destinationPosition,
|
required this.destinationPosition,
|
||||||
this.currentPosition,
|
this.currentPosition,
|
||||||
this.travelMode = TravelMode.Driving,
|
this.travelMode = TravelMode.driving,
|
||||||
}) : assert(true),
|
}) : assert(true),
|
||||||
super(key: key);
|
super(key: key);
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,8 @@
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
|
||||||
import 'package:google_track_trace/google_track_trace.dart';
|
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
test('adds one to input values', () {
|
test('adds one to input values', () {
|
||||||
final calculator = Calculator();
|
|
||||||
expect(calculator.addOne(2), 3);
|
|
||||||
expect(calculator.addOne(-7), -6);
|
|
||||||
expect(calculator.addOne(0), 1);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue