当前位置: 首页>后端>正文

基于开源网易云API+Flutter写的一款音乐播放器(二)

鍘嗘椂2涓鏈堬紝鍩轰簬寮€婧愮綉鏄撲簯API鐨勪竴娆句娇鐢?code>Flutter寮€鍙戠殑妗岄潰闊充箰绋嬪簭缁堜簬瀹屾垚浜嗗畠鐨勭涓€涓増鏈瑅1.0.0馃帀銆傚啀娆℃劅璋㈠ぇ浣负鎴戜滑鏁寸悊骞舵彁渚涗紬澶氭帴鍙c€?/p>

鏁堟灉鍥炬潵涓€娉€?/p>

基于开源网易云API+Flutter写的一款音乐播放器(二),第1张
鏁堟灉鍥?.gif

鏈枃鎺ュ姏涓婁竴绡囦粙缁嶆枃锛屼富瑕佷负澶у璁茶В涓嬪紑鍙?strong>DreamMusic涓亣鍒扮殑鍚勭闂锛屼互鍙婂叧閿疄鐜般€?/p>

鐢ㄦ埛鐧诲綍

鐢ㄦ埛鐧诲綍鍙互璇存槸椤圭洰寮€鍙戠殑绗竴姝ワ紝浣犲彧鏈夋嬁鍒癱ookie浜嗭紝寰堝鎺ュ彛鎵嶈兘姝e父杩斿洖鏁版嵁銆傛垜鎯筹紝姣忎竴涓熀浜庣綉鏄撲簯API寮€鍙戦」鐩殑閮芥湁杩囦笅闈㈢殑缁忓巻锛岃皟鐢ㄧ櫥褰曟帴鍙?/login/cellphone锛圥S锛氬瘑鐮佺櫥褰曞拰楠岃瘉鐮佺櫥褰曪級杩斿洖{code: -460, message: 鈥樼綉缁滃お鎷ユ尋锛岃绋嶅€欏啀璇曪紒鈥檥銆侴Ithub涓婃湁浜哄洖绛斾紶鍏?code>realIP鍙В銆傚叾瀹炵湡瀹炲師鍥犲氨鏄綘娌′紶cookie锛屾垨鑰呬紶鐨刢ookie涓嶅銆?strong>鍙鍦ㄨ姹傚ご涓婃坊鍔燾ookie鍗冲彲銆?/p>

DreamMusic鐨勭櫥褰曟€佹湁涓夌锛屽垎鍒槸锛氭湭鐧诲綍锛屾父瀹㈢櫥褰曪紝鐢ㄦ埛鐧诲綍銆?/p>

澶ц嚧娴佺▼鏄疉PP鍚姩锛岃鍙栨湰鍦颁繚瀛樼殑cookie锛屽鏋滄病鏈夎幏鍙栧埌锛岄偅涔堟槸绗竴娆″惎鍔ㄦ垨鏄凡缁忛€€鍑虹櫥褰曚簡锛岃皟鐢ㄦ父瀹㈢櫥褰曟帴鍙c€傚鏋滃瓨鍦╟ookie锛屼絾鏄病鏈?code>MUSIC_U杩欎釜cookie锛岄偅涔堝氨璁や负褰撳墠鏄父瀹㈢櫥褰曠姸鎬併€傚鏋滄槸瀛樺湪cookie锛屽苟涓攃ookie涓湁MUSIC_U杩欎釜cookie鐨勮瘽锛岃鏄庡綋鍓嶆槸鐢ㄦ埛鐧诲綍鐘舵€侊紝鎷夊彇鐢ㄦ埛淇℃伅鎺ュ彛鑳借幏鍙栧埌鍏蜂綋鐨勭敤鎴蜂俊鎭紝濡傛樀绉帮紝绛惧悕锛屾墜鏈哄彿绛夈€?/p>

[鍥剧墖涓婁紶澶辫触...(image-2f26d3-1667455027467)]

鎵€浠ヨ瀹炵幇涓婇潰鐨勯€昏緫锛屽叧閿湪浜巆ookie濡備綍鑾峰彇锛屼粠鍝噷鑾峰彇銆備袱涓湴鏂癸紝涓€涓槸鍦ㄦ瘡涓帴鍙e搷搴斿ご鐨?code>set-cookie瀛楁涓幏鍙栵紝杩樻湁涓€涓湴鏂规槸鍦ㄧ櫥褰曟帴鍙g殑鍝嶅簲浣撲腑鑾峰彇锛屾瘮濡傛墜鏈哄彿鐧诲綍杩斿洖鐨刯son涓湁涓猚ookie瀛楁璁板綍浜哻ookie鐨勫€笺€?/p>

[鍥剧墖涓婁紶澶辫触...(image-97b6af-1667455027467)]

杩欓噷鎺ㄨ崘涓€涓狥lutter涓ソ鐢ㄧ殑cookie瑙f瀽鍜岀鐞嗕笁鏂瑰簱锛?code>cookie_jar鍜?code>dio_cookie_manager锛屽墠鑰呬富瑕佹槸cookie鐨勮В鏋愬拰io鎿嶄綔锛屽悗闈㈢殑鏄?code>dio鐨勬嫤鎴櫒锛屽彲浠ュ湪HTTP璇锋眰涓敞鍏ュ拰璇诲彇cookie锛岄潪甯告柟渚裤€?/p>

涓嶈繃杩欓噷鏈変釜鍧戯紝灏辨槸濡傛灉浣犱娇鐢ㄧ殑鏄櫥褰曞悗鍝嶅簲浣撲腑鐨刢ookie锛屼篃灏辨槸杩斿洖json涓殑cookie鐨勫€硷紝閭d箞浼氬瓨鍦ㄨВ鏋愬紓甯哥殑鎯呭喌锛屼篃灏辨槸cookiejar浼氳В鏋愬け璐ワ紝骞朵涪澶遍儴鍒哻ookie锛屽叿浣撳師鍥犲彲浠ヨ嚜琛屾煡鐪嬩袱鑰呯殑鍖哄埆銆傚洜姝ゆ垜鍦ㄩ」鐩腑鍐欎簡涓緟鍔╁伐鍏风被CookieParse锛屽厛淇鏍煎紡闂锛屽啀浜ょ粰cookieJar澶勭悊銆?/p>

鍋氬埌涓婇潰杩欎簺锛屼笉鍑烘剰澶栵紝鐧诲綍搴旇鏄病闂浜嗙殑銆?/p>

闊充箰鎾斁鍔熻兘瀹炵幇

闊充箰鎾斁鍔熻兘鍙互璇存槸杩欎釜椤圭洰鐨勬牳蹇冧簡锛屽綋鐒剁敱浜嶧lutter鏄釜UI妗嗘灦锛屽洜姝よ繖閮ㄥ垎鍔熻兘杩樻槸闇€瑕佷緷璧栧師鐢熷疄鐜般€傚競闈笂鍋氱殑濂界殑鏈夊叧闊充箰鎾斁鐨勫簱鍏跺疄涔熷氨涓や釜锛?code>just_audio鍜?code>audioplayers銆?/p>

[鍥剧墖涓婁紶澶辫触...(image-ec09e6-1667455027467)]

鑰岃鍚屾椂鏀寔macos锛?code>windows锛?code>linux鐨勫氨鍙湁audioplayers浜嗐€傛墍浠ユ病寰楅€夛紝灏辩敤audioplayers浜嗐€?/p>

褰撶劧鍦ㄦ闈㈢寮曞叆audioplayers锛屼笉鍑烘剰澶栫殑鎶ラ敊浜嗐€?/p>

Warning: CocoaPods not installed. Skipping pod install.
  CocoaPods is used to retrieve the iOS and macOS platform side's plugin code that responds to your plugin usage on the Dart side.
  Without CocoaPods, plugins will not work on iOS or macOS.
  For more info, see https://flutter.dev/platform-plugins
To install see https://guides.cocoapods.org/using/getting-started.html#installation for instructions.

Exception: CocoaPods not installed or not in valid state.

杩欎釜闂鐪嬩笂鍘诲儚鏄洜涓篊ocoapods娌℃湁瀹夎锛屽鑷存棤娉曠粰macos锛坕OS锛夊钩鍙板畨瑁呮纭殑渚濊禆鐜锛屽洜姝ゆ棤娉曞惎鍔ㄣ€備簨瀹炰笂锛宑ocoapods鏄畨瑁呬簡鐨勶紝鍙鍘绘帀audioplayers杩欎釜涓夋柟搴擄紝绔嬮┈鑳芥甯歌窇璧锋潵銆傞偅涔堥棶棰樺氨鍑哄湪杩欎釜涓夋柟搴撲笂锛屽畠鐨勫紩鍏ヤ技涔庡鑷翠簡Flutter璇嗗埆寮傚父銆?/p>

鐜板湪audioplayer鐨刧it浠撳簱鐨刬ssue涓婃悳绱簡涓€鐣紝娌℃壘鍒扮浉鍏抽棶棰樸€傜湅鏉ヨ繖涓棶棰樻瘮杈冪壒娈婏紝鍙湁鑷繁閬囧埌杩囥€?/p>

鎴戠殑瑙e喅鍔炴硶锛宮ac绯荤粺鍗囩骇锛寈code鍗囩骇銆傚簲璇ユ湁鍏朵粬瑙e喅鏂规硶锛屾垜杩欒竟鏄濂介亣涓婅鍗囩骇绯荤粺锛岀储鎬у厛鍗囩骇绯荤粺浜嗐€?/p>

杩愯璧锋潵鍚庯紝鍙︿竴涓棶棰樺嚭鐜颁簡銆?/p>

[ERROR:flutter/lib/ui/ui_dart_state.cc(198)] Unhandled Exception: AVPlayerItem.Status.failed
#0      MethodChannelAudioplayersPlatform._doHandlePlatformCall
package:audioplayers_platform_interface/method_channel_audioplayers_platform.dart:174
#1      MethodChannelAudioplayersPlatform.platformCallHandler
package:audioplayers_platform_interface/method_channel_audioplayers_platform.dart:147
#2      MethodChannel._handleAsMethodCall
package:flutter/鈥?services/platform_channel.dart:404
#3      MethodChannel.setMethodCallHandler.<anonymous closure>
package:flutter/鈥?services/platform_channel.dart:397
#4      _DefaultBinaryMessenger.setMessageHandler.<anonymous closure>
package:flutter/鈥?services/binding.dart:380
#5      _DefaultBinaryMessenger.setMessageHandler.<anonymous closure>
package:flutter/鈥?services/binding.dart:377
#6      _invoke2.<anonymous closure> (dart:ui/hooks.dart:190:15)
#7      _rootRun (dart:async/zone.dart:1426:13)
#8      _CustomZone.run (dart:async/zone.dart:1328:19)
#9      _CustomZone.runGuarded (dart:async/zone.dart:1236:7)
#10     _invoke2 (dart:ui/hooks.dart:189:10)
#11     _ChannelCallbackRecord.invoke (dart:ui/channel_buffers.dart:42:5)
#12     _Channel.push (dart:ui/channel_buffers.dart:132:31)
#13     ChannelBuffers.push (dart:ui/channel_buffers.dart:329:17)
#14     PlatformDispatcher._dispatchPlatformMessage (dart:ui/platform_dispatcher.dart:589:22)
#15     _dispatchPlatformMessage (dart:ui/hooks.dart:89:31)

ERROR鍑虹幇鐨勭洿鎺ュ師鍥犲氨鏄?code>AVPlayerItem鍒濆鍖栧け璐ワ紝澶氫负璺緞/url濉敊锛屽鏋滄槸鎾斁缃戠粶闊充箰锛屼篃鍙兘鏄病鏈夌綉缁滄潈闄愬鑷淬€?/p>

MacOS寮€鍙戝拰iOS寮€鍙戜竴鏍凤紝濡傛灉瑕佺敤涓€浜涚郴缁熺骇鐨勫姛鑳斤紝闇€瑕佺敵璇锋潈闄愶紝鍦?code>info.plist涓坊鍔犻厤缃俊鎭€?/p>

濡傛灉瑕佹敮鎸丠TTPS锛屽湪macos鐩綍涓嬬殑info.plist涓坊鍔犲涓嬮敭鍊煎銆?/p>

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
</dict>

濡傛灉鏄?code>iOS鍒拌繖涓€姝ュ氨缁撴潫浜嗭紝MacOS寮€鍙戝垯瑕佸鍋氫竴姝ワ紝鍚?code>macos鐩綍鐨?code>DebugProfile.entitlements娣诲姞濡備笅閿€煎銆?/p>

<key>com.apple.security.network.client</key>
    <true/>

杩欐椂锛岄煶涔愯兘姝e父鎾斁浜嗐€?/p>

闊充箰鎾斁鐨勬墍鏈夊姛鑳介兘灏佽鍦?code>SongPlayer绫讳笅锛岀洰鍓嶅疄鐜扮殑鍔熻兘鏈夛細鎾斁鍒楄〃锛屾挱鏀撅紝鏆傚仠锛屼笂涓€棣栵紝涓嬩竴棣栵紝闊抽噺璋冭妭锛屾挱鏀捐烦杞埌鎸囧畾鏃堕棿鐐广€?/p>

璺敱鎺у埗鍣?/h2>

鐢ㄨ繃缃戞槗浜戦煶涔愭闈㈢鐨勯兘鐭ラ亾鍦ㄥ簲鐢ㄧ殑宸︿笂瑙掓湁涓袱涓寜閽紝鐢ㄤ簬鎺у埗椤甸潰鍓嶈繘鍜屽悗閫€锛屼互鍙奣ab鐨勫垏鎹紝闈炲父鏂逛究銆傚洜姝よ繖涓疄鐢ㄧ殑鍔熻兘蹇呴』鍔犱笂銆?/p>

瑕佸疄鐜拌繖涓姛鑳斤紝鎴戜滑蹇呴』璁板綍鐢ㄦ埛鐨勬瘡涓€娆¢〉闈㈠垏鎹㈠拰tab鍒囨崲銆傛垜灏嗚繖涓涓烘娊璞′负RouteAction锛岄〉闈㈣烦杞槸PageRouteAction锛孴ab鍒囨崲鏄?code>TabRouteAction銆傝繖浜沘ction閮界粺涓€鐢?code>RouteControlManager绠$悊锛岃繖鏍峰氨鑳藉湪鍓嶈繘鍜屽悗閫€鏃跺埄鐢ㄨ繖浜沘ction鏉ユ帶鍒堕〉闈㈢殑鍒囨崲浜嗐€?/p>

Tab鍒囨崲涔熷氨鏄晶杈规爮鐨勬椂鏈哄ソ澶勭悊锛屾瘯绔熻繖涓晶杈规爮鏄嚜瀹氫箟鐨勶紝鎸夐挳鐨勭偣鍑诲畬鍏ㄥ彲鎺с€傛垜浠洿鎺ユ潵鐪嬮〉闈㈢殑鍒囨崲涔熷氨鏄鑸殑push鍜宲op鎿嶄綔銆傝繖涓€庝箞鐩戝惉锛熺瓟妗堟槸浣跨敤鑷畾涔?code>NavigatorObserver銆侼avigatorObserver涓毚闇蹭簡瀵艰埅鐨勬瘡涓€娆ush鍜宲op鎿嶄綔锛屼互鍙婄浉搴旂殑璺敱route瀵硅薄锛屼粠涓垜浠彲浠ヨ幏鍙栭亾瀵瑰簲鐨?code>navigatorstate鍜?code>routesetting锛屽洜姝ゅ浜庨〉闈㈢殑鍒囨崲涔熻鎴戜滑鎺屾帶鍦ㄤ簡鎵嬩腑銆?/p>

class CustomNavigatorObserver extends NavigatorObserver {
  // push: route鏄皢瑕乸ush鐨勮矾鐢?
    @override
  void didPush(Route route, RoutepreviousRoute) {
    super.didPush(route, previousRoute);
    RouteControlManager().pushAction(PageRouteAction(navigator: route.navigator, settings: route.settings));
  }

  // pop: route鏄皢瑕佽pop鐨勮矾鐢?
  @override
  void didPop(Route route, RoutepreviousRoute) {
    super.didPop(route, previousRoute);
    RouteControlManager().popAction(PageRouteAction(navigator: route.navigator, settings: route.settings));
  }
}

杩欓噷瀵硅繖鍧楁病鏈夋繁鍏ョ殑鍚屽灏辫闂簡锛屼负鍟ユ嬁鍒?code>avigatorState鍜?code>routesetting灏卞彲浠ユ帶鍒堕〉闈㈢殑鍒囨崲浜嗐€傞偅鎴戝氨澶氬槾涓€鍙ャ€?/p>

鎴戜滑鍏堟潵鐪嬩笅Flutter涓〉闈㈣烦杞槸濡備綍鎺у埗鐨勩€傛湁涓や釜椤甸潰A锛孊銆備粠椤甸潰A鍒伴〉闈鍙玴ush锛屽啀浠庨〉闈鍥炲埌椤甸潰A鍙玴op銆?/p>

// push
Navigator.pushNamed(context, "B");

// pop锛岃繑鍥炲鑸爤鐨勪笂涓€灞?
Navigator.pop(context);

杩欓噷鐨勫叧閿氨鏄幏鍙栧埌涓婁笅鏂?code>context锛屽簳灞傞€氳繃context鏌ユ壘鍒版爲缁撴瀯涓渶杩戠殑NavigatorState锛屼粠鑰屾帶鍒堕〉闈㈢殑瀵艰埅銆備篃灏辨槸context 鈫?NavigatorState銆備负浠€涔堣杩欐牱锛屽洜涓烘垜浠殑姣忎釜椤甸潰鍦ㄥ鑸腑閮芥槸浠?code>OverlayEntry鐨勫舰寮忓瓨鍦ㄥ苟琚鐞嗙殑锛屾嬁鍒颁簡NavigatorState涔熷氨浠h〃鎷垮埌浜嗛〉闈㈢殑鎺у埗鏉冦€?/p>

鍥炲埌鑷畾涔夌殑NavigatorObserver涓紝杩欐椂锛屾垜浠啀杩涜Navigator.pushNamed(context, 鈥渟etting鈥?;鏃讹紝灏卞彲浠ュ湪CustomNavigatorObserver涓嫤鎴埌璺宠浆淇℃伅浜嗐€?/p>

flutter: [route]push --> ModelRoute(RouteSettings("setting", null), 
animation: AnimationController#68be1(鈻?0.000; for ModelRoute)), 
MaterialPageRoute<dynamic>(RouteSettings("/", null), 
animation: AnimationController#c6365(鈴?1.000; paused; 
for MaterialPageRoute<dynamic>(/)))

鑰?code>CustomNavigatorObserver鎴栬€呭洖璋冨嚱鏁颁腑鐨勫弬鏁?code>Route閮借兘鐩存帴鑾峰彇鍒?code>NavigatorState锛屽埌杩欓噷锛屾垜浠笉閫氳繃context鑰岀洿鎺ヨ幏鍙栧埌浜嗘帶鍒跺鑸殑NavigatorState銆?/p>

鐜板湪锛屾垜浠氨鍙互鍐欎袱涓柟娉曟潵鎺у埗鍓嶈繘鍜岃繑鍥炪€?/p>

杩斿洖锛岃皟鐢?code>navigator鐨?code>pop()銆?/p>

void back() {
    if (canBack()) {
      final current = _actions[_currentIndex];
      _currentIndex -= 1;
      if (current.type == RouteActionType.page) {
        PageRouteAction action = current as PageRouteAction;
        action.navigator?.pop();
      }
      notifyListeners();
    }
  }

鍓嶈繘锛岃皟鐢?code>navigator鐨?code>pushNamed鏂规硶銆?/p>

void forward() {
    if (canForward()) {
      _currentIndex += 1;
      final current = _actions[_currentIndex];
      if (current.type == RouteActionType.page) 
        PageRouteAction action = current as PageRouteAction;
        if (action.settings.name != null) {
          action.navigator?.pushNamed(action.settings.name!,
              arguments: action.settings.arguments);
        }
      } 
      notifyListeners();
    }
  }

杩欐牱锛屾垜浠氨鍙互鎼厤杩斿洖鍜屽墠杩涙寜閽紝閫氳繃璋冪敤back()鍜?code>forward()鏉ュ叏灞€鎺у埗椤甸潰鐨勫墠杩涘拰鍚庨€€浜嗭紝瀹岀編銆?/p>

姝岃瘝婊氬姩鍜屽畾浣?/h2>

鐭ラ亾姣忎竴琛岀殑楂樺害锛屼互鍙婃瓕璇嶅垪琛ㄧ殑楂樺害锛屽彲浠ラ€氳繃context鐨刦indRenderObject鏉ヨ幏鍙栨覆鏌撶粍浠剁殑灏哄銆?/p>

final ob = context.findRenderObject();
    if (ob != null && ob is RenderBox) {
      model?.size = ob.size;
    }

缁撳悎婊氬姩鐩戝惉NotificationListener<ScrollNotification>锛岃幏鐭ュ綋鍓嶇殑婊氬姩鍋忕Щ銆傝绠楀嚭闇€瑕佸亸绉荤殑璺濈锛岃皟鐢?code>ScrollController鐨?code>animateTo鍗冲彲瀹炵幇婊氬姩鍒版寚瀹氳鐨勬瓕璇嶅姛鑳姐€?/p>

scrollController.animateTo(offsety,
            duration: const Duration(milliseconds: 200), curve: Curves.ease);

涓嬭浇闊充箰

DreamMusic杩樺疄鐜颁簡闊充箰涓嬭浇鍔熻兘銆備笉杩囬亣鍒颁簡鏂囦欢鏉冮檺闂锛屾垜鍦ㄤ笅杞芥瓕鏇插皾璇曞啓鍏ユ湰鍦癉ownload鐩綍鏃讹紝鎶ヤ互涓嬮敊璇細

鍑虹幇寮傚父銆?
FileSystemException (FileSystemException: Cannot create file, path = '/Users/zl/Library/Containers/com.jinfeng.dreammusic.dreamMusic/Data/Downloads' (OS Error: Operation not permitted, errno = 1))

杩欐槸鍥犱负鎴戜滑娌℃湁璇诲啓鏂囦欢鐨勬潈闄愶紝闇€瑕佸幓淇敼涓嬬敤鎴风殑鏉冮檺銆?/p>

閫氳繃Apple鐨勫紑鍙戞枃妗f壘鍒版湁鍏虫潈闄愰棶棰樼殑璇存槑銆傚叾涓湁涓巿鏉冪閽ョ殑key涓?code>com.apple.security.files.downloads.read-write 锛岃〃绀?strong>瀵圭敤鎴风殑涓嬭浇鏂囦欢澶圭殑璇?鍐欒闂潈闄?/strong>銆傞偅涔堬紝浣跨敤Xcode鎵撳紑Flutter椤圭洰涓殑mac搴旂敤锛屼慨鏀瑰伐绋嬬洰褰曚笅鐨?code>DebugProfile.entitlements鏂囦欢锛屽悜entitlements鏂囦欢涓坊鍔?code>com.apple.security.files.downloads.read-write锛屽苟灏嗗€艰缃负YES锛屼繚瀛樺悗閲嶅惎Flutter椤圭洰銆傚彂鐜板凡缁忓彲浠ュ悜涓嬭浇鐩綍涓鍐欐枃浠朵簡銆?/p>

褰撶劧锛岃繖鏄甯告搷浣溿€傝繕鏈変釜楠氭搷浣滃氨鏄叧闂郴缁熺殑娌欑洅鏈哄埗銆傚皢entitlements鏂囦欢鐨?code>App Sandbox璁剧疆涓篘O銆傝繖鏍锋垜浠氨鍙互璁块棶浠绘剰璺緞浜嗐€傚綋鐒跺叧闂簲鐢ㄧ殑娌欑洅涔熷氨鐩稿綋浜庡叧闂簡搴旂敤鐨勯槻鎶ゆ満鍒讹紝鍥犳杩欎釜閫夐」鎱庣敤銆?/p>

涓嬭浇姝屾洸鍚庯紝姝屾洸鐨勫悕瀛楃瓑淇℃伅濡備綍淇濆瓨锛?/h2>

杩欓噷鏈変袱涓柟妗堬紝涓€涓槸鍚屾椂淇濆瓨涓€涓猨son鏂囦欢锛岀敤浜庤褰曟瓕鏇蹭俊鎭紝杩欎釜鏂规鐨勭己鐐规槸鏁版嵁鍒嗘暎锛屽唴瀹瑰鏄撲涪澶便€傚彟涓€涓柟妗堟槸鐩存帴瀛樺叆mp3鏂囦欢鍐呴儴锛岀綉鏄撲簯闊充箰鐨勯煶涔愪笅杞芥槸杩欎箞瀹炵幇浜嗭紝浣跨敤id3搴撳彲浠ヨ鍙栧埌mp3鏂囦欢涓澶栧瓨鍌ㄧ殑淇°€侷D3瑙f瀽鐩稿叧浠嬬粛

鐩墠鐢变簬鎶€鏈師鍥狅紝鏆傛椂閲囩敤浜嗕笅杞絤p3+json鐨勬柟寮忋€傚悗闈㈡湁鏃堕棿浼氬仛浼樺寲銆傝繖绉嶆柟寮忕壒鍒緷璧栦簬涓や釜鏂囦欢鐨勫畬鏁存€э紝姣曠珶mp3+json鐩稿綋浜庝竴棣栧畬鏁寸殑姝屻€傚洜姝reamMusic杩樺涓嬭浇鏂囦欢鍋氫簡鍒犻櫎鐨勭洃鍚紝閫氳繃涓嬭浇鏂瑰紡瀹炵幇銆?/p>

final stream =
          directory.watch(events: FileSystemEvent.delete, recursive: true);
      stream.listen((event) async {
//澶勭悊鍒犻櫎鍚庣殑閫昏緫
}

Show In Finder瀹炵幇

褰撴椂鐪嬪埌杩欎釜鍔熻兘锛岀涓€鍙嶅簲灏辨槸缃戜笂鎵炬枃浠舵搷浣滅浉鍏崇殑搴撱€傛瘮杈冩湁鍚嶇殑鏈?code>file_selector鍜?code>file_picker銆傝繖涓や釜閮芥彁渚涗簡鏂囦欢閫夋嫨鍔熻兘锛屼絾鏄病鏈夊崟绾殑鎵撳紑鏂囦欢鐩綍鐨勯€夐」銆傜劧鍚庢垜鐪嬩簡file_picker鐨勫疄鐜帮紝濂藉浼欙紝绔熺劧鏄洿鎺ラ€氳繃鍛戒护琛屽疄鐜扮殑锛岃繖褰撴椂灏辫鎴戠伒鎰熶竴闂紝鏈夊姙娉曚簡銆?/p>

open 鍛戒护 鎼炲畾涓€鍒囥€?/p>

class ShowInFinder {
  /// 鎵撳紑鐩綍
  static void open({StringinitialDirectory}) {
    if (initialDirectory?.isNotEmpty == true) {
      final type = FileSystemEntity.typeSync(initialDirectory!);
      if (type == FileSystemEntityType.file || type == FileSystemEntityType.link) {
        debugPrint("[finder]$initialDirectory, 涓嶆槸鐩綍");
        return;
      }
      if (type == FileSystemEntityType.notFound) {
        // 鎸囧畾鐩綍涓嶅瓨鍦紝鍒涘缓
        Directory(initialDirectory).create();
      }
    }
    String argument = initialDirectory ?'.';
    Process.run("open", [argument]);
  }
}

淇敼妗岄潰搴旂敤鐨勫浘鏍囧拰鍚嶇О

搴旂敤鍚嶇О鍜屽浘鏍囬兘闇€瑕佸師鐢熷伐绋嬩腑鍘婚厤缃紝杩欓噷涔熷氨鏄痬acos銆亀indows銆乴inux鐩綍銆?/p>

macOS閰嶇疆鐪嬭繖閲屻€?/p>

windows閰嶇疆鐪嬭繖閲屻€?/p>

Linux閰嶇疆鐪嬭繖閲屻€?/p>

杩欓噷鎴戝彧閰嶄簡macos鍜寃indows鐨勶紝姣曠珶璋佷細鍘荤敤linux杩愯杩欎釜椤圭洰鍛紒锛堝搱鍝堬紝鍏跺疄灏辨槸鎳掞級

鏈€鍚?/h2>

鍙傝€冩枃妗?/h2>

Mac娌欑洅鏈哄埗鍜屾潈闄愰厤缃?/p>

MP3鏂囦欢缁撴瀯瑙f瀽(瓒呰缁?

MP3鏍囩鏍煎紡锛圛D3锛孉PE锛夎秴璇︾粏瑙i噴


https://www.xamrdz.com/backend/3b81997113.html

相关文章: