Skip to content

Clean up public API #16

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

Merged
merged 1 commit into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
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
15 changes: 9 additions & 6 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'dart:convert';
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:path_provider/path_provider.dart';
// Imports needed for tor usage:
import 'package:socks5_proxy/socks_client.dart'; // Just for example; can use any socks5 proxy package, pick your favorite.
import 'package:tor_ffi_plugin/tor_ffi_plugin.dart';
Expand Down Expand Up @@ -33,19 +34,21 @@ class Home extends StatefulWidget {

class _MyAppState extends State<Home> {
// Flag to track if tor has started.
bool torStarted = false;
bool torIsRunning = false;

// Set the default text for the host input field.
final hostController = TextEditingController(text: 'https://icanhazip.com/');
// https://check.torproject.org is another good option.

Future<void> startTor() async {
// Start the Tor daemon.
await Tor.instance.start();
await Tor.instance.start(
torDataDirPath: (await getApplicationSupportDirectory()).path,
);

// Toggle started flag.
setState(() {
torStarted = Tor.instance.started; // Update flag
torIsRunning = Tor.instance.status == TorStatus.on; // Update flag
});

print('Done awaiting; tor should be running');
Expand All @@ -71,7 +74,7 @@ class _MyAppState extends State<Home> {
child: Column(
children: [
TextButton(
onPressed: torStarted
onPressed: torIsRunning
? null
: () async {
unawaited(
Expand Down Expand Up @@ -117,7 +120,7 @@ class _MyAppState extends State<Home> {
),
spacerSmall,
TextButton(
onPressed: torStarted
onPressed: torIsRunning
? () async {
// `socks5_proxy` package example, use another socks5
// connection of your choice.
Expand Down Expand Up @@ -158,7 +161,7 @@ class _MyAppState extends State<Home> {
),
spacerSmall,
TextButton(
onPressed: torStarted
onPressed: torIsRunning
? () async {
// Instantiate a socks socket at localhost and on the port selected by the tor service.
var socksSocket = await SOCKSSocket.create(
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ packages:
source: hosted
version: "1.8.3"
path_provider:
dependency: transitive
dependency: "direct main"
description:
name: path_provider
sha256: a1aa8aaa2542a6bc57e381f132af822420216c80d4781f7aa085ca3229208aaa
Expand Down
1 change: 1 addition & 0 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ dependencies:
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^1.0.2
socks5_proxy: ^1.0.3+dev.3
path_provider: ^2.1.1

dev_dependencies:
flutter_test:
Expand Down
Loading