首页
/
每日頭條
/
科技
/
flutter動态加載
flutter動态加載
更新时间:2025-06-13 23:34:52

今天農村老家的天氣不是很好

而且外面還下雨了,每天隻能坐在老家

打開電腦,看看文章,寫寫文章

今天我給大家帶來一篇Flutter加載本地json文件教程

本頭條核心宗旨

歡迎來到「技術剛剛好」作者,「技術剛剛好」是個人維護,每天至少更新一篇Flutter技術文章,實時為大家播報Flutter最新消息。如果你剛好也在關注Flutter這門技術,那就跟我一起學習進步吧,你的贊,收藏,轉發是對我個人最大的支持,維護不易,歡迎關注。

技術剛剛好經曆

近幾年,移動端跨平台開發技術層出不窮,從Facebook家的ReactNative,到阿裡家WEEX,前端技術在移動端跨平台開發中大展身手,技術剛剛好作為一名Android開發,經曆了從Reactjs到Vuejs的不斷學習。而在2018年,我們的主角變成了Flutter,這是Goolge開源的一個移動端跨平台解決方案,可以快速開發精美的移動App。希望跟大家一起學習,一起進步!

本文核心要點


flutter動态加載(Flutter加載本地JSON文件教程建議收藏)1


JSON文件數據

[ { "name": "Luke Skywalker", "height": "172", "mass": "77", "hair_color": "blond", "skin_color": "fair", "eye_color": "blue", "birth_year": "19BBY", "gender": "male" }, { "name": "C-3PO", "height": "167", "mass": "75", "hair_color": "n/a", "skin_color": "gold", "eye_color": "yellow", "birth_year": "112BBY", "gender": "n/a" }, { "name": "R2-D2", "height": "96", "mass": "32", "hair_color": "n/a", "skin_color": "white, blue", "eye_color": "red", "birth_year": "33BBY", "gender": "n/a" }, { "name": "Darth Vader", "height": "202", "mass": "136", "hair_color": "none", "skin_color": "white", "eye_color": "yellow", "birth_year": "41.9BBY", "gender": "male" }, { "name": "Leia Organa", "height": "150", "mass": "49", "hair_color": "brown", "skin_color": "light", "eye_color": "brown", "birth_year": "19BBY", "gender": "female" }, { "name": "Owen Lars", "height": "178", "mass": "120", "hair_color": "brown, grey", "skin_color": "light", "eye_color": "blue", "birth_year": "52BBY", "gender": "male" }, { "name": "Beru Whitesun lars", "height": "165", "mass": "75", "hair_color": "brown", "skin_color": "light", "eye_color": "blue", "birth_year": "47BBY", "gender": "female" }, { "name": "R5-D4", "height": "97", "mass": "32", "hair_color": "n/a", "skin_color": "white, red", "eye_color": "red", "birth_year": "unknown", "gender": "n/a" }, { "name": "Biggs Darklighter", "height": "183", "mass": "84", "hair_color": "black", "skin_color": "light", "eye_color": "brown", "birth_year": "24BBY", "gender": "male" }, { "name": "Obi-Wan Kenobi", "height": "182", "mass": "77", "hair_color": "auburn, white", "skin_color": "fair", "eye_color": "blue-gray", "birth_year": "57BBY", "gender": "male" } ]

項目結構如下


flutter動态加載(Flutter加載本地JSON文件教程建議收藏)2

項目結構

核心代碼

import 'dart:convert'; import 'package:flutter/material.dart'; void main() { runApp(MaterialApp( home: MyApp(), )); } class MyApp extends StatefulWidget { @override MyAppState createState() => MyAppState(); } class MyAppState extends State<MyApp> { List data; @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text("Load local JSON file"), ), body: Container( child: Center( // Use future builder and DefaultAssetBundle to load the local JSON file child: FutureBuilder( future: DefaultAssetBundle .of(context) .loadString('data_repo/starwars_data.json'), builder: (context, snapshot) { // decode the JSON var new_data = json.decode(snapshot.data.toString()); return ListView.builder( // Build the ListView itemBuilder: (BuildContext context, int index) { return Card( child: Column( crossAxisAlignment: CrossAxisAlignment.stretch, children: <Widget>[ Text("Name: " new_data[index]['name']), Text("Height: " new_data[index]['height']), Text("Mass: " new_data[index]['mass']), Text( "Hair Color: " new_data[index]['hair_color']), Text( "Skin Color: " new_data[index]['skin_color']), Text( "Eye Color: " new_data[index]['eye_color']), Text( "Birth Year: " new_data[index]['birth_year']), Text("Gender: " new_data[index]['gender']) ], ), ); }, itemCount: new_data == null ? 0 : new_data.length, ); }), ), )); } }

謝謝觀看技術剛剛好的文章,技術剛剛好是個人維護,每天至少更新一篇Flutter技術文章,實時為大家播報Flutter最新消息。如果你剛好也在關注Flutter這門技術,那就跟我一起學習進步吧,你的贊,收藏,轉發是對我個人最大的支持,維護不易,歡迎關注。

,
Comments
Welcome to tft每日頭條 comments! Please keep conversations courteous and on-topic. To fosterproductive and respectful conversations, you may see comments from our Community Managers.
Sign up to post
Sort by
Show More Comments
推荐阅读
奧恰洛夫底闆和w968哪個好
奧恰洛夫底闆和w968哪個好
2020年1月1日新年伊始,著名乒乓球品牌BUTTERFLY蝴蝶公司就正式官宣:世界頂尖的乒乓球運動員德國選手迪米特裡•奧恰洛夫正式加入蝴蝶大家庭。奧恰洛夫與蝴蝶牽手并不意外:因為蝴蝶公司長久以來一直是德國國家隊的贊助商,并且早就簽約了同樣...
2025-06-13
蘋果手機無法激活怎麼辦
蘋果手機無法激活怎麼辦
蘋果手機無法激活怎麼辦?首先需要插卡激活,最好是有效的SIM卡雖然無效的SIM卡聯無線網也可以激活無法激活建議換一張卡,老版本的蘋果是分版本的,需要對應的運營商SIM卡激活全網通的蘋果手機三大運營商的SIM卡都可以激活,我來為大家講解一下關...
2025-06-13
如何用手機檢查房間裡的攝像頭
如何用手機檢查房間裡的攝像頭
由于一些不法分子為了竊取個人隐私,在酒店或者私密場所安裝隐蔽攝像頭,對我們個人隐私造成入侵。這些攝像頭雖然很小很隐蔽,但是他們需要拍攝,那麼就必須把鏡頭露出來,所以這也是攝像頭的一個弊端,我們可以使用手機将其找出來,很多手機都有這個功能,但...
2025-06-13
用手機開空調怎麼操作
用手機開空調怎麼操作
用手機開空調怎麼操作?以華為P40,EMUI10系統為例,手機開空調的方法如下:,下面我們就來說一說關于用手機開空調怎麼操作?我們一起去了解并探讨一下這個問題吧!用手機開空調怎麼操作以華為P40,EMUI10系統為例,手機開空調的方法如下:...
2025-06-13
自媒體營銷包含哪4種
自媒體營銷包含哪4種
如今,随着互聯網技術的發展,大多數人的信息來源都是互聯網。随着互聯網的不斷發展,人們對于簡單、快捷、趣味性的需求也随之增加,從碎片化閱讀到短視頻觀看,自媒體也飛速發展起來。自媒體營銷怎麼做?自媒體有哪些營銷技巧?你還以為自媒體隻能靠賺廣告費...
2025-06-13
Copyright 2023-2025 - www.tftnews.com All Rights Reserved