我刚刚安装了Snapcraft,然后使用它来安装Ngrok,但是不幸的是,我仍然无法从终端运行Ngrox。
我的Ngrok安装
╭─yoesoff@yoesoff-ThinkPad-X220 ~/Documents/labs/hello-world ‹master›
╰─➤ sudo snap install ngrok 1 ↵
ngrok 2.3.27 from Khiem Doan (khiemdoan) installed
Ngrk现在已列出
╭─yoesoff@yoesoff-ThinkPad-X220 ~/Documents/labs/hello-world ‹master›
╰─➤ snap list 127 ↵
Name Version Rev Tracking Publisher Notes
core 16-2.39 6964 stable canonical✓ core
ngrok 2.3.27 13 stable khiemdoan -
但是它不起作用
╭─yoesoff@yoesoff-ThinkPad-X220 ~
╰─➤ ngrok
zsh: command not found: ngrok
我的问题是如何运行使用snapcraft安装的应用程序?
谢谢
答案 0 :(得分:1)
您可以使用import 'package:flutter/material.dart';
import 'package:http/http.dart' show get;
import 'dart:convert';
class Post {
String name;
String msg;
String day;
String date;
Post({this.name, this.msg, this.day, this.date});
factory Post.fromJson(Map<String, dynamic> json) {
return Post(
name: json['name'].toString(),
msg: json['msg'].toString(),
day: json['day'].toString(),
date: json['date'].toString(),
);
}
}
class CustomListView extends StatelessWidget {
List teachers = [];
CustomListView(this.teachers);
@override
Widget build(BuildContext context) {
return (
ListView.builder(
itemCount: teachers.length,
itemBuilder: (BuildContext context, int index) {
return createviewItem(teachers[index], context);
},
)
);
}
Widget createviewItem(Post teachers, BuildContext context) {
return ListTile(
title: new Card(
child: new Container(
decoration: BoxDecoration(border: Border.all(color: Colors.lightBlue)),
padding: EdgeInsets.all(20.0),
margin: EdgeInsets.all(20.0),
child: Column(children: <Widget>[
new Text(teachers.name),
new Text(teachers.msg),
new Text(teachers.day),
new Text(teachers.date)
],),
)
)
);
}
}
Future<List<Post>> downloadJSON() async {
final jsonEndpoint = "http://www.alkadhum-col.edu.iq/Teachers%20Activities/get.php";
final response = await get(jsonEndpoint);
if (response.statusCode == 200) {
List teachers = json.decode(response.body);
return teachers.map(
(teacher) => new Post.fromJson(teacher)
).toList();
}
else {
throw Exception("Unable to get JSON data");
}
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
theme: new ThemeData(
primarySwatch: Colors.deepOrange,
),
home: new Scaffold(
appBar: new AppBar(title: const Text('Flutter and PHP')),
body: new Center(
child: new FutureBuilder<List<Post>>(
future: downloadJSON(),
builder: (context, snapshot) {
if (snapshot.hasData) {
List<Post> teachers = snapshot.data;
return new CustomListView(teachers);
} else if (snapshot.hasError) {
return Text('${snapshot.error}');
}
//return a circular progress indicator.
return new CircularProgressIndicator();
},
),
),
),
);
}
}
void main() {
runApp(MyApp());
}
运行该应用程序(请参阅snap run application
)。
如果希望应用程序显示在桌面应用程序列表中,则应在snap run --help
中找到application.desktop
文件,然后可以将其符号链接到/var/lib/snapd/desktop/applications/
。
或者更好的方法是将.local/share/applications/
添加到/var/lib/snapd/desktop/applications/
中,方法是将XDG_DATA_DIRS
添加到~/.profile
中(如果您只想将它应用于gnome,则添加~/.gnomerc
):
export XDG_DATA_DIRS="${XDG_DATA_DIRS}:/var/lib/snapd/desktop"
或者如果存在/etc/profile.d/snapd.sh
source /etc/profile.d/snapd.sh
答案 1 :(得分:0)
问题是我认为Snapcraft的文档不佳所致。 Snap只能运行Snap运行已安装应用程序的唯一方法。以下是运行使用Snap安装的应用程序的方法:
snap run ngrok --version
ngrok version 2.3.27
这种方式无效
ngrok
zsh: command not found: ngrok
有点怪异,但我认为最好手动解压缩Ngrok,而不要使用此较差的工具。