0

我正在尝试减少此处输入图像描述之间的空间,即注释图像和注释标题的前导和标题

我的部分代码是:

drawer: Drawer(
        child: ListView(
          padding: EdgeInsets.zero,
          children: [
            Container(
              height: 110,
              child: DrawerHeader(
                child: Text(
                  'My Secret Diary',
                  style: TextStyle(
                      fontSize: 35,
                      fontWeight: FontWeight.bold,
                      fontFamily: 'madelyn'),
                ),
                decoration: BoxDecoration(
                  color: Colors.greenAccent,
                ),
              ),
            ),
            
            
           Container(
             //decoration : BoxDecoration( border: Border.all(color: Colors.black, width: 1)),
             child: ListTile(

              selectedTileColor: Colors.blue,
               leading: Image.asset('assets/images/notes.png' , width: 25, height: 25, fit: BoxFit.cover,),
               title: Text(
                 'Notes',
                 style: TextStyle(fontFamily: 'alkes', fontSize: 18),
               ),


             ),

           )
          ],
        ),
  
      ),

整个代码:

import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        // This is the theme of your application.
        //
        // Try running your application with "flutter run". You'll see the
        // application has a blue toolbar. Then, without quitting the app, try
        // changing the primarySwatch below to Colors.green and then invoke
        // "hot reload" (press "r" in the console where you ran "flutter run",
        // or simply save your changes to "hot reload" in a Flutter IDE).
        // Notice that the counter didn't reset back to zero; the application
        // is not restarted.
        primarySwatch: Colors.blue,
        // This makes the visual density adapt to the platform that you run
        // the app on. For desktop platforms, the controls will be smaller and
        // closer together (more dense) than on mobile platforms.
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: MyHomePage(title: 'Notes'),
    );
  }
}

class MyHomePage extends StatelessWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  // This widget is the home page of your application. It is stateful, meaning
  // that it has a State object (defined below) that contains fields that affect
  // how it looks.

  // This class is the configuration for the state. It holds the values (in this
  // case the title) provided by the parent (in this case the App widget) and
  // used by the build method of the State. Fields in a Widget subclass are
  // always marked "final".

  final String title;
  GlobalKey<ScaffoldState> _scaffoldkey = GlobalKey<ScaffoldState>();

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
      key: _scaffoldkey,
      drawer: Drawer(
        child: ListView(
          padding: EdgeInsets.zero,
          children: [
            Container(
              height: 110,
              child: DrawerHeader(
                child: Text(
                  'My Secret Diary',
                  style: TextStyle(
                      fontSize: 35,
                      fontWeight: FontWeight.bold,
                      fontFamily: 'madelyn'),
                ),
                decoration: BoxDecoration(
                  color: Colors.greenAccent,
                ),
              ),
            ),
            
            
           Container(
             //decoration : BoxDecoration( border: Border.all(color: Colors.black, width: 1)),
             child: ListTile(

              selectedTileColor: Colors.blue,
               leading: Image.asset('assets/images/notes.png' , width: 25, height: 25, fit: BoxFit.cover,),
               title: Text(
                 'Notes',
                 style: TextStyle(fontFamily: 'alkes', fontSize: 18),
               ),


             ),

           )
          ],
        ),
  
      ),
      body: ListView(
        children: <Widget>[
          SizedBox(height: 20.0),
          Padding(
            padding: EdgeInsets.symmetric(horizontal: 15.0),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.start,
              children: [
                GestureDetector(
                  child: Container(
                    height: 35.0,
                    width: 35.0,
                    decoration: BoxDecoration(
                      image: DecorationImage(
                          image: AssetImage('assets/images/hamburger.png')),
                      borderRadius: BorderRadius.circular(10.0),
                    ),
                  ),
                  onTap: () {
                    _scaffoldkey.currentState.openDrawer();
                  },
                ),
                SizedBox(width: 20.0),
                Text(
                  'Notes',
                  style: TextStyle(
                      fontSize: 28.0,
                      fontWeight: FontWeight.bold,
                      fontFamily: 'futuram'),
                )
              ],
            ),
          ),
        ],
      ),
    );

    throw UnimplementedError();
  }
}
4

1 回答 1

0

ListTile将您的标题包装在Align小部件中

ListTile(
  selectedTileColor: Colors.blue,
  leading: Image.asset('assets/images/notes.png' , width: 25, height: 25, fit: BoxFit.cover,),
  title: Align(
    alignment: Alignment(-5.0, 0), // change -5.0 to your preferred value
    child: Text(
      'Notes',
      style: TextStyle(fontFamily: 'alkes', fontSize: 18),
    ),
  ),
  // ...
),
于 2021-01-17T18:37:46.820 回答