#flutter #mobile #menu
Вопрос:
я пытаюсь распечатать навбар в своем мобильном приложении. Код для main.dart: импорт пакета navbar.dart не используется, как говорит система.навигационная панель совершенно ничего не показывает. кто-нибудь знает, как это исправить? приложение «Погода» само по себе работает. но навбар не печатается. PLaceholderPLaceholderPLaceholderPLaceholderPLaceholderPLaceholderPLaceholderPLaceholderPLaceholderPLaceholderPLaceholderPLaceholderPLaceholder
import 'package:weerappflutter/data_service.dart'; import 'package:flutter/material.dart'; import 'package:weerappflutter/models.dart'; import 'package:weerappflutter/navbar.dart'; void main() { runApp(MyApp()); } class MyApp extends StatefulWidget { @override Statelt;StatefulWidgetgt; createState() =gt; _MyAppState(); } class _MyAppState extends Statelt;MyAppgt; { final _cityTextController = TextEditingController(); final _dataService = DataService(); WeatherResponse? _response; @override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( body: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ if (_response != null) Column( children: [ Image.network(_response!.iconUrl), Text( '${_response!.tempInfo.temperature}°', style: TextStyle(fontSize: 40), ), Text(_response!.weatherInfo.description) ], ), Padding( padding: EdgeInsets.symmetric(vertical: 50), child: SizedBox( width: 150, child: TextField( controller: _cityTextController, decoration: InputDecoration(labelText: 'Voer een stad in:'), textAlign: TextAlign.center), ), ), ElevatedButton(onPressed: _search, child: Text('Toon temparatuur')) ], ), ), )); } void _search() async { final response = await _dataService.getWeather(_cityTextController.text); setState(() =gt; _response = response); } }
код навигационной панели.дротик
import 'package:flutter/material.dart'; class NavBar extends StatelessWidget { @override Widget build(BuildContext context) { return Drawer( child: ListView( // Remove padding padding: EdgeInsets.zero, children: [ UserAccountsDrawerHeader( accountName: Text('WeerBeving'), accountEmail: Text('WeerBeving.com'), currentAccountPicture: CircleAvatar( child: ClipOval( child: Image.network( 'https://oflutter.com/wp-content/uploads/2021/02/girl-profile.png', fit: BoxFit.cover, width: 90, height: 90, ), ), ), decoration: BoxDecoration( color: Colors.blue, image: DecorationImage( fit: BoxFit.fill, image: NetworkImage( 'https://oflutter.com/wp-content/uploads/2021/02/profile-bg3.jpg')), ), ), ListTile( leading: Icon(Icons.favorite), title: Text('Weer'), onTap: () =gt; null, ), ListTile( leading: Icon(Icons.person), title: Text('Aardbevingen Nederland'), onTap: () =gt; null, ), ListTile( leading: Icon(Icons.share), title: Text('Aardbevingen wereldwijd'), onTap: () =gt; null, ), Divider(), ListTile( title: Text('Exit'), leading: Icon(Icons.exit_to_app), onTap: () =gt; null, ), ], ), ); } }
Ответ №1:
Внутри эшафота прямо над телом напишите
drawer:NavBar(),
Вы только импортировали пакет, но не назвали его нигде в main.dart
Ответ №2:
Вы объявили виджет NavBar, но забыли разместить его в дереве виджетов. Для этого используйте выдвижное поле подмостков … Подмостки( ящик: НавБар(), кузов: … )